From c0a1e6540ff312668a9d666433bf5917484a594c Mon Sep 17 00:00:00 2001 From: Babbaj Date: Mon, 31 Jul 2023 16:14:09 -0400 Subject: [PATCH 1/4] simplify smoothLook into one setting and separate smoothLook from freeLook --- src/api/java/baritone/api/Settings.java | 10 ++------- .../java/baritone/behavior/LookBehavior.java | 21 ++++++++++--------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index d7086dad4..46a7f62e2 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -745,16 +745,10 @@ public final class Settings { * 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}. - */ - public final Setting smoothLookPitch = new Setting<>(false); - - /** - * 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..869b8efb8 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -112,12 +112,15 @@ public final class LookBehavior extends Behavior implements ILookBehavior { this.smoothPitchBuffer.pop(); } - 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(); + if (Baritone.settings().freeLook.value) { + ctx.player().rotationYaw = this.prevRotation.getYaw(); + ctx.player().rotationPitch = this.prevRotation.getPitch(); + } else if (Baritone.settings().smoothLook.value) { + ctx.player().rotationYaw = (float) this.smoothYawBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getYaw); + ctx.player().rotationPitch = ctx.player().isElytraFlying() + ? (float) this.smoothPitchBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getPitch) + : this.prevRotation.getPitch(); + } this.prevRotation = null; } @@ -327,12 +330,10 @@ public final class LookBehavior extends Behavior implements ILookBehavior { final boolean blockFreeLook = settings.blockFreeLook.value; final boolean freeLook = settings.freeLook.value; - if (!freeLook) return CLIENT; + if (!freeLook && !settings.smoothLook.value) return CLIENT; if (!blockFreeLook && blockInteract) return CLIENT; - if (ctx.player().isElytraFlying()) { - return settings.elytraFreeLook.value ? SERVER : CLIENT; - } + // 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 From 0ca173f5dcb4c770791b93242bf47ee83560a264 Mon Sep 17 00:00:00 2001 From: Babbaj Date: Mon, 31 Jul 2023 16:41:10 -0400 Subject: [PATCH 2/4] separate smooth look setting for elytra --- src/api/java/baritone/api/Settings.java | 8 ++++++-- src/main/java/baritone/behavior/LookBehavior.java | 8 ++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 46a7f62e2..051cb5686 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -737,16 +737,20 @@ 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 smoothLook = new Setting<>(false); + /** + * Same as {@link #smoothLook} but for elytra flying. + */ + public final Setting elytraSmoothLook = new Setting<>(true); + /** * The number of ticks to average across for {@link #smoothLook}; */ diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 869b8efb8..133c00e73 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -112,10 +112,10 @@ public final class LookBehavior extends Behavior implements ILookBehavior { this.smoothPitchBuffer.pop(); } - if (Baritone.settings().freeLook.value) { + if ((ctx.player().isElytraFlying() && Baritone.settings().elytraFreeLook.value) || (!ctx.player().isElytraFlying() && Baritone.settings().freeLook.value)) { ctx.player().rotationYaw = this.prevRotation.getYaw(); ctx.player().rotationPitch = this.prevRotation.getPitch(); - } else if (Baritone.settings().smoothLook.value) { + } else if ((ctx.player().isElytraFlying() && Baritone.settings().elytraSmoothLook.value) || (!ctx.player().isElytraFlying() && Baritone.settings().smoothLook.value)) { ctx.player().rotationYaw = (float) this.smoothYawBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getYaw); ctx.player().rotationPitch = ctx.player().isElytraFlying() ? (float) this.smoothPitchBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getPitch) @@ -328,13 +328,9 @@ 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 && !settings.smoothLook.value) return CLIENT; if (!blockFreeLook && blockInteract) return CLIENT; - - // 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. From 7aa3eda3f6d75c5fdaea7a6c4be71921f2e1c34c Mon Sep 17 00:00:00 2001 From: Babbaj Date: Mon, 31 Jul 2023 17:07:38 -0400 Subject: [PATCH 3/4] fix nudgeToLevel with smoothLook --- src/main/java/baritone/behavior/LookBehavior.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 133c00e73..9a43f0099 100644 --- a/src/main/java/baritone/behavior/LookBehavior.java +++ b/src/main/java/baritone/behavior/LookBehavior.java @@ -117,9 +117,9 @@ public final class LookBehavior extends Behavior implements ILookBehavior { ctx.player().rotationPitch = this.prevRotation.getPitch(); } else if ((ctx.player().isElytraFlying() && Baritone.settings().elytraSmoothLook.value) || (!ctx.player().isElytraFlying() && Baritone.settings().smoothLook.value)) { ctx.player().rotationYaw = (float) this.smoothYawBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getYaw); - ctx.player().rotationPitch = ctx.player().isElytraFlying() - ? (float) this.smoothPitchBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getPitch) - : this.prevRotation.getPitch(); + if (ctx.player().isElytraFlying()) { + ctx.player().rotationPitch = (float) this.smoothPitchBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getPitch); + } } this.prevRotation = null; From 379156951940a04e602dd0409a24bc69847b7768 Mon Sep 17 00:00:00 2001 From: Babbaj Date: Mon, 31 Jul 2023 22:31:45 -0400 Subject: [PATCH 4/4] refactor so that Target.Mode is not a lie fine yes honey --- .../java/baritone/behavior/LookBehavior.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/baritone/behavior/LookBehavior.java b/src/main/java/baritone/behavior/LookBehavior.java index 9a43f0099..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,22 +101,21 @@ 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 ((ctx.player().isElytraFlying() && Baritone.settings().elytraFreeLook.value) || (!ctx.player().isElytraFlying() && Baritone.settings().freeLook.value)) { + 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) || (!ctx.player().isElytraFlying() && Baritone.settings().smoothLook.value)) { - ctx.player().rotationYaw = (float) this.smoothYawBuffer.stream().mapToDouble(d -> d).average().orElseGet(this.prevRotation::getYaw); + } 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().orElseGet(this.prevRotation::getPitch); + ctx.player().rotationPitch = (float) this.smoothPitchBuffer.stream().mapToDouble(d -> d).average().orElse(this.prevRotation.getPitch()); } } @@ -329,15 +326,21 @@ public final class LookBehavior extends Behavior implements ILookBehavior { final boolean antiCheat = settings.antiCheatCompatibility.value; final boolean blockFreeLook = settings.blockFreeLook.value; - 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; } } }