Skip to content

Commit 5d8136b

Browse files
committed
Simplify.
1 parent 1911553 commit 5d8136b

File tree

1 file changed

+37
-26
lines changed

1 file changed

+37
-26
lines changed

src/main/java/baritone/pathing/movement/MovementHelper.java

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@
5050
import net.minecraft.world.phys.BlockHitResult;
5151
import net.minecraft.world.phys.HitResult;
5252
import net.minecraft.world.phys.Vec3;
53+
import org.jetbrains.annotations.NotNull;
5354

5455
import java.util.List;
5556
import java.util.Optional;
5657

58+
import static baritone.api.utils.RotationUtils.DEG_TO_RAD_F;
5759
import static baritone.pathing.movement.Movement.HORIZONTALS_BUT_ALSO_DOWN_____SO_EVERY_DIRECTION_EXCEPT_UP;
5860
import static baritone.pathing.precompute.Ternary.*;
5961

@@ -661,34 +663,12 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
661663

662664
static void moveTowardsWithRotation(IPlayerContext ctx, MovementState state, BlockPos dest, Rotation rotation) {
663665
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);
667668
Rotation blockRotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
668669
VecUtils.getBlockPosCenter(dest),
669670
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);
692672
switch (selection) {
693673
case 0:
694674
state.setInput(Input.MOVE_FORWARD, true);
@@ -719,6 +699,37 @@ static void moveTowardsWithRotation(IPlayerContext ctx, MovementState state, Blo
719699
}
720700
}
721701

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+
722733
/**
723734
* Returns whether or not the specified block is
724735
* water, regardless of whether or not it is flowing.
@@ -838,7 +849,7 @@ static PlaceResult attemptToPlaceABlock(MovementState state, IBaritone baritone,
838849
if (ctx.getSelectedBlock().isPresent()) {
839850
BlockPos selectedBlock = ctx.getSelectedBlock().get();
840851
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
842853
if (selectedBlock.equals(placeAt) || (MovementHelper.canPlaceAgainst(ctx, selectedBlock) && selectedBlock.relative(side).equals(placeAt))) {
843854
if (wouldSneak) {
844855
state.setInput(Input.SNEAK, true);

0 commit comments

Comments
 (0)