Skip to content

Commit ebad580

Browse files
committed
send rotation update if the active rotation doesnt equal the server rotation
1 parent 2e2157b commit ebad580

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@
2828
import com.lambda.module.modules.movement.NoJumpCooldown;
2929
import com.lambda.module.modules.player.PortalGui;
3030
import com.lambda.module.modules.render.ViewModel;
31+
import com.llamalad7.mixinextras.expression.Definition;
32+
import com.llamalad7.mixinextras.expression.Expression;
3133
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
3234
import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
3335
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
3436
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
37+
import com.llamalad7.mixinextras.sugar.Local;
3538
import com.mojang.authlib.GameProfile;
3639
import net.minecraft.client.MinecraftClient;
3740
import net.minecraft.client.gui.screen.Screen;
@@ -69,14 +72,14 @@ public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) {
6972
}
7073

7174
@WrapOperation(method = "move", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V"))
72-
private void emitMovementEvents(ClientPlayerEntity instance, MovementType movementType, Vec3d vec3d, Operation<Void> original) {
75+
private void wrapMove(ClientPlayerEntity instance, MovementType movementType, Vec3d vec3d, Operation<Void> original) {
7376
EventFlow.post(new MovementEvent.Player.Pre(movementType, vec3d));
7477
original.call(instance, movementType, vec3d);
7578
EventFlow.post(new MovementEvent.Player.Post(movementType, vec3d));
7679
}
7780

7881
@WrapOperation(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/input/Input;tick()V"))
79-
void processMovement(Input input, Operation<Void> original) {
82+
void wrapTick(Input input, Operation<Void> original) {
8083
original.call(input);
8184
RotationManager.processRotations();
8285
RotationManager.redirectStrafeInputs(input);
@@ -89,38 +92,45 @@ private void injectTickMovement(CallbackInfo ci) {
8992
}
9093

9194
@Inject(method = "sendMovementPackets", at = @At("HEAD"))
92-
private void MovementEventPre(CallbackInfo ci) {
95+
private void injectSendMovementPacketsHead(CallbackInfo ci) {
9396
moveEvent = EventFlow.post(new PlayerPacketEvent.Pre(pos, RotationManager.getActiveRotation(), isOnGround(), isSprinting(), horizontalCollision));
9497
}
9598

99+
@Definition(id = "g", local = @Local(type = double.class, ordinal = 3))
100+
@Expression("g != 0.0")
101+
@ModifyExpressionValue(method = "sendMovementPackets", at = @At("MIXINEXTRAS:EXPRESSION"))
102+
private boolean modifyHasRotated(boolean original) {
103+
return RotationManager.getActiveRotation() != RotationManager.getServerRotation() || original;
104+
}
105+
96106
@WrapOperation(method = "sendMovementPackets", at = @At(value = "NEW", target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$Full"))
97-
private PlayerMoveC2SPacket.Full onFullPacket(Vec3d pos, float yaw, float pitch, boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.Full> original) {
107+
private PlayerMoveC2SPacket.Full wrapFullPacket(Vec3d pos, float yaw, float pitch, boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.Full> original) {
98108
return original.call(moveEvent.getPosition(), moveEvent.getRotation().getYawF(), moveEvent.getRotation().getPitchF(), moveEvent.getOnGround(), moveEvent.isCollidingHorizontally());
99109
}
100110

101111
@WrapOperation(method = "sendMovementPackets", at = @At(value = "NEW", target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$PositionAndOnGround"))
102-
private PlayerMoveC2SPacket.PositionAndOnGround onPositionPacket(Vec3d pos, boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.PositionAndOnGround> original) {
112+
private PlayerMoveC2SPacket.PositionAndOnGround wrapPositionAndOnGround(Vec3d pos, boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.PositionAndOnGround> original) {
103113
return original.call(moveEvent.getPosition(), moveEvent.getOnGround(), moveEvent.isCollidingHorizontally());
104114
}
105115

106116
@WrapOperation(method = "sendMovementPackets", at = @At(value = "NEW", target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$LookAndOnGround"))
107-
private PlayerMoveC2SPacket.LookAndOnGround onLookPacket(float yaw, float pitch, boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.LookAndOnGround> original) {
117+
private PlayerMoveC2SPacket.LookAndOnGround wrapLookAndOnGround(float yaw, float pitch, boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.LookAndOnGround> original) {
108118
return original.call(moveEvent.getRotation().getYawF(), moveEvent.getRotation().getPitchF(), moveEvent.getOnGround(), moveEvent.isCollidingHorizontally());
109119
}
110120

111121
@WrapOperation(method = "sendMovementPackets", at = @At(value = "NEW", target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$OnGroundOnly"))
112-
private PlayerMoveC2SPacket.OnGroundOnly onOnGroundPacket(boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.OnGroundOnly> original) {
122+
private PlayerMoveC2SPacket.OnGroundOnly wrapOnGroundOnly(boolean onGround, boolean horizontalCollision, Operation<PlayerMoveC2SPacket.OnGroundOnly> original) {
113123
return original.call(moveEvent.getOnGround(), moveEvent.isCollidingHorizontally());
114124
}
115125

116-
@Inject(method = "sendMovementPackets", at = @At("TAIL"))
117-
private void injectSendMovementPackets(CallbackInfo ci) {
126+
@Inject(method = "sendMovementPackets", at = @At("RETURN"))
127+
private void injectSendMovementPacketsReturn(CallbackInfo ci) {
118128
RotationManager.onRotationSend();
119129
EventFlow.post(new PlayerPacketEvent.Post());
120130
}
121131

122132
@ModifyExpressionValue(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z"))
123-
boolean isSprinting(boolean original) {
133+
boolean modifyIsSprinting(boolean original) {
124134
return EventFlow.post(new MovementEvent.Sprint(original)).getSprint();
125135
}
126136

@@ -141,22 +151,22 @@ void onTick(Operation<Void> original) {
141151
}
142152

143153
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F"))
144-
float fixHeldItemYaw(ClientPlayerEntity instance, Operation<Float> original) {
154+
float wrapGetYaw(ClientPlayerEntity instance, Operation<Float> original) {
145155
return Objects.requireNonNullElse(RotationManager.getHandYaw(), original.call(instance));
146156
}
147157

148158
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F"))
149-
float fixHeldItemPitch(ClientPlayerEntity instance, Operation<Float> original) {
159+
float wrapGetPitch(ClientPlayerEntity instance, Operation<Float> original) {
150160
return Objects.requireNonNullElse(RotationManager.getHandPitch(), original.call(instance));
151161
}
152162

153163
@Inject(method = "swingHand", at = @At("HEAD"), cancellable = true)
154-
void onSwing(Hand hand, CallbackInfo ci) {
164+
void injectSwingHand(Hand hand, CallbackInfo ci) {
155165
if (EventFlow.post(new PlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel();
156166
}
157167

158168
@WrapOperation(method = "swingHand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;swingHand(Lnet/minecraft/util/Hand;)V"))
159-
private void adjustSwing(ClientPlayerEntity instance, Hand hand, Operation<Void> original) {
169+
private void wrapSwingHand(ClientPlayerEntity instance, Hand hand, Operation<Void> original) {
160170
ViewModel viewModel = ViewModel.INSTANCE;
161171

162172
if (!viewModel.isEnabled()) {
@@ -168,7 +178,7 @@ private void adjustSwing(ClientPlayerEntity instance, Hand hand, Operation<Void>
168178
}
169179

170180
@Inject(method = "updateHealth", at = @At("HEAD"))
171-
public void damage(float health, CallbackInfo ci) {
181+
public void injectUpdateHealth(float health, CallbackInfo ci) {
172182
EventFlow.post(new PlayerEvent.Health(health));
173183
}
174184

@@ -189,7 +199,7 @@ public void damage(float health, CallbackInfo ci) {
189199
* }</pre>
190200
*/
191201
@ModifyExpressionValue(method = "tickNausea", at = @At(value = "FIELD", target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;"))
192-
Screen keepScreensInPortal(Screen original) {
202+
Screen modifyCurrentScreen(Screen original) {
193203
if (PortalGui.INSTANCE.isEnabled()) return null;
194204
else return original;
195205
}

0 commit comments

Comments
 (0)