Advertisement
Guest User

transferEntityToDimension

a guest
Feb 16th, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.84 KB | None | 0 0
  1. // transfer entity to dimension. do not transfer player using this method! use transferPlayerToDimension
  2.     static boolean transferEntityToDimension(Entity sourceEntity, int destinationDimension, double x, double y, double z)
  3.     {
  4.         WorldServer sourceWorldServer = MinecraftServer.getServer().worldServerForDimension(sourceEntity.dimension);
  5.         WorldServer destinationWorldServer = MinecraftServer.getServer().worldServerForDimension(destinationDimension);
  6.        
  7.         if(sourceWorldServer == null || destinationWorldServer == null)
  8.         {
  9.             return false;
  10.         }
  11.        
  12.         NBTTagCompound tagCompound = new NBTTagCompound();
  13.         float rotationYaw = sourceEntity.rotationYaw;
  14.         float rotationPitch = sourceEntity.rotationPitch;
  15.         sourceEntity.writeToNBT(tagCompound);
  16.         Class<? extends Entity> entityClass = sourceEntity.getClass();
  17.         sourceWorldServer.removeEntity(sourceEntity);
  18.  
  19.         try
  20.         {
  21.             if(sourceEntity instanceof EntityLiving)
  22.             {
  23.                 Entity destinationEntity = entityClass.getConstructor(World.class).newInstance(destinationWorldServer);
  24.                 destinationEntity.readFromNBT(tagCompound);
  25.                 destinationEntity.setLocationAndAngles(x, y, z, rotationYaw, rotationPitch);
  26.                 destinationWorldServer.spawnEntityInWorld(destinationEntity);
  27.                
  28.                 // register destination entity with
  29.                 TeleporterEntity.register(destinationEntity);
  30.            
  31.                 // so the entity doesn't teleport again when the dimension loads
  32.                 TeleporterEntity.get(destinationEntity).setOnTeleporter(true);
  33.                 TeleporterEntity.get(destinationEntity).setTeleported(true);
  34.                
  35.                 TeleporterEntity.transferToLocation(destinationEntity, x, y, z);
  36.             }
  37.         }
  38.         catch (Exception e)
  39.         {
  40.             return false;
  41.         }      
  42.        
  43.         return true;
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement