Skip to content

Commit 67b9a4a

Browse files
authored
Maintainance: Mixin compatibility (#177)
Using mixinextras to improve compat
1 parent 38996e8 commit 67b9a4a

21 files changed

+188
-181
lines changed

src/main/java/com/lambda/mixin/MinecraftClientMixin.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.lambda.module.modules.player.InventoryMove;
3030
import com.lambda.module.modules.player.PacketMine;
3131
import com.lambda.util.WindowUtils;
32+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
33+
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
3234
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
3335
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
3436
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
@@ -49,7 +51,6 @@
4951
import org.spongepowered.asm.mixin.Unique;
5052
import org.spongepowered.asm.mixin.injection.At;
5153
import org.spongepowered.asm.mixin.injection.Inject;
52-
import org.spongepowered.asm.mixin.injection.Redirect;
5354
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
5455

5556
@Mixin(value = MinecraftClient.class, priority = Integer.MAX_VALUE)
@@ -154,10 +155,10 @@ private void onScreenRemove(@Nullable Screen screen, CallbackInfo ci) {
154155
}
155156
}
156157

157-
@Redirect(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;unpressAll()V"))
158-
private void redirectUnPressAll() {
158+
@WrapOperation(method = "setScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;unpressAll()V"))
159+
private void redirectUnPressAll(Operation<Void> original) {
159160
if (!InventoryMove.getShouldMove()) {
160-
KeyBinding.unpressAll();
161+
original.call();
161162
return;
162163
}
163164
KeyBinding.KEYS_BY_ID.values().forEach(bind -> {
@@ -167,20 +168,16 @@ private void redirectUnPressAll() {
167168
});
168169
}
169170

170-
@Redirect(method = "doAttack()Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
171-
private void redirectHandSwing(ClientPlayerEntity instance, Hand hand) {
172-
if (this.crosshairTarget == null) return;
173-
if (this.crosshairTarget.getType() != HitResult.Type.BLOCK || PacketMine.INSTANCE.isDisabled()) {
174-
instance.swingHand(hand);
175-
}
171+
@WrapWithCondition(method = "doAttack()Z", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
172+
private boolean redirectHandSwing(ClientPlayerEntity instance, Hand hand) {
173+
if (this.crosshairTarget == null) return false;
174+
return this.crosshairTarget.getType() != HitResult.Type.BLOCK || PacketMine.INSTANCE.isDisabled();
176175
}
177176

178-
@Redirect(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))
179-
boolean redirectMultiActon(ClientPlayerInteractionManager instance) {
180-
if (instance == null) return true;
181-
177+
@ModifyExpressionValue(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))
178+
boolean redirectMultiActon(boolean original) {
182179
if (Interact.INSTANCE.isEnabled() && Interact.getMultiAction()) return false;
183-
return instance.isBreakingBlock();
180+
return original;
184181
}
185182

186183
@Inject(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isRiding()Z"))

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.lambda.event.events.InventoryEvent;
2222
import com.lambda.event.events.PlayerEvent;
2323
import com.lambda.interaction.managers.inventory.InventoryManager;
24+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
2425
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
2526
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2627
import net.minecraft.client.network.ClientPlayerEntity;
@@ -42,7 +43,6 @@
4243
import org.spongepowered.asm.mixin.Shadow;
4344
import org.spongepowered.asm.mixin.injection.At;
4445
import org.spongepowered.asm.mixin.injection.Inject;
45-
import org.spongepowered.asm.mixin.injection.Redirect;
4646
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
4747
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
4848

@@ -103,9 +103,9 @@ public void clickSlotHead(int syncId, int slotId, int button, SlotActionType act
103103
* }
104104
* }</pre>
105105
*/
106-
@Redirect(method = "syncSelectedSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;getSelectedSlot()I"))
107-
public int overrideSelectedSlotSync(PlayerInventory instance) {
108-
return EventFlow.post(new InventoryEvent.HotbarSlot.Update(instance.getSelectedSlot())).getSlot();
106+
@ModifyExpressionValue(method = "syncSelectedSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;getSelectedSlot()I"))
107+
public int overrideSelectedSlotSync(int original) {
108+
return EventFlow.post(new InventoryEvent.HotbarSlot.Update(original)).getSlot();
109109
}
110110

111111
@Inject(method = "updateBlockBreakingProgress", at = @At("HEAD"), cancellable = true)

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

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import com.lambda.interaction.managers.rotating.RotationManager;
2727
import com.lambda.module.modules.player.PortalGui;
2828
import com.lambda.module.modules.render.ViewModel;
29+
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
2930
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
3031
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
32+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
3133
import com.mojang.authlib.GameProfile;
3234
import net.minecraft.client.MinecraftClient;
3335
import net.minecraft.client.gui.screen.Screen;
@@ -43,7 +45,6 @@
4345
import org.spongepowered.asm.mixin.Shadow;
4446
import org.spongepowered.asm.mixin.injection.At;
4547
import org.spongepowered.asm.mixin.injection.Inject;
46-
import org.spongepowered.asm.mixin.injection.Redirect;
4748
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
4849
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
4950

@@ -59,16 +60,16 @@ public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) {
5960
super(world, profile);
6061
}
6162

62-
@Redirect(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V"))
63-
private void emitMovementEvents(AbstractClientPlayerEntity instance, MovementType movementType, Vec3d movement) {
64-
EventFlow.post(new MovementEvent.Player.Pre(movementType, movement));
65-
super.move(movementType, movement);
66-
EventFlow.post(new MovementEvent.Player.Post(movementType, movement));
63+
@WrapOperation(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V"))
64+
private void emitMovementEvents(ClientPlayerEntity instance, MovementType movementType, Vec3d vec3d, Operation<Void> original) {
65+
EventFlow.post(new MovementEvent.Player.Pre(movementType, vec3d));
66+
original.call(instance, movementType, vec3d);
67+
EventFlow.post(new MovementEvent.Player.Post(movementType, vec3d));
6768
}
6869

69-
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick()V"))
70-
void processMovement(Input input) {
71-
input.tick();
70+
@WrapOperation(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick()V"))
71+
void processMovement(Input input, Operation<Void> original) {
72+
original.call(input);
7273
RotationManager.processRotations();
7374
RotationManager.redirectStrafeInputs(input);
7475
EventFlow.post(new MovementEvent.InputUpdate(input));
@@ -84,14 +85,14 @@ void sendLambdaMovement(CallbackInfo ci) {
8485
autoJumpEnabled = Lambda.getMc().options.getAutoJump().getValue();
8586
}
8687

87-
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;sendSneakingPacket()V"))
88-
void sendSneakingPacket(ClientPlayerEntity entity) {
88+
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;sendSneakingPacket()V"))
89+
void sendSneakingPacket(ClientPlayerEntity entity, Operation<Void> original) {
8990
PlayerPacketHandler.sendSneakPackets();
9091
}
9192

92-
@Redirect(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z"))
93-
boolean isSprinting(ClientPlayerEntity entity) {
94-
return EventFlow.post(new MovementEvent.Sprint(entity.isSprinting())).getSprint();
93+
@ModifyExpressionValue(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z"))
94+
boolean isSprinting(boolean original) {
95+
return EventFlow.post(new MovementEvent.Sprint(original)).getSprint();
9596
}
9697

9798
@Inject(method = "isSneaking", at = @At(value = "HEAD"), cancellable = true)
@@ -110,27 +111,27 @@ void onTick(Operation<Void> original) {
110111
EventFlow.post(TickEvent.Player.Post.INSTANCE);
111112
}
112113

113-
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
114-
float fixHeldItemYaw(ClientPlayerEntity instance) {
115-
return Objects.requireNonNullElse(RotationManager.getHandYaw(), instance.getYaw());
114+
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
115+
float fixHeldItemYaw(ClientPlayerEntity instance, Operation<Float> original) {
116+
return Objects.requireNonNullElse(RotationManager.getHandYaw(), original.call(instance));
116117
}
117118

118-
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
119-
float fixHeldItemPitch(ClientPlayerEntity instance) {
120-
return Objects.requireNonNullElse(RotationManager.getHandPitch(), instance.getPitch());
119+
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
120+
float fixHeldItemPitch(ClientPlayerEntity instance, Operation<Float> original) {
121+
return Objects.requireNonNullElse(RotationManager.getHandPitch(), original.call(instance));
121122
}
122123

123124
@Inject(method = "swingHand", at = @At("HEAD"), cancellable = true)
124125
void onSwing(Hand hand, CallbackInfo ci) {
125126
if (EventFlow.post(new PlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel();
126127
}
127128

128-
@Redirect(method = "swingHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
129-
private void adjustSwing(AbstractClientPlayerEntity instance, Hand hand) {
129+
@WrapOperation(method = "swingHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
130+
private void adjustSwing(ClientPlayerEntity instance, Hand hand, Operation<Void> original) {
130131
ViewModel viewModel = ViewModel.INSTANCE;
131132

132133
if (!viewModel.isEnabled()) {
133-
instance.swingHand(hand, false);
134+
original.call(instance, hand);
134135
return;
135136
}
136137

@@ -157,9 +158,9 @@ public void damage(float health, CallbackInfo ci) {
157158
* }
158159
* }</pre>
159160
*/
160-
@Redirect(method = "tickNausea", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;"))
161-
Screen keepScreensInPortal(MinecraftClient instance) {
161+
@ModifyExpressionValue(method = "tickNausea", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;"))
162+
Screen keepScreensInPortal(Screen original) {
162163
if (PortalGui.INSTANCE.isEnabled()) return null;
163-
else return client.currentScreen;
164+
else return original;
164165
}
165166
}

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.lambda.util.math.Vec2d;
2929
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
3030
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
31+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
32+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
3133
import net.minecraft.entity.Entity;
3234
import net.minecraft.entity.MovementType;
3335
import net.minecraft.entity.data.TrackedData;
@@ -36,7 +38,6 @@
3638
import org.spongepowered.asm.mixin.Shadow;
3739
import org.spongepowered.asm.mixin.injection.At;
3840
import org.spongepowered.asm.mixin.injection.Inject;
39-
import org.spongepowered.asm.mixin.injection.Redirect;
4041
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
4142

4243
@Mixin(Entity.class)
@@ -51,12 +52,12 @@ public void move(MovementType movementType, Vec3d movement) {
5152
/**
5253
* Modifies the player yaw when there is an active rotation to apply the player velocity correctly
5354
*/
54-
@Redirect(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
55-
public float velocityYaw(Entity entity) {
56-
if ((Object) this != Lambda.getMc().player) return getYaw();
55+
@WrapOperation(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
56+
public float velocityYaw(Entity entity, Operation<Float> original) {
57+
if ((Object) this != Lambda.getMc().player) return original.call(entity);
5758

5859
Float y = RotationManager.getMovementYaw();
59-
if (y == null) return getYaw();
60+
if (y == null) return original.call(entity);
6061

6162
return y;
6263
}
@@ -69,10 +70,10 @@ public float velocityYaw(Entity entity) {
6970
* }
7071
* }</pre>
7172
*/
72-
@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw(F)F"))
73-
float fixDirectionYaw(Entity entity, float tickDelta) {
73+
@WrapOperation(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw(F)F"))
74+
float fixDirectionYaw(Entity entity, float tickDelta, Operation<Float> original) {
7475
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
75-
if (entity != Lambda.getMc().player || rot == null) return entity.getYaw(tickDelta);
76+
if (entity != Lambda.getMc().player || rot == null) return original.call(entity, tickDelta);
7677

7778
return (float) rot.getX();
7879
}
@@ -85,10 +86,10 @@ float fixDirectionYaw(Entity entity, float tickDelta) {
8586
* }
8687
* }</pre>
8788
*/
88-
@Redirect(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch(F)F"))
89-
float fixDirectionPitch(Entity entity, float tickDelta) {
89+
@WrapOperation(method = "getRotationVec", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch(F)F"))
90+
float fixDirectionPitch(Entity entity, float tickDelta, Operation<Float> original) {
9091
Vec2d rot = RotationManager.getRotationForVector(tickDelta);
91-
if (entity != Lambda.getMc().player || rot == null) return entity.getPitch(tickDelta);
92+
if (entity != Lambda.getMc().player || rot == null) return original.call(entity, tickDelta);
9293

9394
return (float) rot.getY();
9495
}
@@ -101,10 +102,10 @@ float fixDirectionPitch(Entity entity, float tickDelta) {
101102
* }
102103
* }</pre>
103104
*/
104-
@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
105-
float fixDirectionYaw2(Entity entity) {
105+
@WrapOperation(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getYaw()F"))
106+
float fixDirectionYaw2(Entity entity, Operation<Float> original) {
106107
Vec2d rot = RotationManager.getRotationForVector(1.0);
107-
if (entity != Lambda.getMc().player || rot == null) return entity.getYaw();
108+
if (entity != Lambda.getMc().player || rot == null) return original.call(entity);
108109

109110
return (float) rot.getX();
110111
}
@@ -117,10 +118,10 @@ float fixDirectionYaw2(Entity entity) {
117118
* }
118119
* }</pre>
119120
*/
120-
@Redirect(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch()F"))
121-
float fixDirectionPitch2(Entity entity) {
121+
@WrapOperation(method = "getRotationVector()Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getPitch()F"))
122+
float fixDirectionPitch2(Entity entity, Operation<Float> original) {
122123
Vec2d rot = RotationManager.getRotationForVector(1.0);
123-
if (entity != Lambda.getMc().player || rot == null) return entity.getPitch();
124+
if (entity != Lambda.getMc().player || rot == null) return original.call(entity);
124125

125126
return (float) rot.getY();
126127
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818
package com.lambda.mixin.entity;
1919

2020
import com.lambda.module.modules.movement.ElytraFly;
21+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
22+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
2123
import net.minecraft.entity.LivingEntity;
2224
import net.minecraft.entity.projectile.FireworkRocketEntity;
2325
import net.minecraft.util.math.Vec3d;
2426
import org.spongepowered.asm.mixin.Mixin;
2527
import org.spongepowered.asm.mixin.injection.At;
26-
import org.spongepowered.asm.mixin.injection.Redirect;
2728

2829
@Mixin(FireworkRocketEntity.class)
2930
public class FireworkRocketEntityMixin {
30-
@Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"))
31-
private void redirectSetVelocity(LivingEntity shooter, Vec3d vec3d) {
31+
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V"))
32+
private void wrapSetVelocity(LivingEntity shooter, Vec3d vec3d, Operation<Void> original) {
3233
if (ElytraFly.getDoBoost()) {
3334
ElytraFly.boostRocket();
34-
} else shooter.setVelocity(vec3d);
35+
} else original.call(shooter, vec3d);
3536
}
3637
}

0 commit comments

Comments
 (0)