2424import com .lambda .event .events .TickEvent ;
2525import com .lambda .interaction .PlayerPacketManager ;
2626import com .lambda .interaction .request .rotation .RotationManager ;
27+ import com .lambda .module .modules .player .PortalGui ;
28+ import net .minecraft .client .MinecraftClient ;
29+ import net .minecraft .client .gui .screen .DeathScreen ;
30+ import net .minecraft .client .gui .screen .Screen ;
31+ import net .minecraft .client .gui .screen .ingame .HandledScreen ;
2732import net .minecraft .client .input .Input ;
2833import net .minecraft .client .network .ClientPlayerEntity ;
2934import net .minecraft .entity .MovementType ;
3035import net .minecraft .entity .damage .DamageSource ;
3136import net .minecraft .util .Hand ;
3237import net .minecraft .util .math .Vec3d ;
38+ import org .spongepowered .asm .mixin .Final ;
3339import org .spongepowered .asm .mixin .Mixin ;
3440import org .spongepowered .asm .mixin .Shadow ;
3541import org .spongepowered .asm .mixin .injection .At ;
@@ -51,6 +57,11 @@ public abstract class ClientPlayerEntityMixin extends EntityMixin {
5157 @ Shadow
5258 protected abstract void autoJump (float dx , float dz );
5359
60+ @ Shadow @ Final protected MinecraftClient client ;
61+
62+ /**
63+ * Post movement events and applies the modified player velocity
64+ */
5465 @ Inject (method = "move" , at = @ At ("HEAD" ), cancellable = true )
5566 void onMove (MovementType movementType , Vec3d movement , CallbackInfo ci ) {
5667 ClientPlayerEntity self = (ClientPlayerEntity ) (Object ) this ;
@@ -78,6 +89,22 @@ void processMovement(Input input, boolean slowDown, float slowDownFactor) {
7889 EventFlow .post (new MovementEvent .InputUpdate (input , slowDown , slowDownFactor ));
7990 }
8091
92+ /**
93+ * Posts the {@link MovementEvent.Sprint} event
94+ * <pre>{@code
95+ * if (this.isSprinting()) {
96+ * boolean bl8 = !this.input.hasForwardMovement() || !this.canSprint();
97+ * boolean bl9 = bl8 || this.horizontalCollision && !this.collidedSoftly || this.isTouchingWater() && !this.isSubmergedInWater();
98+ * if (this.isSwimming()) {
99+ * if (!this.isOnGround() && !this.input.sneaking && bl8 || !this.isTouchingWater()) {
100+ * this.setSprinting(false);
101+ * }
102+ * } else if (bl9) {
103+ * this.setSprinting(false);
104+ * }
105+ * }
106+ * }</pre>
107+ */
81108 @ Redirect (method = "tickMovement" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z" ))
82109 boolean isSprinting (ClientPlayerEntity entity ) {
83110 return EventFlow .post (new MovementEvent .Sprint (entity .isSprinting ())).getSprint ();
@@ -92,6 +119,9 @@ void redirectSneaking(CallbackInfoReturnable<Boolean> cir) {
92119 cir .setReturnValue (EventFlow .post (new MovementEvent .Sneak (self .input .sneaking )).getSneak ());
93120 }
94121
122+ /**
123+ * Overwrites the movement packet update function to use our code
124+ */
95125 @ Inject (method = "sendMovementPackets" , at = @ At (value = "HEAD" ), cancellable = true )
96126 void sendBegin (CallbackInfo ci ) {
97127 ci .cancel ();
@@ -126,8 +156,24 @@ void onSwingHandPre(Hand hand, CallbackInfo ci) {
126156
127157 @ Inject (method = "damage" , at = @ At ("HEAD" ), cancellable = true )
128158 public void damage (DamageSource source , float amount , CallbackInfoReturnable <Boolean > cir ) {
129- if (EventFlow .post (new PlayerEvent .Damage (source , amount )).isCanceled ()) {
130- cir .setReturnValue (false );
131- }
159+ if (EventFlow .post (new PlayerEvent .Damage (source , amount )).isCanceled ()) cir .setReturnValue (false );
160+ }
161+
162+ /**
163+ * Prevents the game from closing Guis when the player is in a nether portal
164+ * <pre>{@code
165+ * if (this.client.currentScreen != null && !this.client.currentScreen.shouldPause() && !(this.client.currentScreen instanceof DeathScreen)) {
166+ * if (this.client.currentScreen instanceof HandledScreen) {
167+ * this.closeHandledScreen();
168+ * }
169+ *
170+ * this.client.setScreen((Screen)null);
171+ * }
172+ * }</pre>
173+ */
174+ @ Redirect (method = "updateNausea" , at = @ At (value = "FIELD" , target = "Lnet/minecraft/client/MinecraftClient;currentScreen:Lnet/minecraft/client/gui/screen/Screen;" ))
175+ Screen keepScreensInPortal (MinecraftClient instance ) {
176+ if (PortalGui .INSTANCE .isEnabled ()) return null ;
177+ else return client .currentScreen ;
132178 }
133179}
0 commit comments