Merge pull request #4084 from babbaj/elytra

more intuitive smooth look/free look settings
This commit is contained in:
Brady Hahn 2023-08-01 00:19:08 -05:00 committed by GitHub
commit 231d3a376b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 32 deletions

View File

@ -737,24 +737,22 @@ public final class Settings {
public final Setting<Boolean> 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<Boolean> 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<Boolean> smoothLookYaw = new Setting<>(false);
public final Setting<Boolean> 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<Boolean> smoothLookPitch = new Setting<>(false);
public final Setting<Boolean> 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<Integer> smoothLookTicks = new Setting<>(10);

View File

@ -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;
}
}
}