Add `smoothLook` setting

This commit is contained in:
Brady 2023-06-25 15:28:06 -07:00
parent 1902e6c1f3
commit 9d1addd114
No known key found for this signature in database
GPG Key ID: 73A788379A197567
2 changed files with 13 additions and 2 deletions

View File

@ -58,6 +58,7 @@ public final class Settings {
public final Setting<Boolean> renderHitboxRaytraces = new Setting<>(false);
public final Setting<Boolean> renderElytraSimulation = new Setting<>(false);
public final Setting<Boolean> elytraFreeLook = new Setting<>(false);
public final Setting<Boolean> smoothLook = new Setting<>(false);
// Experimental Elytra Settings
public final Setting<Boolean> experimentalTakeoff = new Setting<>(false);

View File

@ -26,6 +26,7 @@ import baritone.api.event.events.*;
import baritone.api.utils.IPlayerContext;
import baritone.api.utils.Rotation;
import baritone.behavior.look.ForkableRandom;
import com.google.common.collect.EvictingQueue;
import net.minecraft.network.play.client.CPacketPlayer;
import java.util.Optional;
@ -51,9 +52,12 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
private final AimProcessor processor;
private final EvictingQueue<Float> smoothYawBuffer;
public LookBehavior(Baritone baritone) {
super(baritone);
this.processor = new AimProcessor(baritone.getPlayerContext());
this.smoothYawBuffer = EvictingQueue.create(10);
}
@Override
@ -96,8 +100,14 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
case POST: {
// Reset the player's rotations back to their original values
if (this.prevRotation != null) {
ctx.player().rotationYaw = this.prevRotation.getYaw();
ctx.player().rotationPitch = this.prevRotation.getPitch();
if (Baritone.settings().smoothLook.value) {
ctx.player().rotationYaw = (float) this.smoothYawBuffer.stream()
.mapToDouble(d -> d).average().orElseGet(this.prevRotation::getYaw);
ctx.player().rotationPitch = this.prevRotation.getPitch();
} else {
ctx.player().rotationYaw = this.prevRotation.getYaw();
ctx.player().rotationPitch = this.prevRotation.getPitch();
}
this.prevRotation = null;
}
// The target is done being used for this game tick, so it can be invalidated