diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index d7086dad4..051cb5686 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -737,24 +737,22 @@ public final class Settings { public final Setting blockFreeLook = new Setting<>(false); /** - * Automatically elytra fly without having to force the client-sided rotations. Requires {@link #freeLook}. + * Automatically elytra fly without having to force the client-sided rotations. */ public final Setting elytraFreeLook = new Setting<>(false); /** * Forces the client-sided yaw rotation to an average of the last {@link #smoothLookTicks} of server-sided rotations. - * Requires {@link #freeLook}. */ - public final Setting smoothLookYaw = new Setting<>(false); + public final Setting smoothLook = new Setting<>(false); /** - * Forces the client-sided pitch rotation to an average of the last {@link #smoothLookTicks} of server-sided rotations. - * Requires {@link #freeLook}. + * Same as {@link #smoothLook} but for elytra flying. */ - public final Setting smoothLookPitch = new Setting<>(false); + public final Setting elytraSmoothLook = new Setting<>(true); /** - * The number of ticks to average across for {@link #smoothLookYaw} and {@link #smoothLookPitch}; + * The number of ticks to average across for {@link #smoothLook}; */ public final Setting smoothLookTicks = new Setting<>(10); diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 5f6421d08..5c46c6d2f 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -91,10 +91,8 @@ public final class LookBehavior extends Behavior implements ILookBehavior { // Just return for PRE, we still want to set target to null on POST return; } - if (this.target.mode == Target.Mode.SERVER) { - this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); - } + this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); final Rotation actual = this.processor.peekRotation(this.target.rotation); ctx.player().rotationYaw = actual.getYaw(); ctx.player().rotationPitch = actual.getPitch(); @@ -103,21 +101,23 @@ public final class LookBehavior extends Behavior implements ILookBehavior { case POST: { // Reset the player's rotations back to their original values if (this.prevRotation != null) { - this.smoothYawBuffer.add(this.target.rotation.getYaw()); + this.smoothYawBuffer.addLast(this.target.rotation.getYaw()); while (this.smoothYawBuffer.size() > Baritone.settings().smoothLookTicks.value) { - this.smoothYawBuffer.pop(); + this.smoothYawBuffer.removeFirst(); } - this.smoothPitchBuffer.add(this.target.rotation.getPitch()); + this.smoothPitchBuffer.addLast(this.target.rotation.getPitch()); while (this.smoothPitchBuffer.size() > Baritone.settings().smoothLookTicks.value) { - this.smoothPitchBuffer.pop(); + this.smoothPitchBuffer.removeFirst(); + } + if (this.target.mode == Target.Mode.SERVER) { + ctx.player().rotationYaw = this.prevRotation.getYaw(); + ctx.player().rotationPitch = this.prevRotation.getPitch(); + } else if (ctx.player().isElytraFlying() ? Baritone.settings().elytraSmoothLook.value : Baritone.settings().smoothLook.value) { + ctx.player().rotationYaw = (float) this.smoothYawBuffer.stream().mapToDouble(d -> d).average().orElse(this.prevRotation.getYaw()); + if (ctx.player().isElytraFlying()) { + ctx.player().rotationPitch = (float) this.smoothPitchBuffer.stream().mapToDouble(d -> d).average().orElse(this.prevRotation.getPitch()); + } } - - ctx.player().rotationYaw = Baritone.settings().smoothLookYaw.value - ? (float) this.smoothYawBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getYaw) - : this.prevRotation.getYaw(); - ctx.player().rotationPitch = Baritone.settings().smoothLookPitch.value - ? (float) this.smoothPitchBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getPitch) - : this.prevRotation.getPitch(); this.prevRotation = null; } @@ -325,22 +325,22 @@ public final class LookBehavior extends Behavior implements ILookBehavior { final Settings settings = Baritone.settings(); final boolean antiCheat = settings.antiCheatCompatibility.value; final boolean blockFreeLook = settings.blockFreeLook.value; - final boolean freeLook = settings.freeLook.value; - - if (!freeLook) return CLIENT; - if (!blockFreeLook && blockInteract) return CLIENT; if (ctx.player().isElytraFlying()) { + // always need to set angles while flying return settings.elytraFreeLook.value ? SERVER : CLIENT; + } else if (settings.freeLook.value) { + // Regardless of if antiCheatCompatibility is enabled, if a blockInteract is requested then the player + // rotation needs to be set somehow, otherwise Baritone will halt since objectMouseOver() will just be + // whatever the player is mousing over visually. Let's just settle for setting it silently. + if (blockInteract) { + return blockFreeLook ? SERVER : CLIENT; + } + return antiCheat ? SERVER : NONE; } - // Regardless of if antiCheatCompatibility is enabled, if a blockInteract is requested then the player - // rotation needs to be set somehow, otherwise Baritone will halt since objectMouseOver() will just be - // whatever the player is mousing over visually. Let's just settle for setting it silently. - if (antiCheat || blockInteract) return SERVER; - - // Pathing regularly without antiCheatCompatibility, don't set the player rotation - return NONE; + // all freeLook settings are disabled so set the angles + return CLIENT; } } }