Add `blockFreeLook` setting

This commit is contained in:
Brady 2023-06-11 12:36:53 -05:00
parent 4b0a8eb166
commit 364ae87ef8
No known key found for this signature in database
GPG Key ID: 73A788379A197567
8 changed files with 50 additions and 20 deletions

View File

@ -723,6 +723,11 @@ public final class Settings {
*/
public final Setting<Boolean> freeLook = new Setting<>(true);
/**
* Break and place blocks without having to force the client-sided rotations
*/
public final Setting<Boolean> blockFreeLook = new Setting<>(true);
/**
* Will cause some minor behavioral differences to ensure that Baritone works on anticheats.
* <p>

View File

@ -26,12 +26,12 @@ public class Rotation {
/**
* The yaw angle of this Rotation
*/
private float yaw;
private final float yaw;
/**
* The pitch angle of this Rotation
*/
private float pitch;
private final float pitch;
public Rotation(float yaw, float pitch) {
this.yaw = yaw;
@ -110,6 +110,10 @@ public class Rotation {
);
}
public Rotation withPitch(float pitch) {
return new Rotation(this.yaw, pitch);
}
/**
* Is really close to
*

View File

@ -162,7 +162,8 @@ public final class RotationUtils {
public static Optional<Rotation> reachable(EntityPlayerSP entity, BlockPos pos, double blockReachDistance, boolean wouldSneak) {
IBaritone baritone = BaritoneAPI.getProvider().getBaritoneForPlayer(entity);
if (baritone.getPlayerContext().isLookingAt(pos)) {
IPlayerContext ctx = baritone.getPlayerContext();
if (ctx.isLookingAt(pos)) {
/*
* why add 0.0001?
* to indicate that we actually have a desired pitch
@ -173,7 +174,7 @@ public final class RotationUtils {
*
* or if you're a normal person literally all this does it ensure that we don't nudge the pitch to a normal level
*/
Rotation hypothetical = new Rotation(entity.rotationYaw, entity.rotationPitch + 0.0001F);
Rotation hypothetical = ctx.playerRotations().add(new Rotation(0, 0.0001F));
if (wouldSneak) {
// the concern here is: what if we're looking at it now, but as soon as we start sneaking we no longer are
RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, hypothetical, blockReachDistance, true);
@ -217,6 +218,7 @@ public final class RotationUtils {
*/
public static Optional<Rotation> reachableOffset(Entity entity, BlockPos pos, Vec3d offsetPos, double blockReachDistance, boolean wouldSneak) {
Vec3d eyes = wouldSneak ? RayTraceUtils.inferSneakingEyePosition(entity) : entity.getPositionEyes(1.0F);
// TODO: pr/feature/blockFreeLook - Use playerRotations() here?
Rotation rotation = calcRotationFromVec3d(eyes, offsetPos, new Rotation(entity.rotationYaw, entity.rotationPitch));
RayTraceResult result = RayTraceUtils.rayTraceTowards(entity, rotation, blockReachDistance, wouldSneak);
//System.out.println(result);

View File

@ -22,6 +22,7 @@ import baritone.api.Settings;
import baritone.api.behavior.ILookBehavior;
import baritone.api.event.events.PlayerUpdateEvent;
import baritone.api.event.events.RotationMoveEvent;
import baritone.api.event.events.type.EventState;
import baritone.api.utils.Rotation;
public final class LookBehavior extends Behavior implements ILookBehavior {
@ -34,17 +35,19 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
*/
private Rotation target;
private Rotation serverAngles;
/**
* Whether or not rotations are currently being forced
*/
private boolean force;
/**
* The last player yaw angle. Used when free looking
* The last player angles. Used when free looking
*
* @see Settings#freeLook
*/
private float lastYaw;
private Rotation prevAngles;
public LookBehavior(Baritone baritone) {
super(baritone);
@ -53,11 +56,14 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
@Override
public void updateTarget(Rotation target, boolean force) {
this.target = target;
this.force = force || !Baritone.settings().freeLook.value;
this.force = !Baritone.settings().blockFreeLook.value && (force || !Baritone.settings().freeLook.value);
}
@Override
public void onPlayerUpdate(PlayerUpdateEvent event) {
if (event.getState() == EventState.POST) {
this.serverAngles = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch);
}
if (this.target == null) {
return;
}
@ -80,14 +86,16 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
this.target = null;
}
if (silent) {
this.lastYaw = ctx.player().rotationYaw;
this.prevAngles = new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch);
ctx.player().rotationYaw = this.target.getYaw();
ctx.player().rotationPitch = this.target.getPitch();
}
break;
}
case POST: {
if (silent) {
ctx.player().rotationYaw = this.lastYaw;
ctx.player().rotationYaw = this.prevAngles.getYaw();
ctx.player().rotationPitch = this.prevAngles.getPitch();
this.target = null;
}
break;
@ -103,6 +111,10 @@ public final class LookBehavior extends Behavior implements ILookBehavior {
}
}
public Rotation getEffectiveAngles() {
return this.serverAngles;
}
@Override
public void onPlayerRotationMove(RotationMoveEvent event) {
if (this.target != null) {

View File

@ -599,9 +599,9 @@ public interface MovementHelper extends ActionCosts, Helper {
static void moveTowards(IPlayerContext ctx, MovementState state, BlockPos pos) {
state.setTarget(new MovementTarget(
new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
VecUtils.getBlockPosCenter(pos),
ctx.playerRotations()).getYaw(), ctx.player().rotationPitch),
ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()),
false
)).setInput(Input.MOVE_FORWARD, true);
}

View File

@ -234,11 +234,10 @@ public class MovementDescend extends Movement {
if (safeMode()) {
double destX = (src.getX() + 0.5) * 0.17 + (dest.getX() + 0.5) * 0.83;
double destZ = (src.getZ() + 0.5) * 0.17 + (dest.getZ() + 0.5) * 0.83;
EntityPlayerSP player = ctx.player();
state.setTarget(new MovementState.MovementTarget(
new Rotation(RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
new Vec3d(destX, dest.getY(), destZ),
new Rotation(player.rotationYaw, player.rotationPitch)).getYaw(), player.rotationPitch),
ctx.playerRotations()).withPitch(ctx.playerRotations().getPitch()),
false
)).setInput(Input.MOVE_FORWARD, true);
return state;

View File

@ -190,9 +190,9 @@ public class MovementPillar extends Movement {
boolean vine = fromDown.getBlock() == Blocks.VINE;
Rotation rotation = RotationUtils.calcRotationFromVec3d(ctx.playerHead(),
VecUtils.getBlockPosCenter(positionToPlace),
new Rotation(ctx.player().rotationYaw, ctx.player().rotationPitch));
ctx.playerRotations());
if (!ladder) {
state.setTarget(new MovementState.MovementTarget(new Rotation(ctx.player().rotationYaw, rotation.getPitch()), true));
state.setTarget(new MovementState.MovementTarget(ctx.playerRotations().withPitch(rotation.getPitch()), true));
}
boolean blockIsThere = MovementHelper.canWalkOn(ctx, src) || ladder;

View File

@ -17,12 +17,11 @@
package baritone.utils.player;
import baritone.Baritone;
import baritone.api.BaritoneAPI;
import baritone.api.cache.IWorldData;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import baritone.api.utils.IPlayerController;
import baritone.api.utils.RayTraceUtils;
import baritone.api.utils.*;
import baritone.behavior.LookBehavior;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
@ -57,6 +56,15 @@ public enum PrimaryPlayerContext implements IPlayerContext, Helper {
return BaritoneAPI.getProvider().getPrimaryBaritone().getWorldProvider().getCurrentWorld();
}
@Override
public Rotation playerRotations() {
final Rotation lbTarget = ((LookBehavior) BaritoneAPI.getProvider().getPrimaryBaritone().getLookBehavior()).getEffectiveAngles();
if (lbTarget == null || !Baritone.settings().blockFreeLook.value) {
return IPlayerContext.super.playerRotations();
}
return lbTarget;
}
@Override
public RayTraceResult objectMouseOver() {
return RayTraceUtils.rayTraceTowards(player(), playerRotations(), playerController().getBlockReachDistance());