2121import com .lambda .event .EventFlow ;
2222import com .lambda .event .events .ChatEvent ;
2323import com .lambda .event .events .InventoryEvent ;
24+ import com .lambda .event .events .PlayerEvent ;
2425import com .lambda .event .events .WorldEvent ;
2526import com .lambda .interaction .managers .inventory .InventoryManager ;
27+ import com .lambda .interaction .managers .rotating .RotationManager ;
2628import com .lambda .module .modules .movement .Velocity ;
27- import com .lambda .module .modules .player .NoForceRotate ;
2829import com .lambda .module .modules .render .NoRender ;
2930import com .llamalad7 .mixinextras .injector .ModifyExpressionValue ;
3031import com .llamalad7 .mixinextras .injector .wrapmethod .WrapMethod ;
3334import net .minecraft .client .network .ClientPlayNetworkHandler ;
3435import net .minecraft .client .network .PlayerListEntry ;
3536import net .minecraft .entity .Entity ;
37+ import net .minecraft .entity .EntityPosition ;
3638import net .minecraft .network .packet .s2c .play .*;
39+ import org .jetbrains .annotations .Nullable ;
40+ import org .objectweb .asm .Opcodes ;
3741import org .spongepowered .asm .mixin .Mixin ;
42+ import org .spongepowered .asm .mixin .Unique ;
3843import org .spongepowered .asm .mixin .injection .At ;
3944import org .spongepowered .asm .mixin .injection .Inject ;
4045import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
46+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
47+
48+ import java .util .Set ;
4149
4250@ Mixin (ClientPlayNetworkHandler .class )
4351public class ClientPlayNetworkHandlerMixin {
52+ @ Unique
53+ @ Nullable
54+ private static PlayerEvent .ServerForceRotate forceRotateEvent = null ;
55+
4456 @ Inject (method = "onGameJoin(Lnet/minecraft/network/packet/s2c/play/GameJoinS2CPacket;)V" , at = @ At ("TAIL" ))
4557 void injectJoinPacket (GameJoinS2CPacket packet , CallbackInfo ci ) {
4658 EventFlow .post (new WorldEvent .Join ());
@@ -79,7 +91,7 @@ private void onScreenHandlerSlotUpdate(ScreenHandlerSlotUpdateS2CPacket packet,
7991 * }
8092 * }</pre>
8193 */
82- @ ModifyExpressionValue (method = "onGameJoin(Lnet/minecraft/network/packet/s2c/play/GameJoinS2CPacket;)V" , at = @ At (value = "FIELD" , target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;seenInsecureChatWarning:Z" , ordinal = 0 ))
94+ @ ModifyExpressionValue (method = "onGameJoin(Lnet/minecraft/network/packet/s2c/play/GameJoinS2CPacket;)V" , at = @ At (value = "FIELD" , target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;seenInsecureChatWarning:Z" , ordinal = 0 , opcode = Opcodes . GETFIELD ))
8395 public boolean onServerMetadata (boolean original ) {
8496 return (NoRender .getNoChatVerificationToast () && NoRender .INSTANCE .isEnabled ()) || original ;
8597 }
@@ -137,25 +149,30 @@ void onOverlayMessage(OverlayMessageS2CPacket packet, CallbackInfo ci) {
137149 }
138150 }
139151
140- @ ModifyExpressionValue (method = "setPosition(Lnet/minecraft/entity/EntityPosition;Ljava/util/Set;Lnet/minecraft/entity/Entity;Z)Z" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/entity/EntityPosition;yaw()F" ))
152+ @ Inject (method = "setPosition" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/entity/EntityPosition;apply(Lnet/minecraft/entity/EntityPosition;Lnet/minecraft/entity/EntityPosition;Ljava/util/Set;)Lnet/minecraft/entity/EntityPosition;" , ordinal = 0 , shift = At .Shift .AFTER ))
153+ private static void injectAfterRotationApply (EntityPosition pos , Set <PositionFlag > flags , Entity entity , boolean bl , CallbackInfoReturnable <Boolean > cir ) {
154+ var player = Lambda .getMc ().player ;
155+ if (entity != player ) return ;
156+ forceRotateEvent = EventFlow .post (new PlayerEvent .ServerForceRotate (pos .yaw (), pos .pitch ()));
157+ }
158+
159+ @ ModifyExpressionValue (method = "setPosition" , at = {@ At (value = "INVOKE" , target = "Lnet/minecraft/entity/EntityPosition;yaw()F" , ordinal = 0 ), @ At (value = "INVOKE" , target = "Lnet/minecraft/entity/EntityPosition;yaw()F" , ordinal = 1 )})
141160 private static float wrapSetYaw (float original , @ Local (argsOnly = true ) Entity entity ) {
142161 var player = Lambda .getMc ().player ;
143162 if (entity != player ) return original ;
144163 if (player == null ) return original ;
145- if (NoForceRotate .INSTANCE .isEnabled ()) {
146- return player .getYaw ();
147- }
148- return original ;
164+ final var force = forceRotateEvent == null || !forceRotateEvent .isCanceled ();
165+ RotationManager .resetYaw (original , force );
166+ return force ? player .getYaw () : original ;
149167 }
150168
151- @ ModifyExpressionValue (method = "setPosition( Lnet/minecraft/entity/EntityPosition;Ljava/util/Set;Lnet/minecraft/entity/Entity;Z)Z " , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/entity/EntityPosition;pitch()F" ) )
169+ @ ModifyExpressionValue (method = "setPosition" , at = { @ At ( value = "INVOKE" , target = " Lnet/minecraft/entity/EntityPosition;pitch()F " , ordinal = 0 ), @ At (value = "INVOKE" , target = "Lnet/minecraft/entity/EntityPosition;pitch()F" , ordinal = 1 )} )
152170 private static float wrapSetPitch (float original , @ Local (argsOnly = true ) Entity entity ) {
153171 var player = Lambda .getMc ().player ;
154172 if (entity != player ) return original ;
155173 if (player == null ) return original ;
156- if (NoForceRotate .INSTANCE .isEnabled ()) {
157- return player .getPitch ();
158- }
159- return original ;
174+ final var force = forceRotateEvent == null || !forceRotateEvent .isCanceled ();
175+ RotationManager .resetPitch (original , force );
176+ return force ? player .getPitch () : original ;
160177 }
161178}
0 commit comments