diff --git a/src/api/java/baritone/api/utils/Rotation.java b/src/api/java/baritone/api/utils/Rotation.java index c75a9a559..2ae67e7ae 100644 --- a/src/api/java/baritone/api/utils/Rotation.java +++ b/src/api/java/baritone/api/utils/Rotation.java @@ -159,6 +159,26 @@ public class Rotation { return newYaw; } + /** + * Gets the distance between a starting yaw and an offset yaw. + * Distance can be negative if the offset yaw is left of the starting yaw. + * + * @param yaw The initial yaw + * @param offsetYaw The offset yaw + * @return The distance between the yaws + */ + public static float yawDistanceFromOffset(float yaw, float offsetYaw) { + if ((yaw > 0 ^ offsetYaw > 0) && ((yaw > 90 || yaw < -90) ^ (offsetYaw > 90 || offsetYaw < -90))) { + if (yaw < 0) { + return 360 + (yaw - offsetYaw); + } else { + return 360 - (yaw - offsetYaw); + } + } else { + return yaw - offsetYaw; + } + } + @Override public String toString() { return "Yaw: " + yaw + ", Pitch: " + pitch; diff --git a/src/main/java/baritone/pathing/movement/MovementHelper.java b/src/main/java/baritone/pathing/movement/MovementHelper.java index 6e82172c5..08fb2e3d8 100644 --- a/src/main/java/baritone/pathing/movement/MovementHelper.java +++ b/src/main/java/baritone/pathing/movement/MovementHelper.java @@ -660,12 +660,7 @@ public interface MovementHelper extends ActionCosts, Helper { )).setInput(Input.MOVE_FORWARD, true); } - static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) { - float idealYaw = RotationUtils.calcRotationFromVec3d( - ctx.playerHead(), - VecUtils.getBlockPosCenter(dest), - ctx.playerRotations() - ).getYaw(); + static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, float idealYaw) { MovementOption.getOptions( Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F), Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F), @@ -676,9 +671,39 @@ public interface MovementHelper extends ActionCosts, Helper { ))).ifPresent(selection -> selection.setInputs(state)); } - static void roundYaw(IPlayerContext ctx, MovementState state) { + static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) { + float idealYaw = RotationUtils.calcRotationFromVec3d( + ctx.playerHead(), + VecUtils.getBlockPosCenter(dest), + ctx.playerRotations() + ).getYaw(); + moveTowardsWithoutRotation(ctx, state, idealYaw); + } + + static void moveTowardsWithSlightRotation(IPlayerContext ctx, MovementState state, BlockPos dest) { + float idealYaw = RotationUtils.calcRotationFromVec3d( + ctx.playerHead(), + VecUtils.getBlockPosCenter(dest), + ctx.playerRotations() + ).getYaw(); + moveTowardsWithoutRotation(ctx, state, idealYaw); + float distance = Rotation.yawDistanceFromOffset(ctx.playerRotations().getYaw(), idealYaw) % 45f; + float newYaw; + if (distance > 0) { + if (distance > 22.5f) { + newYaw = -45f + distance; + } else { + newYaw = distance; + } + } else { + if (distance < -22.5f) { + newYaw = 45f + distance; + } else { + newYaw = distance; + } + } state.setTarget(new MovementTarget(new Rotation( - Math.round(ctx.playerRotations().getYaw() / 45f) * 45f, + ctx.playerRotations().getYaw() - newYaw, ctx.playerRotations().getPitch() ), true)); } diff --git a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java index e1d7571d8..156da1adb 100644 --- a/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java +++ b/src/main/java/baritone/pathing/movement/movements/MovementTraverse.java @@ -356,8 +356,7 @@ public class MovementTraverse extends Movement { } return state; } - MovementHelper.roundYaw(ctx, state); - MovementHelper.moveTowardsWithoutRotation(ctx, state, dest); + MovementHelper.moveTowardsWithSlightRotation(ctx, state, dest); return state; } }