Advertisement
GamingLVScripts

onUpdateWalkingPlayer

Apr 1st, 2024
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.48 KB | None | 0 0
  1. /**
  2.      * called every tick when the player is on foot. Performs all the things that normally happen during movement.
  3.      */
  4.     public void onUpdateWalkingPlayer(UpdateMotionEvent updateMotionEvent, float yaw, float pitch) {
  5.         boolean flag = this.isSprinting();
  6.  
  7.         if (flag != this.serverSprintState) {
  8.             if (flag) {
  9.                 this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.START_SPRINTING));
  10.             } else {
  11.                 this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.STOP_SPRINTING));
  12.             }
  13.  
  14.  
  15.             PlayerHandler.shouldSprintReset = false;
  16.  
  17.             this.serverSprintState = flag;
  18.         }
  19.  
  20.         boolean flag1 = this.isSneaking();
  21.  
  22.         if (flag1 != this.serverSneakState) {
  23.             if (flag1) {
  24.                 this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.START_SNEAKING));
  25.             } else {
  26.                 this.sendQueue.addToSendQueue(new C0BPacketEntityAction(this, C0BPacketEntityAction.Action.STOP_SNEAKING));
  27.             }
  28.  
  29.             this.serverSneakState = flag1;
  30.         }
  31.  
  32.         if (updateMotionEvent.isCurrentView()) {
  33.             double d0 = this.posX - this.lastReportedPosX;
  34.             double d1 = this.getEntityBoundingBox().minY - this.lastReportedPosY;
  35.             double d2 = this.posZ - this.lastReportedPosZ;
  36.             double d3 = (double) (yaw - this.lastReportedYaw);
  37.             double d4 = (double) (pitch - this.lastReportedPitch);
  38.  
  39.             boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
  40.             boolean flag3 = d3 != 0.0D || d4 != 0.0D;
  41.  
  42.             if (this.ridingEntity == null) {
  43.                 if (flag2 && flag3) {
  44.                     this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, yaw, pitch, this.onGround));
  45.                 } else if (flag2) {
  46.                     this.sendQueue.addToSendQueue(new C03PacketPlayer.C04PacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround));
  47.                 } else if (flag3) {
  48.                     this.sendQueue.addToSendQueue(new C03PacketPlayer.C05PacketPlayerLook(yaw, pitch, this.onGround));
  49.                 } else {
  50.                     this.sendQueue.addToSendQueue(new C03PacketPlayer(this.onGround));
  51.                 }
  52.             } else {
  53.                 final RidingEntityEvent ridingEntityEvent = new RidingEntityEvent(this.motionX, -999D, this.motionZ, this.onGround).publishItself();
  54.                 this.sendQueue.addToSendQueue(new C03PacketPlayer.C06PacketPlayerPosLook(ridingEntityEvent.getMotionX(), ridingEntityEvent.getMotionY(), ridingEntityEvent.getMotionZ(), yaw, pitch, ridingEntityEvent.isOnGround()));
  55.                 flag2 = false;
  56.             }
  57.  
  58.             ++this.positionUpdateTicks;
  59.  
  60.             if (flag2) {
  61.                 this.lastReportedPosX = this.posX;
  62.                 this.lastReportedPosY = this.getEntityBoundingBox().minY;
  63.                 this.lastReportedPosZ = this.posZ;
  64.                 this.positionUpdateTicks = 0;
  65.             }
  66.  
  67.             if (flag3) {
  68.                 this.lastReportedYaw = yaw;
  69.                 this.lastReportedPitch = pitch;
  70.             }
  71.  
  72.             new UpdateMotionEvent(UpdateMotionEvent.Type.POST, updateMotionEvent.isCurrentView()).publishItself();
  73.         }
  74.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement