pitch smooth look and setting for ticks

This commit is contained in:
Brady 2023-07-17 17:58:08 -05:00
parent 90cfd82810
commit 1b82bd1f33
No known key found for this signature in database
GPG Key ID: 73A788379A197567
2 changed files with 34 additions and 13 deletions

View File

@ -742,10 +742,21 @@ public final class Settings {
public final Setting<Boolean> elytraFreeLook = new Setting<>(false);
/**
* Forces the client-sided rotations to an average of the last 10 ticks of server-sided rotations.
* 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> smoothLook = new Setting<>(false);
public final Setting<Boolean> smoothLookYaw = 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<Boolean> smoothLookPitch = new Setting<>(false);
/**
* The number of ticks to average across for {@link #smoothLookYaw} and {@link #smoothLookPitch};
*/
public final Setting<Integer> smoothLookTicks = new Setting<>(10);
/**
* When true, the player will remain with its existing look direction as often as possible.

View File

@ -26,9 +26,10 @@ 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.ArrayDeque;
import java.util.Deque;
import java.util.Optional;
public final class LookBehavior extends Behavior implements ILookBehavior {
@ -52,12 +53,14 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
private final AimProcessor processor;
private final EvictingQueue<Float> smoothYawBuffer;
private final Deque<Float> smoothYawBuffer;
private final Deque<Float> smoothPitchBuffer;
public LookBehavior(Baritone baritone) {
super(baritone);
this.processor = new AimProcessor(baritone.getPlayerContext());
this.smoothYawBuffer = EvictingQueue.create(10);
this.smoothYawBuffer = new ArrayDeque<>();
this.smoothPitchBuffer = new ArrayDeque<>();
}
@Override
@ -100,15 +103,22 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
case POST: {
// Reset the player's rotations back to their original values
if (this.prevRotation != null) {
if (Baritone.settings().smoothLook.value) {
this.smoothYawBuffer.add(this.target.rotation.getYaw());
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.smoothYawBuffer.add(this.target.rotation.getYaw());
while (this.smoothYawBuffer.size() > Baritone.settings().smoothLookTicks.value) {
this.smoothYawBuffer.pop();
}
this.smoothPitchBuffer.add(this.target.rotation.getPitch());
while (this.smoothPitchBuffer.size() > Baritone.settings().smoothLookTicks.value) {
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();
this.prevRotation = null;
}
// The target is done being used for this game tick, so it can be invalidated