Skip to content

Commit a2a6769

Browse files
committed
Round yaw to 45 degrees when bridging.
1 parent 0eb0e67 commit a2a6769

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -661,27 +661,28 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
661661
}
662662

663663
static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) {
664-
float ax = Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F);
665-
float az = Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F);
666-
Rotation blockRotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
664+
float idealYaw = RotationUtils.calcRotationFromVec3d(
665+
ctx.playerHead(),
667666
VecUtils.getBlockPosCenter(dest),
668-
ctx.playerRotations());
669-
boolean canSprint = Baritone.settings().allowSprint.value;
670-
Arrays.stream(new MovementOption[]{
671-
new MovementOption(Input.MOVE_FORWARD, canSprint ? ax * 1.3f : ax, canSprint ? az * 1.3f : az),
672-
new MovementOption(Input.MOVE_BACK, -ax, -az),
673-
new MovementOption(Input.MOVE_LEFT, -az, ax),
674-
new MovementOption(Input.MOVE_RIGHT, az, -ax),
675-
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_LEFT, (canSprint ? ax * 1.3f : ax) - az, (canSprint ? az * 1.3f : az) + ax),
676-
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_RIGHT, (canSprint ? ax * 1.3f : ax) + az, (canSprint ? az * 1.3f : az) - ax),
677-
new MovementOption(Input.MOVE_BACK, Input.MOVE_LEFT, -ax - az, -az + ax),
678-
new MovementOption(Input.MOVE_BACK, Input.MOVE_RIGHT, -ax + az, -az - ax),
679-
}).min(Comparator.comparing(option -> option.distanceToSq(
680-
Mth.sin(blockRotation.getYaw() * DEG_TO_RAD_F),
681-
Mth.cos(blockRotation.getYaw() * DEG_TO_RAD_F)
667+
ctx.playerRotations()
668+
).getYaw();
669+
MovementOption.getOptions(
670+
Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F),
671+
Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F),
672+
Baritone.settings().allowSprint.value
673+
).min(Comparator.comparing(option -> option.distanceToSq(
674+
Mth.sin(idealYaw * DEG_TO_RAD_F),
675+
Mth.cos(idealYaw * DEG_TO_RAD_F)
682676
))).ifPresent(selection -> selection.setInputs(state));
683677
}
684678

679+
static void roundYaw(IPlayerContext ctx, MovementState state) {
680+
state.setTarget(new MovementTarget(new Rotation(
681+
Math.round(ctx.playerRotations().getYaw() / 45f) * 45f,
682+
ctx.playerRotations().getPitch()
683+
), true));
684+
}
685+
685686
/**
686687
* Returns whether or not the specified block is
687688
* water, regardless of whether or not it is flowing.

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import baritone.api.utils.input.Input;
2121
import net.minecraft.util.Mth;
2222

23+
import java.util.stream.Stream;
24+
2325
public record MovementOption(Input input1, Input input2, float motionX, float motionZ) {
2426

2527
public MovementOption(Input input1, float motionX, float motionZ) {
@@ -38,4 +40,17 @@ public void setInputs(MovementState movementState) {
3840
public float distanceToSq(float otherX, float otherZ) {
3941
return Mth.abs(motionX() - otherX) + Mth.abs(motionZ() - otherZ);
4042
}
43+
44+
public static Stream<MovementOption> getOptions(float motionX, float motionZ, boolean canSprint) {
45+
return Stream.of(
46+
new MovementOption(Input.MOVE_FORWARD, canSprint ? motionX * 1.3f : motionX, canSprint ? motionZ * 1.3f : motionZ),
47+
new MovementOption(Input.MOVE_BACK, -motionX, -motionZ),
48+
new MovementOption(Input.MOVE_LEFT, -motionZ, motionX),
49+
new MovementOption(Input.MOVE_RIGHT, motionZ, -motionX),
50+
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_LEFT, (canSprint ? motionX * 1.3f : motionX) - motionZ, (canSprint ? motionZ * 1.3f : motionZ) + motionX),
51+
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_RIGHT, (canSprint ? motionX * 1.3f : motionX) + motionZ, (canSprint ? motionZ * 1.3f : motionZ) - motionX),
52+
new MovementOption(Input.MOVE_BACK, Input.MOVE_LEFT, -motionX - motionZ, -motionZ + motionX),
53+
new MovementOption(Input.MOVE_BACK, Input.MOVE_RIGHT, -motionX + motionZ, -motionZ - motionX)
54+
);
55+
}
4156
}

src/main/java/baritone/pathing/movement/movements/MovementTraverse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ public MovementState updateState(MovementState state) {
356356
}
357357
return state;
358358
}
359+
MovementHelper.roundYaw(ctx, state);
359360
MovementHelper.moveTowardsWithoutRotation(ctx, state, dest);
360361
return state;
361362
}

0 commit comments

Comments
 (0)