Guest User

Untitled

a guest
May 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. /**
  2. *supports teleporting entities from location to location in the same dimension doesn't support actual cross dimensional teleport
  3. */
  4. public static void doTeleport(Entity e, double x, double y, double z,float yaw, float pitch)
  5. {
  6. int chunkOldX = (int)e.posX >> 4;
  7. int chunkOldZ = (int)e.posZ >> 4;
  8. int chunkX = (int)x >> 4;
  9. int chunkZ = (int)z >> 4;
  10. //remove from old chunk
  11. if(chunkOldX != chunkX || chunkOldZ != chunkZ)
  12. {
  13. Chunk chunkOld = e.world.getChunkFromChunkCoords(chunkOldX,chunkOldZ);
  14. chunkOld.removeEntity(e);
  15. }
  16.  
  17. if (e instanceof EntityPlayerMP)
  18. {
  19. Set<SPacketPlayerPosLook.EnumFlags> set = EnumSet.<SPacketPlayerPosLook.EnumFlags>noneOf(SPacketPlayerPosLook.EnumFlags.class);
  20. e.dismountRidingEntity();
  21. e.setLocationAndAngles(x, y, z, e.rotationYaw, e.rotationPitch);
  22. ((EntityPlayerMP)e).connection.setPlayerLocation(x, y, z, yaw, pitch, set);
  23. }
  24. else
  25. {
  26. float f2 = (float)MathHelper.wrapDegrees(yaw);
  27. float f3 = (float)MathHelper.wrapDegrees(pitch);
  28. f3 = MathHelper.clamp(f3, -90.0F, 90.0F);
  29. e.setLocationAndAngles(x, y, z, f2, f3);
  30. }
  31.  
  32. if (!(e instanceof EntityLivingBase) || !((EntityLivingBase)e).isElytraFlying())
  33. {
  34. e.motionY = 0.0D;
  35. e.onGround = true;
  36. }
  37. //vanilla hotfix add entity to the chunk if not already added
  38. Chunk chunk = e.world.getChunkFromChunkCoords(chunkX,chunkZ);
  39. if(!containsEntity(chunk.getEntityLists(),e))
  40. chunk.addEntity(e);
  41. }
Add Comment
Please, Sign In to add comment