Skip to content

Commit 133281d

Browse files
committed
make baritone override literally everything rotation related. Still uses packet mine or fast break if either are enabled, but now works without them too.
1 parent 67ac955 commit 133281d

13 files changed

Lines changed: 107 additions & 60 deletions

src/main/java/com/lambda/mixin/baritone/BaritonePlayerContextMixin.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,28 @@
3333

3434
@Mixin(value = BaritonePlayerContext.class, remap = false) // fix compileJava warning
3535
public abstract class BaritonePlayerContextMixin {
36-
@Shadow
37-
@Final
38-
private Baritone baritone;
39-
40-
@Shadow
41-
public abstract ClientPlayerEntity player();
42-
43-
// Let baritone know the actual rotation
44-
@ModifyReturnValue(method = "playerRotations", at = @At("RETURN"), remap = false)
45-
Rotation syncRotationWithBaritone(Rotation original) {
46-
if (baritone != BaritoneHandler.getPrimary()) return original;
47-
48-
var baritoneRot = baritone.getLookBehavior().getEffectiveRotation();
49-
var lambdaRot = RotationManager.getActiveRotation();
50-
51-
float yaw = baritoneRot.map(Rotation::getYaw).orElseGet(lambdaRot::getYawF);
52-
float pitch = baritoneRot.map(Rotation::getPitch).orElseGet(lambdaRot::getPitchF);
53-
54-
if (Float.isNaN(yaw) || Float.isNaN(pitch)) {
55-
return original;
56-
}
57-
58-
return new Rotation(wrapDegrees(yaw), pitch);
59-
}
36+
// @Shadow
37+
// @Final
38+
// private Baritone baritone;
39+
//
40+
// @Shadow
41+
// public abstract ClientPlayerEntity player();
42+
//
43+
// // Let baritone know the actual rotation
44+
// @ModifyReturnValue(method = "playerRotations", at = @At("RETURN"), remap = false)
45+
// Rotation syncRotationWithBaritone(Rotation original) {
46+
// if (baritone != BaritoneHandler.getPrimary()) return original;
47+
//
48+
// var baritoneRot = baritone.getLookBehavior().getEffectiveRotation();
49+
// var lambdaRot = RotationManager.getActiveRotation();
50+
//
51+
// float yaw = baritoneRot.map(Rotation::getYaw).orElseGet(lambdaRot::getYawF);
52+
// float pitch = baritoneRot.map(Rotation::getPitch).orElseGet(lambdaRot::getPitchF);
53+
//
54+
// if (Float.isNaN(yaw) || Float.isNaN(pitch)) {
55+
// return original;
56+
// }
57+
//
58+
// return new Rotation(wrapDegrees(yaw), pitch);
59+
// }
6060
}

src/main/java/com/lambda/mixin/baritone/BaritonePlayerControllerMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030

3131
@Mixin(BaritonePlayerController.class)
3232
public class BaritonePlayerControllerMixin {
33-
@Inject(method = "clickBlock", at = @At("HEAD"))
33+
@Inject(method = "clickBlock", at = @At("HEAD"), cancellable = true)
3434
private void injectClickBlock(BlockPos loc, Direction face, CallbackInfoReturnable<Boolean> cir) {
3535
if (PacketMine.INSTANCE.isEnabled() || FastBreak.INSTANCE.isEnabled()) {
3636
var interaction = Lambda.getMc().interactionManager;
3737
if (interaction == null) return;
3838
interaction.updateBlockBreakingProgress(loc, face);
39+
cir.cancel();
3940
}
4041
}
4142
}

src/main/java/com/lambda/mixin/baritone/LookBehaviourMixin.java

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,28 @@
2929
import org.spongepowered.asm.mixin.injection.At;
3030
import org.spongepowered.asm.mixin.injection.Inject;
3131
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
32+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
33+
34+
import java.util.Optional;
3235

