Add blockFreeLook setting
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user