2121import com .lambda .event .EventFlow ;
2222import com .lambda .event .events .MovementEvent ;
2323import com .lambda .event .events .PlayerEvent ;
24+ import com .lambda .event .events .PlayerPacketEvent ;
2425import com .lambda .event .events .TickEvent ;
25- import com .lambda .interaction .PlayerPacketHandler ;
2626import com .lambda .interaction .managers .rotating .RotationManager ;
2727import com .lambda .module .modules .movement .ElytraFly ;
2828import com .lambda .module .modules .movement .NoJumpCooldown ;
3737import net .minecraft .client .gui .screen .Screen ;
3838import net .minecraft .client .input .Input ;
3939import net .minecraft .client .network .AbstractClientPlayerEntity ;
40- import net .minecraft .client .network .ClientPlayNetworkHandler ;
4140import net .minecraft .client .network .ClientPlayerEntity ;
4241import net .minecraft .client .world .ClientWorld ;
4342import net .minecraft .entity .MovementType ;
44- import net .minecraft .network .packet .Packet ;
43+ import net .minecraft .network .packet .c2s . play . PlayerMoveC2SPacket ;
4544import net .minecraft .util .Hand ;
4645import net .minecraft .util .math .Vec3d ;
47- import org .objectweb .asm .Opcodes ;
4846import org .spongepowered .asm .mixin .Final ;
4947import org .spongepowered .asm .mixin .Mixin ;
5048import org .spongepowered .asm .mixin .Shadow ;
49+ import org .spongepowered .asm .mixin .Unique ;
5150import org .spongepowered .asm .mixin .injection .At ;
5251import org .spongepowered .asm .mixin .injection .Inject ;
5352import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
5756
5857@ Mixin (value = ClientPlayerEntity .class , priority = Integer .MAX_VALUE )
5958public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity {
60- @ Shadow public Input input ;
61- @ Shadow @ Final protected MinecraftClient client ;
59+ @ Shadow
60+ public Input input ;
61+ @ Shadow
62+ @ Final
63+ protected MinecraftClient client ;
64+ @ Unique
65+ private PlayerPacketEvent .Pre moveEvent ;
6266
6367 public ClientPlayerEntityMixin (ClientWorld world , GameProfile profile ) {
6468 super (world , profile );
@@ -84,36 +88,35 @@ private void injectTickMovement(CallbackInfo ci) {
8488 if (NoJumpCooldown .INSTANCE .isEnabled () || (ElytraFly .INSTANCE .isEnabled () && ElytraFly .getMode () == ElytraFly .FlyMode .Bounce )) jumpingCooldown = 0 ;
8589 }
8690
87- @ ModifyExpressionValue (method = "sendMovementPackets" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F" ))
88- private float modifyGetYaw (float original ) {
89- final var rot = RotationManager .getHeadYaw ();
90- return rot != null ? rot : original ;
91+ @ Inject (method = "sendMovementPackets" , at = @ At ("HEAD" ))
92+ private void MovementEventPre (CallbackInfo ci ) {
93+ moveEvent = EventFlow .post (new PlayerPacketEvent .Pre (pos , RotationManager .getActiveRotation (), isOnGround (), isSprinting (), horizontalCollision ));
9194 }
9295
93- @ ModifyExpressionValue (method = "sendMovementPackets" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F" ))
94- private float modifyGetPitch (float original ) {
95- final var rot = RotationManager .getHeadPitch ();
96- return rot != null ? rot : original ;
96+ @ 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 ) {
98+ return original .call (moveEvent .getPosition (), moveEvent .getRotation ().getYawF (), moveEvent .getRotation ().getPitchF (), moveEvent .getOnGround (), moveEvent .isCollidingHorizontally ());
9799 }
98100
99- @ ModifyExpressionValue (method = "sendMovementPackets" , at = @ At (value = "FIELD " , target = "Lnet /minecraft/client/ network/ClientPlayerEntity;lastYawClient:F" , opcode = Opcodes . GETFIELD ))
100- private float modifyLastYawClient ( float original ) {
101- return RotationManager . getServerRotation (). getYawF ( );
101+ @ 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 ) {
103+ return original . call ( moveEvent . getPosition (), moveEvent . getOnGround (), moveEvent . isCollidingHorizontally () );
102104 }
103105
104- @ ModifyExpressionValue (method = "sendMovementPackets" , at = @ At (value = "FIELD " , target = "Lnet /minecraft/client/ network/ClientPlayerEntity;lastPitchClient:F" , opcode = Opcodes . GETFIELD ))
105- private float modifyLastPitchClient (float original ) {
106- return RotationManager . getServerRotation (). getPitchF ();
106+ @ 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 ) {
108+ return original . call ( moveEvent . getRotation (). getYawF (), moveEvent . getRotation (). getPitchF (), moveEvent . getOnGround (), moveEvent . isCollidingHorizontally () );
107109 }
108110
109- @ WrapOperation (method = "sendMovementPackets" , at = @ At (value = "INVOKE " , target = "Lnet /minecraft/client/ network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V " ))
110- private void wrapSendPacket ( ClientPlayNetworkHandler instance , Packet packet , Operation <Void > original ) {
111- PlayerPacketHandler . sendPlayerPackets ( packet );
111+ @ 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 ) {
113+ return original . call ( moveEvent . getOnGround (), moveEvent . isCollidingHorizontally () );
112114 }
113115
114116 @ Inject (method = "sendMovementPackets" , at = @ At ("TAIL" ))
115117 private void injectSendMovementPackets (CallbackInfo ci ) {
116118 RotationManager .onRotationSend ();
119+ EventFlow .post (new PlayerPacketEvent .Post ());
117120 }
118121
119122 @ ModifyExpressionValue (method = "tickMovement" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z" ))
@@ -171,6 +174,7 @@ public void damage(float health, CallbackInfo ci) {
171174
172175 /**
173176 * Prevents the game from closing Guis when the player is in a nether portal
177+ *
174178 * <pre>{@code
175179 * if (this.client.currentScreen != null
176180 * && !this.client.currentScreen.shouldPause()
0 commit comments