2424import net .minecraft .inventory .IInventory ;
2525import net .minecraft .network .play .client .CPacketEntityAction ;
2626import net .minecraft .network .play .client .CPacketPlayer ;
27+ import net .minecraft .util .MovementInput ;
28+ import net .minecraft .util .math .AxisAlignedBB ;
2729import net .minecraft .util .math .Vec3d ;
2830import net .minecraft .world .IInteractionObject ;
2931import net .minecraft .world .World ;
3739import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
3840import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
3941
42+ import java .util .Objects ;
43+
4044@ Mixin (value = EntityPlayerSP .class , priority = Integer .MAX_VALUE )
4145public abstract class MixinEntityPlayerSP extends EntityPlayer {
4246 @ Shadow @ Final public NetHandlerPlayClient connection ;
47+ @ Shadow public MovementInput movementInput ;
48+ @ Shadow public float renderArmYaw ;
49+ @ Shadow public float renderArmPitch ;
50+ @ Shadow public float prevRenderArmYaw ;
51+ @ Shadow public float prevRenderArmPitch ;
4352 @ Shadow protected Minecraft mc ;
4453 @ Shadow private double lastReportedPosX ;
4554 @ Shadow private double lastReportedPosY ;
@@ -56,9 +65,6 @@ public MixinEntityPlayerSP(World worldIn, GameProfile gameProfileIn) {
5665 super (worldIn , gameProfileIn );
5766 }
5867
59- @ Shadow
60- protected abstract boolean isCurrentViewEntity ();
61-
6268 @ Shadow
6369 protected abstract void updateAutoJump (float p_189810_1_ , float p_189810_2_ );
6470
@@ -89,7 +95,7 @@ private void onPushOutOfBlocks(CallbackInfoReturnable<Boolean> callbackInfoRetur
8995 public void onDisplayGUIChest (IInventory chestInventory , CallbackInfo ci ) {
9096 if (BeaconSelector .INSTANCE .isEnabled ()) {
9197 if (chestInventory instanceof IInteractionObject && "minecraft:beacon" .equals (((IInteractionObject ) chestInventory ).getGuiID ())) {
92- Minecraft .getMinecraft ().displayGuiScreen (new LambdaGuiBeacon (this . inventory , chestInventory ));
98+ Minecraft .getMinecraft ().displayGuiScreen (new LambdaGuiBeacon (inventory , chestInventory ));
9399 ci .cancel ();
94100 }
95101 }
@@ -104,11 +110,11 @@ public void moveHead(MoverType type, double x, double y, double z, CallbackInfo
104110 LambdaEventBus .INSTANCE .post (event );
105111
106112 if (event .isModified ()) {
107- double prevX = this . posX ;
108- double prevZ = this . posZ ;
113+ double prevX = posX ;
114+ double prevZ = posZ ;
109115
110116 super .move (type , event .getX (), event .getY (), event .getZ ());
111- this . updateAutoJump ((float ) (this . posX - prevX ), (float ) (this . posZ - prevZ ));
117+ updateAutoJump ((float ) (posX - prevX ), (float ) (posZ - prevZ ));
112118
113119 ci .cancel ();
114120 }
@@ -123,11 +129,50 @@ public boolean modifySprinting(boolean sprinting) {
123129 }
124130 }
125131
126- // We have to return true here so it would still update movement inputs from Baritone and send packets
127- @ Inject (method = "isCurrentViewEntity" , at = @ At ("RETURN" ), cancellable = true )
128- protected void mixinIsCurrentViewEntity (CallbackInfoReturnable <Boolean > cir ) {
129- if (Freecam .INSTANCE .isEnabled () && Freecam .INSTANCE .getCameraGuy () != null ) {
130- cir .setReturnValue (mc .getRenderViewEntity () == Freecam .INSTANCE .getCameraGuy ());
132+ // Cannot use an inject in isCurrentViewEntity due to rusherhack redirecting it here
133+ @ Inject (method = "onUpdateWalkingPlayer" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/entity/EntityPlayerSP;isCurrentViewEntity()Z" ), cancellable = true )
134+ protected void mixinUpdateWalkingPlayerCompat (CallbackInfo ci ) {
135+ if (Freecam .INSTANCE .isEnabled () && Freecam .INSTANCE .getCameraGuy () != null && Objects .equals (this , mc .player )) {
136+ ci .cancel ();
137+ // we need to perform the same actions as what is in the mc method
138+ ++positionUpdateTicks ;
139+ final AxisAlignedBB boundingBox = getEntityBoundingBox ();
140+ final Vec3d pos = new Vec3d (posX , boundingBox .minY , posZ );
141+ final Vec2f rot = new Vec2f (rotationYaw , rotationPitch );
142+ final boolean isMoving = isMoving (pos );
143+ final boolean isRotating = isRotating (rot );
144+ sendPlayerPacket (isMoving , isRotating , pos , rot );
145+ if (isMoving ) {
146+ lastReportedPosX = pos .x ;
147+ lastReportedPosY = pos .y ;
148+ lastReportedPosZ = pos .z ;
149+ positionUpdateTicks = 0 ;
150+ }
151+
152+ if (isRotating ) {
153+ lastReportedYaw = rot .getX ();
154+ lastReportedPitch = rot .getY ();
155+ }
156+
157+ prevOnGround = onGround ;
158+ autoJumpEnabled = mc .gameSettings .autoJump ;
159+ }
160+ }
161+
162+ // Cannot use an inject in isCurrentViewEntity due to rusherhack redirecting it here
163+ @ Inject (method = "updateEntityActionState" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/entity/EntityPlayerSP;isCurrentViewEntity()Z" ), cancellable = true )
164+ protected void mixinEntityActionState (CallbackInfo ci ) {
165+ if (Freecam .INSTANCE .isEnabled () && Freecam .INSTANCE .getCameraGuy () != null && Objects .equals (this , mc .player )) {
166+ ci .cancel ();
167+
168+ // we need to perform the same actions as what is in the mc method
169+ moveStrafing = movementInput .moveStrafe ;
170+ moveForward = movementInput .moveForward ;
171+ isJumping = movementInput .jump ;
172+ prevRenderArmYaw = renderArmYaw ;
173+ prevRenderArmPitch = renderArmPitch ;
174+ renderArmPitch = renderArmPitch + (rotationPitch - renderArmPitch ) * 0.5f ;
175+ renderArmYaw = renderArmYaw + (rotationYaw - renderArmYaw ) * 0.5f ;
131176 }
132177 }
133178
@@ -141,23 +186,25 @@ private void onUpdateInvokeOnUpdateWalkingPlayer(CallbackInfo ci) {
141186 Vec3d serverSidePos = PlayerPacketManager .INSTANCE .getServerSidePosition ();
142187 Vec2f serverSideRotation = PlayerPacketManager .INSTANCE .getPrevServerSideRotation ();
143188
144- this . lastReportedPosX = serverSidePos .x ;
145- this . lastReportedPosY = serverSidePos .y ;
146- this . lastReportedPosZ = serverSidePos .z ;
189+ lastReportedPosX = serverSidePos .x ;
190+ lastReportedPosY = serverSidePos .y ;
191+ lastReportedPosZ = serverSidePos .z ;
147192
148- this . lastReportedYaw = serverSideRotation .getX ();
149- this . lastReportedPitch = serverSideRotation .getY ();
193+ lastReportedYaw = serverSideRotation .getX ();
194+ lastReportedPitch = serverSideRotation .getY ();
150195 }
151196
152197 @ Inject (method = "onUpdateWalkingPlayer" , at = @ At ("HEAD" ), cancellable = true )
153198 private void onUpdateWalkingPlayerHead (CallbackInfo ci ) {
199+ if (Freecam .INSTANCE .isEnabled () && Freecam .INSTANCE .getCameraGuy () != null
200+ && Objects .equals (this , Freecam .INSTANCE .getCameraGuy ())) return ;
154201
155202 CriticalsUpdateWalkingEvent criticalsEditEvent = new CriticalsUpdateWalkingEvent ();
156203 LambdaEventBus .INSTANCE .post (criticalsEditEvent );
157204
158205 // Setup flags
159- Vec3d position = new Vec3d (this . posX , this . getEntityBoundingBox ().minY , this . posZ );
160- Vec2f rotation = new Vec2f (this . rotationYaw , this . rotationPitch );
206+ Vec3d position = new Vec3d (posX , getEntityBoundingBox ().minY , posZ );
207+ Vec2f rotation = new Vec2f (rotationYaw , rotationPitch );
161208 boolean moving = isMoving (position );
162209 boolean rotating = isRotating (rotation );
163210
@@ -181,76 +228,71 @@ private void onUpdateWalkingPlayerHead(CallbackInfo ci) {
181228 sendSneakPacket ();
182229 sendPlayerPacket (moving , rotating , position , rotation );
183230
184- this . prevOnGround = onGround ;
231+ prevOnGround = onGround ;
185232 }
186233
187- ++this . positionUpdateTicks ;
188- this . autoJumpEnabled = this . mc .gameSettings .autoJump ;
234+ ++positionUpdateTicks ;
235+ autoJumpEnabled = mc .gameSettings .autoJump ;
189236 }
190237
191238 event = event .nextPhase ();
192239 LambdaEventBus .INSTANCE .post (event );
193240 }
194241
195242 private void sendSprintPacket () {
196- boolean sprinting = this . isSprinting ();
243+ boolean sprinting = isSprinting ();
197244
198- if (sprinting != this . serverSprintState ) {
245+ if (sprinting != serverSprintState ) {
199246 if (sprinting ) {
200- this . connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .START_SPRINTING ));
247+ connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .START_SPRINTING ));
201248 } else {
202- this . connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .STOP_SPRINTING ));
249+ connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .STOP_SPRINTING ));
203250 }
204- this . serverSprintState = sprinting ;
251+ serverSprintState = sprinting ;
205252 }
206253 }
207254
208255 private void sendSneakPacket () {
209- boolean sneaking = this . isSneaking ();
256+ boolean sneaking = isSneaking ();
210257
211- if (sneaking != this . serverSneakState ) {
258+ if (sneaking != serverSneakState ) {
212259 if (sneaking ) {
213- this . connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .START_SNEAKING ));
260+ connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .START_SNEAKING ));
214261 } else {
215- this . connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .STOP_SNEAKING ));
262+ connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .STOP_SNEAKING ));
216263 }
217- this . serverSneakState = sneaking ;
264+ serverSneakState = sneaking ;
218265 }
219266 }
220267
221268 private void sendPlayerPacket (boolean moving , boolean rotating , Vec3d position , Vec2f rotation ) {
222- if (!this .isCurrentViewEntity ()) return ;
223-
224- if (this .isRiding ()) {
225- this .connection .sendPacket (new CPacketPlayer .PositionRotation (this .motionX , -999.0D , this .motionZ , rotation .getX (), rotation .getY (), onGround ));
269+ if (isRiding ()) {
270+ connection .sendPacket (new CPacketPlayer .PositionRotation (motionX , -999.0D , motionZ , rotation .getX (), rotation .getY (), onGround ));
226271 moving = false ;
227272 } else if (moving && rotating ) {
228- this . connection .sendPacket (new CPacketPlayer .PositionRotation (position .x , position .y , position .z , rotation .getX (), rotation .getY (), onGround ));
273+ connection .sendPacket (new CPacketPlayer .PositionRotation (position .x , position .y , position .z , rotation .getX (), rotation .getY (), onGround ));
229274 } else if (moving ) {
230- this . connection .sendPacket (new CPacketPlayer .Position (position .x , position .y , position .z , onGround ));
275+ connection .sendPacket (new CPacketPlayer .Position (position .x , position .y , position .z , onGround ));
231276 } else if (rotating ) {
232- this . connection .sendPacket (new CPacketPlayer .Rotation (rotation .getX (), rotation .getY (), onGround ));
233- } else if (this . prevOnGround != onGround ) {
234- this . connection .sendPacket (new CPacketPlayer (onGround ));
277+ connection .sendPacket (new CPacketPlayer .Rotation (rotation .getX (), rotation .getY (), onGround ));
278+ } else if (prevOnGround != onGround ) {
279+ connection .sendPacket (new CPacketPlayer (onGround ));
235280 }
236281
237- if (moving ) {
238- this .positionUpdateTicks = 0 ;
239- }
282+ if (moving ) positionUpdateTicks = 0 ;
240283 }
241284
242285 private boolean isMoving (Vec3d position ) {
243- double xDiff = position .x - this . lastReportedPosX ;
244- double yDiff = position .y - this . lastReportedPosY ;
245- double zDiff = position .z - this . lastReportedPosZ ;
286+ double xDiff = position .x - lastReportedPosX ;
287+ double yDiff = position .y - lastReportedPosY ;
288+ double zDiff = position .z - lastReportedPosZ ;
246289
247- return this . positionUpdateTicks >= 20 || xDiff * xDiff + yDiff * yDiff + zDiff * zDiff > 9.0E-4D ;
290+ return positionUpdateTicks >= 20 || xDiff * xDiff + yDiff * yDiff + zDiff * zDiff > 9.0E-4D ;
248291 }
249292
250293 private boolean isRotating (Vec2f rotation ) {
251- double yawDiff = rotation .getX () - this .lastReportedYaw ;
252- double pitchDiff = rotation .getY () - this .lastReportedPitch ;
253-
294+ double yawDiff = rotation .getX () - lastReportedYaw ;
295+ double pitchDiff = rotation .getY () - lastReportedPitch ;
254296 return yawDiff != 0.0D || pitchDiff != 0.0D ;
255297 }
256298}
0 commit comments