11/*
2- * Copyright 2025 Lambda
2+ * Copyright 2024 Lambda
33 *
44 * This program is free software: you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
2626import com .lambda .interaction .request .rotation .RotationManager ;
2727import com .lambda .module .modules .player .PortalGui ;
2828import net .minecraft .client .MinecraftClient ;
29+ import net .minecraft .client .gui .screen .DeathScreen ;
2930import net .minecraft .client .gui .screen .Screen ;
31+ import net .minecraft .client .gui .screen .ingame .HandledScreen ;
3032import net .minecraft .client .input .Input ;
3133import net .minecraft .client .network .ClientPlayerEntity ;
3234import net .minecraft .entity .MovementType ;
35+ import net .minecraft .entity .damage .DamageSource ;
3336import net .minecraft .util .Hand ;
3437import net .minecraft .util .math .Vec3d ;
3538import org .spongepowered .asm .mixin .Final ;
4649@ Mixin (value = ClientPlayerEntity .class , priority = Integer .MAX_VALUE )
4750public abstract class ClientPlayerEntityMixin extends EntityMixin {
4851
52+ @ Shadow
53+ public Input input ;
4954 @ Shadow
5055 private boolean autoJumpEnabled ;
5156
@@ -77,11 +82,11 @@ void onMove(MovementType movementType, Vec3d movement, CallbackInfo ci) {
7782 this .autoJump (currX - prevX , currZ - prevZ );
7883 }
7984
80- @ Redirect (method = "tickMovement" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/input/Input;tick()V" ))
81- void processMovement (Input input ) {
82- input .tick ();
83- RotationManager .BaritoneProcessor .processPlayerMovement (input );
84- EventFlow .post (new MovementEvent .InputUpdate (input ));
85+ @ Redirect (method = "tickMovement" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/input/Input;tick(ZF )V" ))
86+ void processMovement (Input input , boolean slowDown , float slowDownFactor ) {
87+ input .tick (slowDown , slowDownFactor );
88+ RotationManager .BaritoneProcessor .processPlayerMovement (input , slowDown , slowDownFactor );
89+ EventFlow .post (new MovementEvent .InputUpdate (input , slowDown , slowDownFactor ));
8590 }
8691
8792 /**
@@ -111,7 +116,7 @@ void redirectSneaking(CallbackInfoReturnable<Boolean> cir) {
111116 if (self != Lambda .getMc ().player ) return ;
112117
113118 if (self .input == null ) return ;
114- cir .setReturnValue (EventFlow .post (new MovementEvent .Sneak (self .input .playerInput . sneak () )).getSneak ());
119+ cir .setReturnValue (EventFlow .post (new MovementEvent .Sneak (self .input .sneaking )).getSneak ());
115120 }
116121
117122 /**
@@ -134,12 +139,12 @@ void onTickPost(CallbackInfo ci) {
134139 EventFlow .post (new TickEvent .Player .Post ());
135140 }
136141
137- @ Redirect (method = "tick " , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F" ))
142+ @ Redirect (method = "tickNewAi " , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;getYaw()F" ))
138143 float fixHeldItemYaw (ClientPlayerEntity instance ) {
139144 return Objects .requireNonNullElse (RotationManager .getHandYaw (), instance .getYaw ());
140145 }
141146
142- @ Redirect (method = "tick " , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F" ))
147+ @ Redirect (method = "tickNewAi " , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;getPitch()F" ))
143148 float fixHeldItemPitch (ClientPlayerEntity instance ) {
144149 return Objects .requireNonNullElse (RotationManager .getHandPitch (), instance .getPitch ());
145150 }
@@ -149,27 +154,24 @@ void onSwingHandPre(Hand hand, CallbackInfo ci) {
149154 if (EventFlow .post (new PlayerEvent .SwingHand (hand )).isCanceled ()) ci .cancel ();
150155 }
151156
152- @ Inject (method = "updateHealth " , at = @ At ("HEAD" ))
153- public void damage (float health , CallbackInfo ci ) {
154- EventFlow .post (new PlayerEvent .Damage (health ) );
157+ @ Inject (method = "damage " , at = @ At ("HEAD" ), cancellable = true )
158+ public void damage (DamageSource source , float amount , CallbackInfoReturnable < Boolean > cir ) {
159+ if ( EventFlow .post (new PlayerEvent .Damage (source , amount )). isCanceled ()) cir . setReturnValue ( false );
155160 }
156161
157162 /**
158163 * Prevents the game from closing Guis when the player is in a nether portal
159164 * <pre>{@code
160- * if (this.client.currentScreen != null
161- * && !this.client.currentScreen.shouldPause()
162- * && !(this.client.currentScreen instanceof DeathScreen)
163- * && !(this.client.currentScreen instanceof CreditsScreen)) {
165+ * if (this.client.currentScreen != null && !this.client.currentScreen.shouldPause() && !(this.client.currentScreen instanceof DeathScreen)) {
164166 * if (this.client.currentScreen instanceof HandledScreen) {
165167 * this.closeHandledScreen();
166168 * }
167169 *
168- * this.client.setScreen(null);
170+ * this.client.setScreen((Screen) null);
169171 * }
170172 * }</pre>
171173 */
172- @ Redirect (method = "tickNausea " , at = @ At (value = "FIELD" , target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;" ))
174+ @ Redirect (method = "updateNausea " , at = @ At (value = "FIELD" , target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;" ))
173175 Screen keepScreensInPortal (MinecraftClient instance ) {
174176 if (PortalGui .INSTANCE .isEnabled ()) return null ;
175177 else return client .currentScreen ;
0 commit comments