Don't bother returning `serverRotations` if no free look

This commit is contained in:
Brady 2023-06-12 19:03:03 -05:00
parent ed34ae73c0
commit 13fc58933d
No known key found for this signature in database
GPG Key ID: 73A788379A197567
2 changed files with 11 additions and 8 deletions

View File

@ -28,6 +28,8 @@ import baritone.api.utils.IPlayerContext;
import baritone.api.utils.Rotation; import baritone.api.utils.Rotation;
import net.minecraft.network.play.client.CPacketPlayer; import net.minecraft.network.play.client.CPacketPlayer;
import java.util.Optional;
public final class LookBehavior extends Behavior implements ILookBehavior { public final class LookBehavior extends Behavior implements ILookBehavior {
/** /**
@ -70,9 +72,9 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch); this.prevRotation = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch);
} }
ctx.player().rotationYaw = this.target.rotation.getYaw();
float oldPitch = ctx.playerRotations().getPitch(); float oldPitch = ctx.playerRotations().getPitch();
float desiredPitch = this.target.rotation.getPitch(); float desiredPitch = this.target.rotation.getPitch();
ctx.player().rotationYaw = this.target.rotation.getYaw();
ctx.player().rotationPitch = desiredPitch; ctx.player().rotationPitch = desiredPitch;
ctx.player().rotationYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; ctx.player().rotationYaw += (Math.random() - 0.5) * Baritone.settings().randomLooking.value;
ctx.player().rotationPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value; ctx.player().rotationPitch += (Math.random() - 0.5) * Baritone.settings().randomLooking.value;
@ -126,8 +128,12 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
} }
} }
public Rotation getEffectiveRotation() { public Optional<Rotation> getEffectiveRotation() {
return this.serverRotation; if (Baritone.settings().freeLook.value || Baritone.settings().blockFreeLook.value) {
return Optional.of(this.serverRotation);
}
// If neither of the freeLook settings are on, just defer to the player's actual rotations
return Optional.empty();
} }
@Override @Override

View File

@ -58,11 +58,8 @@ public enum PrimaryPlayerContext implements IPlayerContext, Helper {
@Override @Override
public Rotation playerRotations() { public Rotation playerRotations() {
final Rotation lbTarget = ((LookBehavior) BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()).getEffectiveRotation(); return ((LookBehavior) BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()).getEffectiveRotation()
if (lbTarget == null || !Baritone.settings().blockFreeLook.value) { .orElseGet(IPlayerContext.super::playerRotations);
return IPlayerContext.super.playerRotations();
}
return lbTarget;
} }
@Override @Override