Advertisement
GamingLVScripts

handlePlayerPosLook

Apr 1st, 2024
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. /**
  2.      * Handles changes in player positioning and rotation such as when travelling to a new dimension, (re)spawning,
  3.      * mounting horses etc. Seems to immediately reply to the server with the clients post-processing perspective on the
  4.      * player positioning
  5.      */
  6.     public void handlePlayerPosLook(S08PacketPlayerPosLook packetIn)
  7.     {
  8.         PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);
  9.         EntityPlayer entityplayer = this.gameController.thePlayer;
  10.         double d0 = packetIn.getX();
  11.         double d1 = packetIn.getY();
  12.         double d2 = packetIn.getZ();
  13.         float f = packetIn.getYaw();
  14.         float f1 = packetIn.getPitch();
  15.  
  16.         if (packetIn.func_179834_f().contains(S08PacketPlayerPosLook.EnumFlags.X)) {
  17.             d0 += entityplayer.posX;
  18.         } else {
  19.             entityplayer.motionX = 0.0D;
  20.         }
  21.  
  22.         if (packetIn.func_179834_f().contains(S08PacketPlayerPosLook.EnumFlags.Y)) {
  23.             d1 += entityplayer.posY;
  24.         } else {
  25.             entityplayer.motionY = 0.0D;
  26.         }
  27.  
  28.         if (packetIn.func_179834_f().contains(S08PacketPlayerPosLook.EnumFlags.Z)) {
  29.             d2 += entityplayer.posZ;
  30.         } else {
  31.             entityplayer.motionZ = 0.0D;
  32.         }
  33.  
  34.         if (packetIn.func_179834_f().contains(S08PacketPlayerPosLook.EnumFlags.X_ROT)) {
  35.             f1 += PlayerHandler.pitch;
  36.         }
  37.  
  38.         if (packetIn.func_179834_f().contains(S08PacketPlayerPosLook.EnumFlags.Y_ROT)) {
  39.             f += PlayerHandler.yaw;
  40.         }
  41.  
  42.         final HeadLookEvent headLookEvent = new HeadLookEvent(f, f1, d0, d1, d2).publishItself();
  43.  
  44.         final float yaw = f;
  45.         final float pitch = f1;
  46.         if (!headLookEvent.isCancelled())
  47.             entityplayer.setPositionAndRotation(headLookEvent.getX(), headLookEvent.getY(), headLookEvent.getZ(), headLookEvent.getYaw(), headLookEvent.getPitch());
  48.         PlayerHandler.yaw = yaw;
  49.         PlayerHandler.pitch = pitch;
  50.         this.netManager.sendPacket(new C03PacketPlayer.C06PacketPlayerPosLook(entityplayer.posX, entityplayer.getEntityBoundingBox().minY, entityplayer.posZ, yaw, pitch, false));
  51.  
  52.         if (!this.doneLoadingTerrain) {
  53.             this.gameController.thePlayer.prevPosX = this.gameController.thePlayer.posX;
  54.             this.gameController.thePlayer.prevPosY = this.gameController.thePlayer.posY;
  55.             this.gameController.thePlayer.prevPosZ = this.gameController.thePlayer.posZ;
  56.             this.doneLoadingTerrain = true;
  57.             this.gameController.displayGuiScreen((GuiScreen) null);
  58.         }
  59.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement