Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // transfer entity to dimension. do not transfer player using this method! use transferPlayerToDimension
- static boolean transferEntityToDimension(Entity sourceEntity, int destinationDimension, double x, double y, double z)
- {
- WorldServer sourceWorldServer = MinecraftServer.getServer().worldServerForDimension(sourceEntity.dimension);
- WorldServer destinationWorldServer = MinecraftServer.getServer().worldServerForDimension(destinationDimension);
- if(sourceWorldServer == null || destinationWorldServer == null)
- {
- return false;
- }
- NBTTagCompound tagCompound = new NBTTagCompound();
- float rotationYaw = sourceEntity.rotationYaw;
- float rotationPitch = sourceEntity.rotationPitch;
- sourceEntity.writeToNBT(tagCompound);
- Class<? extends Entity> entityClass = sourceEntity.getClass();
- sourceWorldServer.removeEntity(sourceEntity);
- try
- {
- if(sourceEntity instanceof EntityLiving)
- {
- Entity destinationEntity = entityClass.getConstructor(World.class).newInstance(destinationWorldServer);
- destinationEntity.readFromNBT(tagCompound);
- destinationEntity.setLocationAndAngles(x, y, z, rotationYaw, rotationPitch);
- destinationWorldServer.spawnEntityInWorld(destinationEntity);
- // register destination entity with
- TeleporterEntity.register(destinationEntity);
- // so the entity doesn't teleport again when the dimension loads
- TeleporterEntity.get(destinationEntity).setOnTeleporter(true);
- TeleporterEntity.get(destinationEntity).setTeleported(true);
- TeleporterEntity.transferToLocation(destinationEntity, x, y, z);
- }
- }
- catch (Exception e)
- {
- return false;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement