66import net .aspw .viaforgeplus .event .EventState ;
77import net .aspw .viaforgeplus .event .MotionEvent ;
88import net .aspw .viaforgeplus .event .PushOutEvent ;
9+ import net .aspw .viaforgeplus .event .UpdateEvent ;
910import net .minecraft .client .Minecraft ;
11+ import net .minecraft .client .audio .PositionedSoundRecord ;
1012import net .minecraft .client .entity .AbstractClientPlayer ;
1113import net .minecraft .client .entity .EntityPlayerSP ;
1214import net .minecraft .client .network .NetHandlerPlayClient ;
15+ import net .minecraft .item .ItemSword ;
1316import net .minecraft .network .Packet ;
1417import net .minecraft .network .play .client .C03PacketPlayer ;
1518import net .minecraft .network .play .client .C0BPacketEntityAction ;
19+ import net .minecraft .potion .Potion ;
20+ import net .minecraft .util .MovementInput ;
21+ import net .minecraft .util .ResourceLocation ;
1622import net .minecraft .world .World ;
1723import org .spongepowered .asm .mixin .*;
1824import org .spongepowered .asm .mixin .injection .At ;
@@ -27,11 +33,25 @@ public abstract class MixinEntityPlayerSP extends AbstractClientPlayer {
2733 @ Shadow
2834 public boolean serverSprintState ;
2935 @ Shadow
36+ public int sprintingTicksLeft ;
37+ @ Shadow
38+ public float timeInPortal ;
39+ @ Shadow
40+ public float prevTimeInPortal ;
41+ @ Shadow
42+ public MovementInput movementInput ;
43+ @ Shadow
44+ public float horseJumpPower ;
45+ @ Shadow
46+ public int horseJumpPowerCounter ;
47+ @ Shadow
3048 @ Final
3149 public NetHandlerPlayClient sendQueue ;
3250 @ Shadow
3351 public int positionUpdateTicks ;
3452 @ Shadow
53+ protected int sprintToggleTimer ;
54+ @ Shadow
3555 protected Minecraft mc ;
3656 @ Unique
3757 private boolean viaForge$prevOnGround ;
@@ -60,6 +80,12 @@ public MixinEntityPlayerSP(World p_i45074_1_, GameProfile p_i45074_2_) {
6080 @ Shadow
6181 protected abstract boolean isCurrentViewEntity ();
6282
83+ @ Shadow
84+ protected abstract void sendHorseJump ();
85+
86+ @ Shadow
87+ public abstract boolean isRidingHorse ();
88+
6389 @ Redirect (method = "onUpdateWalkingPlayer" , at = @ At (value = "INVOKE" , target = "Lnet/minecraft/client/network/NetHandlerPlayClient;addToSendQueue(Lnet/minecraft/network/Packet;)V" , ordinal = 7 ))
6490 public void viaPatch (final NetHandlerPlayClient instance , final Packet <?> p_addToSendQueue_1_ ) {
6591 if (ProtocolFixer .newerThan1_8 ()) {
@@ -159,6 +185,160 @@ public void onUpdateWalkingPlayer() {
159185 }
160186 }
161187
188+ /**
189+ * @author As_pw
190+ * @reason Update Event
191+ */
192+ @ Override
193+ @ Overwrite
194+ public void onLivingUpdate () {
195+ ProtocolInject .eventManager .callEvent (new UpdateEvent ());
196+ if (this .sprintingTicksLeft > 0 ) {
197+ --this .sprintingTicksLeft ;
198+
199+ if (this .sprintingTicksLeft == 0 ) {
200+ this .setSprinting (false );
201+ }
202+ }
203+
204+ if (this .sprintToggleTimer > 0 ) {
205+ --this .sprintToggleTimer ;
206+ }
207+
208+ this .prevTimeInPortal = this .timeInPortal ;
209+
210+ if (this .inPortal ) {
211+ if (this .mc .currentScreen != null && !this .mc .currentScreen .doesGuiPauseGame ()) {
212+ this .mc .displayGuiScreen (null );
213+ }
214+
215+ if (this .timeInPortal == 0.0F ) {
216+ this .mc .getSoundHandler ().playSound (PositionedSoundRecord .create (new ResourceLocation ("portal.trigger" ), this .rand .nextFloat () * 0.4F + 0.8F ));
217+ }
218+
219+ this .timeInPortal += 0.0125F ;
220+
221+ if (this .timeInPortal >= 1.0F ) {
222+ this .timeInPortal = 1.0F ;
223+ }
224+
225+ this .inPortal = false ;
226+ } else if (this .isPotionActive (Potion .confusion ) && this .getActivePotionEffect (Potion .confusion ).getDuration () > 60 ) {
227+ this .timeInPortal += 0.006666667F ;
228+
229+ if (this .timeInPortal > 1.0F ) {
230+ this .timeInPortal = 1.0F ;
231+ }
232+ } else {
233+ if (this .timeInPortal > 0.0F ) {
234+ this .timeInPortal -= 0.05F ;
235+ }
236+
237+ if (this .timeInPortal < 0.0F ) {
238+ this .timeInPortal = 0.0F ;
239+ }
240+ }
241+
242+ if (this .timeUntilPortal > 0 ) {
243+ --this .timeUntilPortal ;
244+ }
245+
246+ final boolean flag = this .movementInput .jump ;
247+ final boolean flag1 = this .movementInput .sneak ;
248+ final float f = 0.8F ;
249+ final boolean flag2 = this .movementInput .moveForward >= f ;
250+ this .movementInput .updatePlayerMoveState ();
251+
252+ if (getHeldItem () != null && (this .isUsingItem () || (getHeldItem ().getItem () instanceof ItemSword && mc .thePlayer .isBlocking () && !this .isRiding ()))) {
253+ this .movementInput .moveStrafe *= 0.2F ;
254+ this .movementInput .moveForward *= 0.2F ;
255+ this .sprintToggleTimer = 0 ;
256+ }
257+
258+ this .pushOutOfBlocks (this .posX - (double ) this .width * 0.35D , this .getEntityBoundingBox ().minY + 0.5D , this .posZ + (double ) this .width * 0.35D );
259+ this .pushOutOfBlocks (this .posX - (double ) this .width * 0.35D , this .getEntityBoundingBox ().minY + 0.5D , this .posZ - (double ) this .width * 0.35D );
260+ this .pushOutOfBlocks (this .posX + (double ) this .width * 0.35D , this .getEntityBoundingBox ().minY + 0.5D , this .posZ - (double ) this .width * 0.35D );
261+ this .pushOutOfBlocks (this .posX + (double ) this .width * 0.35D , this .getEntityBoundingBox ().minY + 0.5D , this .posZ + (double ) this .width * 0.35D );
262+
263+ final boolean flag3 = (float ) this .getFoodStats ().getFoodLevel () > 6.0F || this .capabilities .allowFlying ;
264+
265+ if (this .onGround && !flag1 && !flag2 && this .movementInput .moveForward >= f && !this .isSprinting () && flag3 && !this .isUsingItem () && !this .isPotionActive (Potion .blindness )) {
266+ if (this .sprintToggleTimer <= 0 && !this .mc .gameSettings .keyBindSprint .isKeyDown ()) {
267+ this .sprintToggleTimer = 7 ;
268+ } else {
269+ this .setSprinting (true );
270+ }
271+ }
272+
273+ if (!this .isSprinting () && this .movementInput .moveForward >= f && flag3 && !this .isUsingItem () && !this .isPotionActive (Potion .blindness ) && this .mc .gameSettings .keyBindSprint .isKeyDown ())
274+ this .setSprinting (true );
275+
276+ if (this .isSprinting () && (this .movementInput .moveForward < f || mc .thePlayer .isCollidedHorizontally || !flag3 ))
277+ this .setSprinting (false );
278+
279+ if (this .capabilities .allowFlying ) {
280+ if (this .mc .playerController .isSpectatorMode ()) {
281+ if (!this .capabilities .isFlying ) {
282+ this .capabilities .isFlying = true ;
283+ this .sendPlayerAbilities ();
284+ }
285+ } else if (!flag && this .movementInput .jump ) {
286+ if (this .flyToggleTimer == 0 ) {
287+ this .flyToggleTimer = 7 ;
288+ } else {
289+ this .capabilities .isFlying = !this .capabilities .isFlying ;
290+ this .sendPlayerAbilities ();
291+ this .flyToggleTimer = 0 ;
292+ }
293+ }
294+ }
295+
296+ if (this .capabilities .isFlying && this .isCurrentViewEntity ()) {
297+ if (this .movementInput .sneak ) {
298+ this .motionY -= this .capabilities .getFlySpeed () * 3.0F ;
299+ }
300+
301+ if (this .movementInput .jump ) {
302+ this .motionY += this .capabilities .getFlySpeed () * 3.0F ;
303+ }
304+ }
305+
306+ if (this .isRidingHorse ()) {
307+ if (this .horseJumpPowerCounter < 0 ) {
308+ ++this .horseJumpPowerCounter ;
309+
310+ if (this .horseJumpPowerCounter == 0 ) {
311+ this .horseJumpPower = 0.0F ;
312+ }
313+ }
314+
315+ if (flag && !this .movementInput .jump ) {
316+ this .horseJumpPowerCounter = -10 ;
317+ this .sendHorseJump ();
318+ } else if (!flag && this .movementInput .jump ) {
319+ this .horseJumpPowerCounter = 0 ;
320+ this .horseJumpPower = 0.0F ;
321+ } else if (flag ) {
322+ ++this .horseJumpPowerCounter ;
323+
324+ if (this .horseJumpPowerCounter < 10 ) {
325+ this .horseJumpPower = (float ) this .horseJumpPowerCounter * 0.1F ;
326+ } else {
327+ this .horseJumpPower = 0.8F + 2.0F / (float ) (this .horseJumpPowerCounter - 9 ) * 0.1F ;
328+ }
329+ }
330+ } else {
331+ this .horseJumpPower = 0.0F ;
332+ }
333+
334+ super .onLivingUpdate ();
335+
336+ if (this .onGround && this .capabilities .isFlying && !this .mc .playerController .isSpectatorMode ()) {
337+ this .capabilities .isFlying = false ;
338+ this .sendPlayerAbilities ();
339+ }
340+ }
341+
162342 @ Inject (method = "pushOutOfBlocks" , at = @ At ("HEAD" ), cancellable = true )
163343 private void pushOutEvent (final CallbackInfoReturnable <Boolean > callbackInfoReturnable ) {
164344 final PushOutEvent event = new PushOutEvent ();
0 commit comments