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();
- // if write fails entity is a mount; must write parent to instead
- while(sourceEntity.writeToNBTOptional(tagCompound) == false)
- {
- sourceEntity = sourceEntity.riddenByEntity;
- sourceEntity.writeToNBTOptional(tagCompound);
- }
- // get rotation values from entity
- float rotationYaw = sourceEntity.rotationYaw;
- float rotationPitch = sourceEntity.rotationPitch;
- // remove entity from source world
- sourceWorldServer.removeEntity(sourceEntity);
- // create entity from saved nbt tag
- Entity destinationEntity = EntityList.createEntityFromNBT(tagCompound, destinationWorldServer);
- // set entity location and orientation
- destinationEntity.setLocationAndAngles(x, y, z, rotationYaw, rotationPitch);
- // spawn entity in destination world
- destinationWorldServer.spawnEntityInWorld(destinationEntity);
- // register destination entity with IExtendedEntityProperties - TeleporterEntity
- TeleporterEntity destinationEntityProperties = TeleporterEntity.get(destinationEntity);
- if(destinationEntityProperties == null)
- {
- TeleporterEntity.register(destinationEntity);
- }
- // so the entity doesn't teleport again when the dimension loads
- destinationEntityProperties.setOnTeleporter(true);
- destinationEntityProperties.setTeleported(true);
- // finally, apply the teleportation transfer to ensure the enemy is in the correct location
- TeleporterEntity.transferToLocation(destinationEntity, x, y, z);
- return true;
- }
Add Comment
Please, Sign In to add comment