3336
@Mixin(value = LookBehavior.class, remap = false)
3437
public class LookBehaviourMixin {
35-
@Unique
36-
LookBehavior instance = (LookBehavior) (Object) this;
37-
38-
// Redirect baritone's rotations into our rotation engine
39-
@Inject(method = "updateTarget", at = @At("HEAD"))
40-
void onTargetUpdate(Rotation rotation, boolean blockInteract, CallbackInfo ci) {
41-
if (instance.baritone != BaritoneHandler.getPrimary()) return;
42-
RotationManager.handleBaritoneRotation(rotation.getYaw(), rotation.getPitch());
43-
}
44-
45-
@WrapOperation(method = "onPlayerUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;setYaw(F)V"))
46-
private void wrapSetYaw(ClientPlayerEntity instance, float v, Operation<Void> original) {}
47-
48-
@WrapOperation(method = "onPlayerUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;setPitch(F)V"))
49-
private void wrapSetPitch(ClientPlayerEntity instance, float v, Operation<Void> original) {}
50-
51-
@WrapOperation(method = "pig", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;setYaw(F)V"))
52-
private void wrapPigSetYaw(ClientPlayerEntity instance, float v, Operation<Void> original) {}
38+
// @Unique
39+
// LookBehavior instance = (LookBehavior) (Object) this;
40+
//
41+
// // Redirect baritone's rotations into our rotation engine
42+
// @Inject(method = "updateTarget", at = @At("HEAD"))
43+
// void onTargetUpdate(Rotation rotation, boolean blockInteract, CallbackInfo ci) {
44+
// if (instance.baritone != BaritoneHandler.getPrimary()) return;
45+
// RotationManager.handleBaritoneRotation(rotation.getYaw(), rotation.getPitch());
46+
// }
47+
//
48+
// @WrapOperation(method = "onPlayerUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;setYaw(F)V"))
49+
// private void wrapSetYaw(ClientPlayerEntity instance, float v, Operation<Void> original) {}
50+
//
51+
// @WrapOperation(method = "onPlayerUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;setPitch(F)V"))
52+
// private void wrapSetPitch(ClientPlayerEntity instance, float v, Operation<Void> original) {}
53+
//
54+
// @WrapOperation(method = "pig", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;setYaw(F)V"))
55+
// private void wrapPigSetYaw(ClientPlayerEntity instance, float v, Operation<Void> original) {}
5356
}

