1717
1818package com .lambda .mixin .entity ;
1919
20- import com .lambda .Lambda ;
2120import com .lambda .event .EventFlow ;
2221import com .lambda .event .events .MovementEvent ;
2322import com .lambda .event .events .PlayerEvent ;
2423import com .lambda .event .events .PlayerPacketEvent ;
2524import com .lambda .event .events .TickEvent ;
26- import com .lambda .interaction .managers .rotating .Rotation ;
2725import com .lambda .interaction .managers .rotating .RotationManager ;
2826import com .lambda .module .modules .movement .ElytraFly ;
2927import com .lambda .module .modules .movement .NoJumpCooldown ;
3028import com .lambda .module .modules .player .PortalGui ;
3129import com .lambda .module .modules .render .ViewModel ;
32- import com .llamalad7 .mixinextras .expression .Definition ;
33- import com .llamalad7 .mixinextras .expression .Expression ;
3430import com .llamalad7 .mixinextras .injector .ModifyExpressionValue ;
3531import com .llamalad7 .mixinextras .injector .ModifyReturnValue ;
3632import com .llamalad7 .mixinextras .injector .wrapmethod .WrapMethod ;
3733import com .llamalad7 .mixinextras .injector .wrapoperation .Operation ;
3834import com .llamalad7 .mixinextras .injector .wrapoperation .WrapOperation ;
39- import com .llamalad7 .mixinextras .sugar .Local ;
35+ import com .llamalad7 .mixinextras .sugar .Share ;
36+ import com .llamalad7 .mixinextras .sugar .ref .LocalRef ;
4037import com .mojang .authlib .GameProfile ;
4138import net .minecraft .client .gui .screen .Screen ;
4239import net .minecraft .client .input .Input ;
4340import net .minecraft .client .network .AbstractClientPlayerEntity ;
41+ import net .minecraft .client .network .ClientPlayNetworkHandler ;
4442import net .minecraft .client .network .ClientPlayerEntity ;
4543import net .minecraft .client .world .ClientWorld ;
4644import net .minecraft .entity .MovementType ;
45+ import net .minecraft .network .packet .Packet ;
4746import net .minecraft .network .packet .c2s .play .PlayerMoveC2SPacket ;
4847import net .minecraft .util .Hand ;
48+ import net .minecraft .util .math .Vec2f ;
4949import net .minecraft .util .math .Vec3d ;
5050import org .objectweb .asm .Opcodes ;
5151import org .spongepowered .asm .mixin .Mixin ;
52- import org .spongepowered .asm .mixin .Shadow ;
53- import org .spongepowered .asm .mixin .Unique ;
5452import org .spongepowered .asm .mixin .injection .At ;
5553import org .spongepowered .asm .mixin .injection .Inject ;
5654import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
57- import org .spongepowered .asm .mixin .injection .callback .LocalCapture ;
5855
5956import java .util .Objects ;
6057
58+ import static com .lambda .Lambda .getMc ;
59+
6160@ Mixin (value = ClientPlayerEntity .class , priority = Integer .MAX_VALUE )
6261public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity {
63- @ Shadow
64- private float lastYawClient ;
65- @ Shadow
66- private float lastPitchClient ;
67- @ Unique
68- private PlayerPacketEvent .Pre moveEvent ;
69-
7062 public ClientPlayerEntityMixin (ClientWorld world , GameProfile profile ) {
7163 super (world , profile );
7264 }
7365
66+ @ WrapMethod (method = "tick" )
67+ void onTick (Operation <Void > original ) {
68+ EventFlow .post (TickEvent .Player .Pre .INSTANCE );
69+ original .call ();
70+ EventFlow .post (TickEvent .Player .Post .INSTANCE );
71+ }
72+
73+ @ Inject (method = "tick" , at = @ At ("HEAD" ))
74+ private void injectTick (CallbackInfo ci , @ Share (namespace = "shared_rotations" , value = "target_rotation" ) final LocalRef <Vec2f > targetRotation ) {
75+ if (RotationManager .getRequests ().stream ().anyMatch (Objects ::nonNull )) {
76+ final var activeRotation = RotationManager .getActiveRotation ();
77+ targetRotation .set (new Vec2f (activeRotation .getYawF (), activeRotation .getPitchF ()));
78+ }
79+ }
80+
7481 @ WrapOperation (method = "move" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/AbstractClientPlayerEntity;move(Lnet/minecraft/entity/MovementType;Lnet/minecraft/util/math/Vec3d;)V" ))
7582 private void wrapMove (ClientPlayerEntity instance , MovementType movementType , Vec3d vec3d , Operation <Void > original ) {
7683 EventFlow .post (new MovementEvent .Player .Pre (movementType , vec3d ));
@@ -91,43 +98,23 @@ private void injectTickMovement(CallbackInfo ci) {
9198 if (NoJumpCooldown .INSTANCE .isEnabled () || (ElytraFly .INSTANCE .isEnabled () && ElytraFly .getMode () == ElytraFly .FlyMode .Bounce )) jumpingCooldown = 0 ;
9299 }
93100
94- @ Inject (method = "sendMovementPackets" , at = @ At ("HEAD" ))
95- private void injectSendMovementPacketsHead (CallbackInfo ci ) {
96- moveEvent = EventFlow .post (new PlayerPacketEvent .Pre (pos , RotationManager .getActiveRotation (), isOnGround (), isSprinting (), horizontalCollision ));
97- }
98-
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 ().equalFloat (RotationManager .getServerRotation ()) || original ;
101+ @ ModifyExpressionValue (method = "sendMovementPackets" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F" ))
102+ private float modifyGetYaw (float original ) {
103+ final var yaw = RotationManager .getHeadYaw ();
104+ return yaw != null ? yaw : original ;
104105 }
105106
106- @ Inject (method = "sendMovementPackets" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V" , shift = At .Shift .BEFORE ), locals = LocalCapture .CAPTURE_FAILEXCEPTION )
107- private void injectSendPacket (CallbackInfo ci , double d , double e , double f , double g , double h , boolean bl , boolean bl2 ) {
108- if (RotationManager .getRequests ().stream ().allMatch (Objects ::isNull )) {
109- moveEvent .setRotation (new Rotation (g + lastYawClient , h + lastPitchClient ));
110- }
111- }
112-
113- @ WrapOperation (method = "sendMovementPackets" , at = @ At (value = "NEW" , target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$Full" ))
114- private PlayerMoveC2SPacket .Full wrapFullPacket (Vec3d pos , float yaw , float pitch , boolean onGround , boolean horizontalCollision , Operation <PlayerMoveC2SPacket .Full > original ) {
115- return original .call (moveEvent .getPosition (), moveEvent .getRotation ().getYawF (), moveEvent .getRotation ().getPitchF (), moveEvent .getOnGround (), moveEvent .isCollidingHorizontally ());
116- }
117-
118- @ WrapOperation (method = "sendMovementPackets" , at = @ At (value = "NEW" , target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$PositionAndOnGround" ))
119- private PlayerMoveC2SPacket .PositionAndOnGround wrapPositionAndOnGround (Vec3d pos , boolean onGround , boolean horizontalCollision , Operation <PlayerMoveC2SPacket .PositionAndOnGround > original ) {
120- return original .call (moveEvent .getPosition (), moveEvent .getOnGround (), moveEvent .isCollidingHorizontally ());
121- }
122-
123- @ WrapOperation (method = "sendMovementPackets" , at = @ At (value = "NEW" , target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$LookAndOnGround" ))
124- private PlayerMoveC2SPacket .LookAndOnGround wrapLookAndOnGround (float yaw , float pitch , boolean onGround , boolean horizontalCollision , Operation <PlayerMoveC2SPacket .LookAndOnGround > original ) {
125- return original .call (moveEvent .getRotation ().getYawF (), moveEvent .getRotation ().getPitchF (), moveEvent .getOnGround (), moveEvent .isCollidingHorizontally ());
107+ @ ModifyExpressionValue (method = "sendMovementPackets" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F" ))
108+ private float modifyGetPitch (float original ) {
109+ final var pitch = RotationManager .getHeadPitch ();
110+ return pitch != null ? pitch : original ;
126111 }
127112
128- @ WrapOperation (method = "sendMovementPackets" , at = @ At (value = "NEW" , target = "net/minecraft/network/packet/c2s/play/PlayerMoveC2SPacket$OnGroundOnly" ))
129- private PlayerMoveC2SPacket .OnGroundOnly wrapOnGroundOnly (boolean onGround , boolean horizontalCollision , Operation <PlayerMoveC2SPacket .OnGroundOnly > original ) {
130- return original .call (moveEvent .getOnGround (), moveEvent .isCollidingHorizontally ());
113+ @ WrapOperation (method = "sendMovementPackets" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V" ))
114+ private void wrapSendPacket (ClientPlayNetworkHandler instance , Packet packet , Operation <Void > original ) {
115+ var event = EventFlow .post (new PlayerPacketEvent .Send ((PlayerMoveC2SPacket ) packet ));
116+ if (event .isCanceled ()) return ;
117+ original .call (instance , event .getPacket ());
131118 }
132119
133120 @ Inject (method = "sendMovementPackets" , at = @ At ("TAIL" ))
@@ -144,19 +131,11 @@ boolean modifyIsSprinting(boolean original) {
144131 @ ModifyReturnValue (method = "isSneaking" , at = @ At ("RETURN" ))
145132 boolean injectSneakingInput (boolean original ) {
146133 ClientPlayerEntity self = (ClientPlayerEntity ) (Object ) this ;
147- if (self != Lambda .getMc ().player ||
148- self .input == null ) return original ;
134+ if (self != getMc ().player || self .input == null ) return original ;
149135
150136 return EventFlow .post (new MovementEvent .Sneak (self .input .playerInput .sneak ())).getSneak ();
151137 }
152138
153- @ WrapMethod (method = "tick" )
154- void onTick (Operation <Void > original ) {
155- EventFlow .post (TickEvent .Player .Pre .INSTANCE );
156- original .call ();
157- EventFlow .post (TickEvent .Player .Post .INSTANCE );
158- }
159-
160139 @ WrapOperation (method = "tick" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F" ))
161140 float wrapGetYaw (ClientPlayerEntity instance , Operation <Float > original ) {
162141 return Objects .requireNonNullElse (RotationManager .getHandYaw (), original .call (instance ));
0 commit comments