Skip to content

Commit 61c0a09

Browse files
committed
Add 45 degree intervals to yaw change.
1 parent a2a6769 commit 61c0a09

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

src/api/java/baritone/api/utils/Rotation.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ public static float normalizeYaw(float yaw) {
159159
return newYaw;
160160
}
161161

162+
/**
163+
* Gets the distance between a starting yaw and an offset yaw.
164+
* Distance can be negative if the offset yaw is left of the starting yaw.
165+
*
166+
* @param yaw The initial yaw
167+
* @param offsetYaw The offset yaw
168+
* @return The distance between the yaws
169+
*/
170+
public static float yawDistanceFromOffset(float yaw, float offsetYaw) {
171+
if ((yaw > 0 ^ offsetYaw > 0) && ((yaw > 90 || yaw < -90) ^ (offsetYaw > 90 || offsetYaw < -90))) {
172+
if (yaw < 0) {
173+
return 360 + (yaw - offsetYaw);
174+
} else {
175+
return 360 - (yaw - offsetYaw);
176+
}
177+
} else {
178+
return yaw - offsetYaw;
179+
}
180+
}
181+
162182
@Override
163183
public String toString() {
164184
return "Yaw: " + yaw + ", Pitch: " + pitch;

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,7 @@ static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
660660
)).setInput(Input.MOVE_FORWARD, true);
661661
}
662662

663-
static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) {
664-
float idealYaw = RotationUtils.calcRotationFromVec3d(
665-
ctx.playerHead(),
666-
VecUtils.getBlockPosCenter(dest),
667-
ctx.playerRotations()
668-
).getYaw();
663+
static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, float idealYaw) {
669664
MovementOption.getOptions(
670665
Mth.sin(ctx.playerRotations().getYaw() * DEG_TO_RAD_F),
671666
Mth.cos(ctx.playerRotations().getYaw() * DEG_TO_RAD_F),
@@ -676,9 +671,39 @@ static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state,
676671
))).ifPresent(selection -> selection.setInputs(state));
677672
}
678673

679-
static void roundYaw(IPlayerContext ctx, MovementState state) {
674+
static void moveTowardsWithoutRotation(IPlayerContext ctx, MovementState state, BlockPos dest) {
675+
float idealYaw = RotationUtils.calcRotationFromVec3d(
676+
ctx.playerHead(),
677+
VecUtils.getBlockPosCenter(dest),
678+
ctx.playerRotations()
679+
).getYaw();
680+
moveTowardsWithoutRotation(ctx, state, idealYaw);
681+
}
682+
683+
static void moveTowardsWithSlightRotation(IPlayerContext ctx, MovementState state, BlockPos dest) {
684+
float idealYaw = RotationUtils.calcRotationFromVec3d(
685+
ctx.playerHead(),
686+
VecUtils.getBlockPosCenter(dest),
687+
ctx.playerRotations()
688+
).getYaw();
689+
moveTowardsWithoutRotation(ctx, state, idealYaw);
690+
float distance = Rotation.yawDistanceFromOffset(ctx.playerRotations().getYaw(), idealYaw) % 45f;
691+
float newYaw;
692+
if (distance > 0) {
693+
if (distance > 22.5f) {
694+
newYaw = -45f + distance;
695+
} else {
696+
newYaw = distance;
697+
}
698+
} else {
699+
if (distance < -22.5f) {
700+
newYaw = 45f + distance;
701+
} else {
702+
newYaw = distance;
703+
}
704+
}
680705
state.setTarget(new MovementTarget(new Rotation(
681-
Math.round(ctx.playerRotations().getYaw() / 45f) * 45f,
706+
ctx.playerRotations().getYaw() - newYaw,
682707
ctx.playerRotations().getPitch()
683708
), true));
684709
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ public MovementState updateState(MovementState state) {
356356
}
357357
return state;
358358
}
359-
MovementHelper.roundYaw(ctx, state);
360-
MovementHelper.moveTowardsWithoutRotation(ctx, state, dest);
359+
MovementHelper.moveTowardsWithSlightRotation(ctx, state, dest);
361360
return state;
362361
}
363362
}

0 commit comments

Comments
 (0)