|
50 | 50 | import net.minecraft.world.phys.BlockHitResult; |
51 | 51 | import net.minecraft.world.phys.HitResult; |
52 | 52 | import net.minecraft.world.phys.Vec3; |
| 53 | +import org.jetbrains.annotations.NotNull; |
53 | 54 |
|
54 | 55 | import java.util.List; |
55 | 56 | import java.util.Optional; |
56 | 57 |
|
| 58 | +import static baritone.api.utils.RotationUtils.DEG_TO_RAD_F; |
57 | 59 | import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP; |
58 | 60 | import static baritone.pathing.precompute.Ternary.*; |
59 | 61 |
|
@@ -661,34 +663,12 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) { |
661 | 663 |
|
662 | 664 | static void moveTowardsWithRotation(IPlayerContext ctx, MovementState state, BlockPos dest, Rotation rotation) { |
663 | 665 | state.setTarget(new MovementTarget(rotation, true)); |
664 | | - boolean canSprint = Baritone.settings().allowSprint.value; |
665 | | - float ax = Mth.sin((float)Math.toRadians(ctx.playerRotations().getYaw())); |
666 | | - float az = Mth.cos((float)Math.toRadians(ctx.playerRotations().getYaw())); |
| 666 | + float ax = Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F); |
| 667 | + float az = Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F); |
667 | 668 | Rotation blockRotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(), |
668 | 669 | VecUtils.getBlockPosCenter(dest), |
669 | 670 | ctx.playerRotations()); |
670 | | - float targetAx = Mth.sin((float)Math.toRadians(blockRotation.getYaw())); |
671 | | - float targetAz = Mth.cos((float)Math.toRadians(blockRotation.getYaw())); |
672 | | - float[][] options = { |
673 | | - {canSprint ? ax * 1.3f : ax, canSprint ? az * 1.3f : az}, // W |
674 | | - {-ax, -az}, // S |
675 | | - {-az, az}, // A |
676 | | - {az, -ax}, // D |
677 | | - {(canSprint ? ax * 1.3f : ax) - az, (canSprint ? az * 1.3f : az) + ax}, // W+A |
678 | | - {(canSprint ? ax * 1.3f : ax) + az, (canSprint ? az * 1.3f : az) - ax}, // W+D |
679 | | - {-ax - az, -az + ax}, // S+A |
680 | | - {-ax + az, -az - ax} // S+D |
681 | | - }; |
682 | | - int selection = -1; |
683 | | - float closestX = 100000; |
684 | | - float closestZ = 100000; |
685 | | - for (int i = 0; i < options.length; i++) { |
686 | | - if (Math.abs(targetAx - options[i][0]) + Math.abs(targetAz - options[i][1]) < closestX + closestZ) { |
687 | | - closestX = Math.abs(targetAx - options[i][0]); |
688 | | - closestZ = Math.abs(targetAz - options[i][1]); |
689 | | - selection = i; |
690 | | - } |
691 | | - } |
| 671 | + int selection = getSelection(blockRotation, ax, az); |
692 | 672 | switch (selection) { |
693 | 673 | case 0: |
694 | 674 | state.setInput(Input.MOVE_FORWARD, true); |
@@ -719,6 +699,37 @@ static void moveTowardsWithRotation(IPlayerContext ctx, MovementState state, Blo |
719 | 699 | } |
720 | 700 | } |
721 | 701 |
|
| 702 | + private static int getSelection(Rotation blockRotation, float ax, float az) { |
| 703 | + float targetAx = Mth.sin(blockRotation.getYaw() * DEG_TO_RAD_F); |
| 704 | + float targetAz = Mth.cos(blockRotation.getYaw() * DEG_TO_RAD_F); |
| 705 | + float[][] options = getOptions(ax, az); |
| 706 | + int selection = -1; |
| 707 | + float closestX = 100000; |
| 708 | + float closestZ = 100000; |
| 709 | + for (int i = 0; i < options.length; i++) { |
| 710 | + if (Math.abs(targetAx - options[i][0]) + Math.abs(targetAz - options[i][1]) < closestX + closestZ) { |
| 711 | + closestX = Math.abs(targetAx - options[i][0]); |
| 712 | + closestZ = Math.abs(targetAz - options[i][1]); |
| 713 | + selection = i; |
| 714 | + } |
| 715 | + } |
| 716 | + return selection; |
| 717 | + } |
| 718 | + |
| 719 | + private static float[] @NotNull [] getOptions(float ax, float az) { |
| 720 | + boolean canSprint = Baritone.settings().allowSprint.value; |
| 721 | + return new float[][]{ |
| 722 | + {canSprint ? ax * 1.3f : ax, canSprint ? az * 1.3f : az}, // W |
| 723 | + {-ax, -az}, // S |
| 724 | + {-az, az}, // A |
| 725 | + {az, -ax}, // D |
| 726 | + {(canSprint ? ax * 1.3f : ax) - az, (canSprint ? az * 1.3f : az) + ax}, // W+A |
| 727 | + {(canSprint ? ax * 1.3f : ax) + az, (canSprint ? az * 1.3f : az) - ax}, // W+D |
| 728 | + {-ax - az, -az + ax}, // S+A |
| 729 | + {-ax + az, -az - ax} // S+D |
| 730 | + }; |
| 731 | + } |
| 732 | + |
722 | 733 | /** |
723 | 734 | * Returns whether or not the specified block is |
724 | 735 | * water, regardless of whether or not it is flowing. |
@@ -838,7 +849,7 @@ static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone, |
838 | 849 | if (ctx.getSelectedBlock().isPresent()) { |
839 | 850 | BlockPos selectedBlock = ctx.getSelectedBlock().get(); |
840 | 851 | Direction side = ((BlockHitResult) ctx.objectMouseOver()).getDirection(); |
841 | | - // only way for selectedBlock.equals(placeAt) to be true is if it's replacable |
| 852 | + // only way for selectedBlock.equals(placeAt) to be true is if it's replaceable |
842 | 853 | if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.relative(side).equals(placeAt))) { |
843 | 854 | if (wouldSneak) { |
844 | 855 | state.setInput(Input.SNEAK, true); |
|
0 commit comments