src/main/java/com/lambda/mixin/entity/ClientPlayInteractionManagerMixin.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.lambda.event.EventFlow;
2121
import com.lambda.event.events.InventoryEvent;
2222
import com.lambda.event.events.PlayerEvent;
23+
import com.lambda.interaction.BaritoneHandler;
2324
import com.lambda.interaction.managers.inventory.InventoryManager;
2425
import com.lambda.interaction.managers.rotating.RotationManager;
2526
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
@@ -77,12 +78,16 @@ public void interactItemHead(PlayerEntity player, Hand hand, CallbackInfoReturna
7778

7879
@ModifyExpressionValue(method = "method_41929", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getYaw()F"))
7980
private float modifyHand(float original) {
81+
if (BaritoneHandler.isActive()) return original;
82+
8083
var headYaw = RotationManager.getHeadYaw();
8184
return headYaw != null ? headYaw : original;
8285
}
8386

8487
@ModifyExpressionValue(method = "method_41929", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getPitch()F"))
8588
private float modifySequence(float original) {
89+
if (BaritoneHandler.isActive()) return original;
90+
8691
var headPitch = RotationManager.getHeadPitch();
8792
return headPitch != null ? headPitch : original;
8893
}

src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.lambda.event.EventFlow;
2121
import com.lambda.event.events.*;
22+
import com.lambda.interaction.BaritoneHandler;
2223
import com.lambda.interaction.managers.rotating.RotationManager;
2324
import com.lambda.module.modules.movement.elytrafly.ElytraFly;
2425
import com.lambda.module.modules.movement.NoJumpCooldown;
@@ -70,6 +71,8 @@ void onTick(Operation<Void> original) {
7071

7172
@Inject(method = "tick", at = @At("HEAD"))
7273
private void injectTick(CallbackInfo ci, @Share(namespace = "shared_rotations", value = "target_rotation") final LocalRef<Vec2f> targetRotation) {
74+
if (BaritoneHandler.isActive()) return;
75+
7376
if (RotationManager.getRequests().stream().anyMatch(Objects::nonNull)) {
7477
final var activeRotation = RotationManager.getActiveRotation();
7578
targetRotation.set(new Vec2f(activeRotation.getYawF(), activeRotation.getPitchF()));
@@ -93,8 +96,10 @@ private void wrapMove(ClientPlayerEntity instance, MovementType movementType, Ve
9396
@WrapOperation(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick()V"))
9497
void wrapTick(Input input, Operation<Void> original) {
9598
original.call(input);
96-
RotationManager.processRotations();
97-
RotationManager.redirectStrafeInputs(input);
99+
if (!BaritoneHandler.isActive()) {
100+
RotationManager.processRotations();
101+
RotationManager.redirectStrafeInputs(input);
102+
}
98103
EventFlow.post(new MovementEvent.InputUpdate(input));
99104
}
100105

@@ -105,12 +110,16 @@ private void injectTickMovement(CallbackInfo ci) {
105110

106111
@ModifyExpressionValue(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
107112
private float modifyGetYaw(float original) {
113+
if (BaritoneHandler.isActive()) return original;
114+
108115
final var yaw = RotationManager.getHeadYaw();
109116
return yaw != null ? yaw : original;
110117
}
111118

112119
@ModifyExpressionValue(method = "sendMovementPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
113120
private float modifyGetPitch(float original) {
121+
if (BaritoneHandler.isActive()) return original;
122+
114123
final var pitch = RotationManager.getHeadPitch();
115124
return pitch != null ? pitch : original;
116125
}
@@ -124,7 +133,7 @@ private void wrapSendPacket(ClientPlayNetworkHandler instance, Packet packet, Op
124133

125134
@Inject(method = "sendMovementPackets", at = @At("TAIL"))
126135
private void injectSendMovementPacketsReturn(CallbackInfo ci) {
127-
RotationManager.onRotationSend();
136+
if (!BaritoneHandler.isActive()) { RotationManager.onRotationSend(); }
128137
EventFlow.post(new PlayerPacketEvent.Post());
129138
}
130139

@@ -143,12 +152,12 @@ boolean injectSneakingInput(boolean original) {
143152

144153
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
145154
float wrapGetYaw(ClientPlayerEntity instance, Operation<Float> original) {
146-
return Objects.requireNonNullElse(RotationManager.getHandYaw(), original.call(instance));
155+
return BaritoneHandler.isActive() ? original.call(instance) : Objects.requireNonNullElse(RotationManager.getHandYaw(), original.call(instance));
147156
}
148157

149158
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
150159
float wrapGetPitch(ClientPlayerEntity instance, Operation<Float> original) {
151-
return Objects.requireNonNullElse(RotationManager.getHandPitch(), original.call(instance));
160+
return BaritoneHandler.isActive() ? original.call(instance) : Objects.requireNonNullElse(RotationManager.getHandPitch(), original.call(instance));
152161
}
153162

154163
@Inject(method = "swingHand", at = @At("HEAD"), cancellable = true)

src/main/java/com/lambda/mixin/entity/EntityMixin.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.lambda.event.EventFlow;
2121
import com.lambda.event.events.EntityEvent;
2222
import com.lambda.event.events.PlayerEvent;
23+
import com.lambda.interaction.BaritoneHandler;
2324
import com.lambda.interaction.managers.rotating.RotationManager;
2425
import com.lambda.module.modules.movement.elytrafly.ElytraFly;
2526
import com.lambda.module.modules.movement.elytrafly.ElytraFly.FlyMode;
@@ -60,6 +61,8 @@ public void move(MovementType movementType, Vec3d movement) {}
6061
*/
6162
@WrapOperation(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
6263
public float velocityYaw(Entity entity, Operation<Float> original) {
64+
if (BaritoneHandler.isActive()) return original.call(entity);
65+
6366
if ((Object) this != getMc().player) return original.call(entity);
6467

6568
Float y = RotationManager.getMovementYaw();
@@ -78,6 +81,8 @@ public float velocityYaw(Entity entity, Operation<Float> original) {
7881
*/
7982
@WrapOperation(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw(F)F"))
8083
float fixDirectionYaw(Entity entity, float tickDelta, Operation<Float> original) {
84+
if (BaritoneHandler.isActive()) return original.call(entity, tickDelta);
85+
8186
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
8287
if (entity != getMc().player || rot == null) return original.call(entity, tickDelta);
8388

@@ -94,6 +99,8 @@ float fixDirectionYaw(Entity entity, float tickDelta, Operation<Float> original)
9499
*/
95100
@WrapOperation(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch(F)F"))
96101
float fixDirectionPitch(Entity entity, float tickDelta, Operation<Float> original) {
102+
if (BaritoneHandler.isActive()) return original.call(entity, tickDelta);
103+
97104
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
98105
if (entity != getMc().player || rot == null) return original.call(entity, tickDelta);
99106

@@ -110,6 +117,8 @@ float fixDirectionPitch(Entity entity, float tickDelta, Operation<Float> origina
110117
*/
111118
@WrapOperation(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
112119
float fixDirectionYaw2(Entity entity, Operation<Float> original) {
120+
if (BaritoneHandler.isActive()) return original.call(entity);
121+
113122
Vec2d rot = RotationManager.getRotationForVector(1.0);
114123
if (entity != getMc().player || rot == null) return original.call(entity);
115124

@@ -126,6 +135,8 @@ float fixDirectionYaw2(Entity entity, Operation<Float> original) {
126135
*/
127136
@WrapOperation(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch()F"))
128137
float fixDirectionPitch2(Entity entity, Operation<Float> original) {
138+
if (BaritoneHandler.isActive()) return original.call(entity);
139+
129140
Vec2d rot = RotationManager.getRotationForVector(1.0);
130141
if (entity != getMc().player || rot == null) return original.call(entity);
131142

@@ -155,12 +166,16 @@ private boolean modifyGetFlagGlowing(boolean original) {
155166

156167
@WrapWithCondition(method = "changeLookDirection", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setYaw(F)V"))
157168
private boolean wrapSetYaw(Entity instance, float yaw) {
169+
if (BaritoneHandler.isActive()) return true;
170+
158171
if ((Object) this != getMc().player) return true;
159172
return RotationManager.getLockYaw() == null;
160173
}
161174

162175
@WrapWithCondition(method = "changeLookDirection", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;setPitch(F)V"))
163176
private boolean wrapSetPitch(Entity instance, float yaw) {
177+
if (BaritoneHandler.isActive()) return true;
178+
164179
if ((Object) this != getMc().player) return true;
165180
return RotationManager.getLockPitch() == null;
166181
}

src/main/java/com/lambda/mixin/entity/LivingEntityMixin.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.lambda.Lambda;
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.MovementEvent;
23+
import com.lambda.interaction.BaritoneHandler;
2324
import com.lambda.interaction.managers.rotating.RotationManager;
2425
import com.lambda.module.modules.movement.Velocity;
2526
import com.lambda.module.modules.movement.elytrafly.ElytraFly;
@@ -65,6 +66,8 @@ void onJump(CallbackInfo ci, @Local LocalFloatRef heightRef) {
6566

6667
@ModifyExpressionValue(method = "jump", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"))
6768
float hookModifyJumpYaw(float original) {
69+
if (BaritoneHandler.isActive()) return original;
70+
6871
if (lambda$instance == Lambda.getMc().player) {
6972
Float yaw = RotationManager.getMovementYaw();
7073
return yaw == null ? original : yaw;
@@ -89,6 +92,8 @@ void onTravelPost(Vec3d movementInput, CallbackInfo ci) {
8992
*/
9093
@WrapOperation(method = "calcGlidingVelocity(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getPitch()F"))
9194
private float hookModifyFallFlyingPitch(LivingEntity entity, Operation<Float> original) {
95+
if (BaritoneHandler.isActive()) return original.call(entity);
96+
9297
Float pitch = RotationManager.getMovementPitch();
9398
if (entity != Lambda.getMc().player || pitch == null) return original.call(entity);
9499

@@ -118,6 +123,8 @@ private float hookModifyFallFlyingPitch(LivingEntity entity, Operation<Float> or
118123
*/
119124
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"), slice = @Slice(to = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F", ordinal = 1)))
120125
private float rotBody(LivingEntity entity, Operation<Float> original) {
126+
if (BaritoneHandler.isActive()) return original.call(entity);
127+
121128
if (lambda$instance != Lambda.getMc().player) {
122129
return original.call(entity);
123130
}
@@ -149,6 +156,8 @@ private float rotBody(LivingEntity entity, Operation<Float> original) {
149156
*/
150157
@WrapOperation(method = "turnHead", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getYaw()F"))
151158
private float rotHead(LivingEntity entity, Operation<Float> original) {
159+
if (BaritoneHandler.isActive()) return original.call(entity);
160+
152161
if (lambda$instance != Lambda.getMc().player) {
153162
return original.call(entity);
154163
}

src/main/java/com/lambda/mixin/entity/PlayerEntityMixin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.lambda.Lambda;
2121
import com.lambda.event.EventFlow;
2222
import com.lambda.event.events.MovementEvent;
23+
import com.lambda.interaction.BaritoneHandler;
2324
import com.lambda.interaction.managers.rotating.RotationManager;
2425
import com.lambda.module.modules.player.Reach;
2526
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
@@ -41,6 +42,8 @@ private void injectSafeWalk(CallbackInfoReturnable<Boolean> cir) {
4142

4243
@WrapOperation(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;getYaw()F"))
4344
private float wrapHeadYaw(PlayerEntity instance, Operation<Float> original) {
45+
if (BaritoneHandler.isActive()) return original.call(instance);
46+
4447
if ((Object) this != Lambda.getMc().player) {
4548
return original.call(instance);
4649
}

src/main/java/com/lambda/mixin/render/CameraMixin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.mixin.render;
1919

20+
import com.lambda.interaction.BaritoneHandler;
2021
import com.lambda.interaction.managers.rotating.RotationManager;
2122
import com.lambda.module.modules.render.CameraTweaks;
2223
import com.lambda.module.modules.render.FreeLook;
@@ -71,6 +72,8 @@ private void onUpdate(World area, Entity focusedEntity, boolean thirdPerson, boo
7172
*/
7273
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setPos(DDD)V", shift = At.Shift.AFTER))
7374
private void injectQuickPerspectiveSwap(World area, Entity focusedEntity, boolean thirdPerson, boolean inverseView, float tickProgress, CallbackInfo ci) {
75+
if (BaritoneHandler.isActive()) return;
76+
7477
var rot = RotationManager.getLockRotation();
7578
if (rot == null) return;
7679
if (FreeLook.INSTANCE.isEnabled()) {

src/main/java/com/lambda/mixin/render/LivingEntityRendererMixin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package com.lambda.mixin.render;
1919

2020
import com.lambda.Lambda;
21+
import com.lambda.interaction.BaritoneHandler;
2122
import com.lambda.interaction.managers.rotating.RotationManager;
2223
import com.lambda.module.modules.render.Nametags;
2324
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
@@ -35,6 +36,8 @@
3536
public class LivingEntityRendererMixin {
3637
@WrapOperation(method = "updateRenderState(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/client/render/entity/state/LivingEntityRenderState;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;getLerpedPitch(F)F"))
3738
private float wrapGetLerpedPitch(LivingEntity livingEntity, float v, Operation<Float> original) {
39+
if (BaritoneHandler.isActive()) return original.call(livingEntity, v);
40+
3841
Float headPitch = RotationManager.getHeadPitch();
3942
if (livingEntity != Lambda.getMc().player || headPitch == null) return original.call(livingEntity, v);
4043

0 commit comments

Comments
 (0)