24
24
import net .minecraft .inventory .IInventory ;
25
25
import net .minecraft .network .play .client .CPacketEntityAction ;
26
26
import net .minecraft .network .play .client .CPacketPlayer ;
27
+ import net .minecraft .util .MovementInput ;
28
+ import net .minecraft .util .math .AxisAlignedBB ;
27
29
import net .minecraft .util .math .Vec3d ;
28
30
import net .minecraft .world .IInteractionObject ;
29
31
import net .minecraft .world .World ;
37
39
import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
38
40
import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
39
41
42
+ import java .util .Objects ;
43
+
40
44
@ Mixin (value = EntityPlayerSP .class , priority = Integer .MAX_VALUE )
41
45
public abstract class MixinEntityPlayerSP extends EntityPlayer {
42
46
@ 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 ;
43
52
@ Shadow protected Minecraft mc ;
44
53
@ Shadow private double lastReportedPosX ;
45
54
@ Shadow private double lastReportedPosY ;
@@ -56,9 +65,6 @@ public MixinEntityPlayerSP(World worldIn, GameProfile gameProfileIn) {
56
65
super (worldIn , gameProfileIn );
57
66
}
58
67
59
- @ Shadow
60
- protected abstract boolean isCurrentViewEntity ();
61
-
62
68
@ Shadow
63
69
protected abstract void updateAutoJump (float p_189810_1_ , float p_189810_2_ );
64
70
@@ -89,7 +95,7 @@ private void onPushOutOfBlocks(CallbackInfoReturnable<Boolean> callbackInfoRetur
89
95
public void onDisplayGUIChest (IInventory chestInventory , CallbackInfo ci ) {
90
96
if (BeaconSelector .INSTANCE .isEnabled ()) {
91
97
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 ));
93
99
ci .cancel ();
94
100
}
95
101
}
@@ -104,11 +110,11 @@ public void moveHead(MoverType type, double x, double y, double z, CallbackInfo
104
110
LambdaEventBus .INSTANCE .post (event );
105
111
106
112
if (event .isModified ()) {
107
- double prevX = this . posX ;
108
- double prevZ = this . posZ ;
113
+ double prevX = posX ;
114
+ double prevZ = posZ ;
109
115
110
116
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 ));
112
118
113
119
ci .cancel ();
114
120
}
@@ -123,11 +129,50 @@ public boolean modifySprinting(boolean sprinting) {
123
129
}
124
130
}
125
131
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 ;
131
176
}
132
177
}
133
178
@@ -141,23 +186,25 @@ private void onUpdateInvokeOnUpdateWalkingPlayer(CallbackInfo ci) {
141
186
Vec3d serverSidePos = PlayerPacketManager .INSTANCE .getServerSidePosition ();
142
187
Vec2f serverSideRotation = PlayerPacketManager .INSTANCE .getPrevServerSideRotation ();
143
188
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 ;
147
192
148
- this . lastReportedYaw = serverSideRotation .getX ();
149
- this . lastReportedPitch = serverSideRotation .getY ();
193
+ lastReportedYaw = serverSideRotation .getX ();
194
+ lastReportedPitch = serverSideRotation .getY ();
150
195
}
151
196
152
197
@ Inject (method = "onUpdateWalkingPlayer" , at = @ At ("HEAD" ), cancellable = true )
153
198
private void onUpdateWalkingPlayerHead (CallbackInfo ci ) {
199
+ if (Freecam .INSTANCE .isEnabled () && Freecam .INSTANCE .getCameraGuy () != null
200
+ && Objects .equals (this , Freecam .INSTANCE .getCameraGuy ())) return ;
154
201
155
202
CriticalsUpdateWalkingEvent criticalsEditEvent = new CriticalsUpdateWalkingEvent ();
156
203
LambdaEventBus .INSTANCE .post (criticalsEditEvent );
157
204
158
205
// 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 );
161
208
boolean moving = isMoving (position );
162
209
boolean rotating = isRotating (rotation );
163
210
@@ -181,76 +228,71 @@ private void onUpdateWalkingPlayerHead(CallbackInfo ci) {
181
228
sendSneakPacket ();
182
229
sendPlayerPacket (moving , rotating , position , rotation );
183
230
184
- this . prevOnGround = onGround ;
231
+ prevOnGround = onGround ;
185
232
}
186
233
187
- ++this . positionUpdateTicks ;
188
- this . autoJumpEnabled = this . mc .gameSettings .autoJump ;
234
+ ++positionUpdateTicks ;
235
+ autoJumpEnabled = mc .gameSettings .autoJump ;
189
236
}
190
237
191
238
event = event .nextPhase ();
192
239
LambdaEventBus .INSTANCE .post (event );
193
240
}
194
241
195
242
private void sendSprintPacket () {
196
- boolean sprinting = this . isSprinting ();
243
+ boolean sprinting = isSprinting ();
197
244
198
- if (sprinting != this . serverSprintState ) {
245
+ if (sprinting != serverSprintState ) {
199
246
if (sprinting ) {
200
- this . connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .START_SPRINTING ));
247
+ connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .START_SPRINTING ));
201
248
} else {
202
- this . connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .STOP_SPRINTING ));
249
+ connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .STOP_SPRINTING ));
203
250
}
204
- this . serverSprintState = sprinting ;
251
+ serverSprintState = sprinting ;
205
252
}
206
253
}
207
254
208
255
private void sendSneakPacket () {
209
- boolean sneaking = this . isSneaking ();
256
+ boolean sneaking = isSneaking ();
210
257
211
- if (sneaking != this . serverSneakState ) {
258
+ if (sneaking != serverSneakState ) {
212
259
if (sneaking ) {
213
- this . connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .START_SNEAKING ));
260
+ connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .START_SNEAKING ));
214
261
} else {
215
- this . connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .STOP_SNEAKING ));
262
+ connection .sendPacket (new CPacketEntityAction (this , CPacketEntityAction .Action .STOP_SNEAKING ));
216
263
}
217
- this . serverSneakState = sneaking ;
264
+ serverSneakState = sneaking ;
218
265
}
219
266
}
220
267
221
268
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 ));
226
271
moving = false ;
227
272
} 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 ));
229
274
} 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 ));
231
276
} 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 ));
235
280
}
236
281
237
- if (moving ) {
238
- this .positionUpdateTicks = 0 ;
239
- }
282
+ if (moving ) positionUpdateTicks = 0 ;
240
283
}
241
284
242
285
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 ;
246
289
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 ;
248
291
}
249
292
250
293
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 ;
254
296
return yawDiff != 0.0D || pitchDiff != 0.0D ;
255
297
}
256
298
}
0 commit comments