Round yaw to 45 degrees when bridging.

This commit is contained in:
Murat65536
2025-08-23 20:25:16 -04:00
parent 0eb0e6709a
commit a2a6769742
3 changed files with 34 additions and 17 deletions

View File

@@ -661,27 +661,28 @@ public interface MovementHelper extends ActionCosts, Helper {
}
static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) {
float ax = Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F);
float az = Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F);
Rotation blockRotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
float idealYaw = RotationUtils.calcRotationFromVec3d(
ctx.playerHead(),
VecUtils.getBlockPosCenter(dest),
ctx.playerRotations());
boolean canSprint = Baritone.settings().allowSprint.value;
Arrays.stream(new MovementOption[]{
new MovementOption(Input.MOVE_FORWARD, canSprint ? ax * 1.3f : ax, canSprint ? az * 1.3f : az),
new MovementOption(Input.MOVE_BACK, -ax, -az),
new MovementOption(Input.MOVE_LEFT, -az, ax),
new MovementOption(Input.MOVE_RIGHT, az, -ax),
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_LEFT, (canSprint ? ax * 1.3f : ax) - az, (canSprint ? az * 1.3f : az) + ax),
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_RIGHT, (canSprint ? ax * 1.3f : ax) + az, (canSprint ? az * 1.3f : az) - ax),
new MovementOption(Input.MOVE_BACK, Input.MOVE_LEFT, -ax - az, -az + ax),
new MovementOption(Input.MOVE_BACK, Input.MOVE_RIGHT, -ax + az, -az - ax),
}).min(Comparator.comparing(option -> option.distanceToSq(
Mth.sin(blockRotation.getYaw() * DEG_TO_RAD_F),
Mth.cos(blockRotation.getYaw() * DEG_TO_RAD_F)
ctx.playerRotations()
).getYaw();
MovementOption.getOptions(
Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F),
Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F),
Baritone.settings().allowSprint.value
).min(Comparator.comparing(option -> option.distanceToSq(
Mth.sin(idealYaw * DEG_TO_RAD_F),
Mth.cos(idealYaw * DEG_TO_RAD_F)
))).ifPresent(selection -> selection.setInputs(state));
}
static void roundYaw(IPlayerContext ctx, MovementState state) {
state.setTarget(new MovementTarget(new Rotation(
Math.round(ctx.playerRotations().getYaw() / 45f) * 45f,
ctx.playerRotations().getPitch()
), true));
}
/**
* Returns whether or not the specified block is
* water, regardless of whether or not it is flowing.

View File

@@ -20,6 +20,8 @@ package baritone.pathing.movement;
import baritone.api.utils.input.Input;
import net.minecraft.util.Mth;
import java.util.stream.Stream;
public record MovementOption(Input input1, Input input2, float motionX, float motionZ) {
public MovementOption(Input input1, float motionX, float motionZ) {
@@ -38,4 +40,17 @@ public record MovementOption(Input input1, Input input2, float motionX, float mo
public float distanceToSq(float otherX, float otherZ) {
return Mth.abs(motionX() - otherX) + Mth.abs(motionZ() - otherZ);
}
public static Stream<MovementOption> getOptions(float motionX, float motionZ, boolean canSprint) {
return Stream.of(
new MovementOption(Input.MOVE_FORWARD, canSprint ? motionX * 1.3f : motionX, canSprint ? motionZ * 1.3f : motionZ),
new MovementOption(Input.MOVE_BACK, -motionX, -motionZ),
new MovementOption(Input.MOVE_LEFT, -motionZ, motionX),
new MovementOption(Input.MOVE_RIGHT, motionZ, -motionX),
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_LEFT, (canSprint ? motionX * 1.3f : motionX) - motionZ, (canSprint ? motionZ * 1.3f : motionZ) + motionX),
new MovementOption(Input.MOVE_FORWARD, Input.MOVE_RIGHT, (canSprint ? motionX * 1.3f : motionX) + motionZ, (canSprint ? motionZ * 1.3f : motionZ) - motionX),
new MovementOption(Input.MOVE_BACK, Input.MOVE_LEFT, -motionX - motionZ, -motionZ + motionX),
new MovementOption(Input.MOVE_BACK, Input.MOVE_RIGHT, -motionX + motionZ, -motionZ - motionX)
);
}
}

View File

@@ -356,6 +356,7 @@ public class MovementTraverse extends Movement {
}
return state;
}
MovementHelper.roundYaw(ctx, state);
MovementHelper.moveTowardsWithoutRotation(ctx, state, dest);
return state;
}