|
31 | 31 | import baritone.utils.ToolSet;
|
32 | 32 | import net.minecraft.core.BlockPos;
|
33 | 33 | import net.minecraft.core.Direction;
|
| 34 | +import net.minecraft.util.Mth; |
34 | 35 | import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
35 | 36 | import net.minecraft.world.level.block.*;
|
36 | 37 | import net.minecraft.world.level.block.piston.MovingPistonBlock;
|
|
50 | 51 | import net.minecraft.world.phys.HitResult;
|
51 | 52 | import net.minecraft.world.phys.Vec3;
|
52 | 53 |
|
53 |
| -import java.util.ArrayList; |
54 |
| -import java.util.List; |
55 |
| -import java.util.Optional; |
| 54 | +import java.util.*; |
56 | 55 |
|
| 56 | +import static baritone.api.utils.RotationUtils.DEG_TO_RAD_F; |
57 | 57 | import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP;
|
58 | 58 | import static baritone.pathing.precompute.Ternary.*;
|
59 | 59 |
|
@@ -659,6 +659,43 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
|
659 | 659 | )).setInput(Input.MOVE_FORWARD, true);
|
660 | 660 | }
|
661 | 661 |
|
| 662 | + static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, float idealYaw) { |
| 663 | + MovementOption.getOptions( |
| 664 | + Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F), |
| 665 | + Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F), |
| 666 | + Baritone.settings().allowSprint.value |
| 667 | + ).min(Comparator.comparing(option -> option.distanceToSq( |
| 668 | + Mth.sin(idealYaw * DEG_TO_RAD_F), |
| 669 | + Mth.cos(idealYaw * DEG_TO_RAD_F) |
| 670 | + ))).ifPresent(selection -> selection.setInputs(state)); |
| 671 | + } |
| 672 | + |
| 673 | + static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) { |
| 674 | + float idealYaw = RotationUtils.calcRotationFromVec3d( |
| 675 | + ctx.playerHead(), |
| 676 | + VecUtils.getBlockPosCenter(dest), |
| 677 | + ctx.playerRotations() |
| 678 | + ).getYaw(); |
| 679 | + moveTowardsWithoutRotation(ctx, state, idealYaw); |
| 680 | + } |
| 681 | + |
| 682 | + static void moveTowardsWithSlightRotation(IPlayerContext ctx, MovementState state, BlockPos dest) { |
| 683 | + float idealYaw = RotationUtils.calcRotationFromVec3d( |
| 684 | + ctx.playerHead(), |
| 685 | + VecUtils.getBlockPosCenter(dest), |
| 686 | + ctx.playerRotations() |
| 687 | + ).getYaw(); |
| 688 | + float distance = Rotation.yawDistanceFromOffset(ctx.playerRotations().getYaw(), idealYaw) % 45f; |
| 689 | + float newYaw = distance > 0f ? |
| 690 | + distance > 22.5f ? distance - 45f : distance : |
| 691 | + distance < -22.5f ? distance + 45f : distance; |
| 692 | + state.setTarget(new MovementTarget(new Rotation( |
| 693 | + ctx.playerRotations().getYaw() - newYaw, |
| 694 | + ctx.playerRotations().getPitch() |
| 695 | + ), true)); |
| 696 | + moveTowardsWithoutRotation(ctx, state, idealYaw); |
| 697 | + } |
| 698 | + |
662 | 699 | /**
|
663 | 700 | * Returns whether or not the specified block is
|
664 | 701 | * water, regardless of whether or not it is flowing.
|
@@ -778,7 +815,7 @@ static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone,
|
778 | 815 | if (ctx.getSelectedBlock().isPresent()) {
|
779 | 816 | BlockPos selectedBlock = ctx.getSelectedBlock().get();
|
780 | 817 | Direction side = ((BlockHitResult) ctx.objectMouseOver()).getDirection();
|
781 |
| - // only way for selectedBlock.equals(placeAt) to be true is if it's replacable |
| 818 | + // only way for selectedBlock.equals(placeAt) to be true is if it's replaceable |
782 | 819 | if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.relative(side).equals(placeAt))) {
|
783 | 820 | if (wouldSneak) {
|
784 | 821 | state.setInput(Input.SNEAK, true);
|
|
0 commit comments