* @param link destination
* @return teleported entity
*/
public Entity teleportEntity(Entity entity, TelDestination link)
{
WorldServer oldWorld, newWorld;
EntityPlayerMP player;
try
{
oldWorld = (WorldServer) entity.worldObj;
newWorld = (WorldServer) link.dim;
player = (entity instanceof EntityPlayerMP) ? (EntityPlayerMP) entity : null;
}
catch (Throwable e)
{
return entity;
}
if ( oldWorld == null )
return entity;
if ( newWorld == null )
return entity;
// Is something riding? Handle it first.
if ( entity.riddenByEntity != null )
{
return teleportEntity( entity.riddenByEntity, link );
}
// Are we riding something? Dismount and tell the mount to go first.
Entity cart = entity.ridingEntity;
if ( cart != null )
{
entity.mountEntity( null );
cart = teleportEntity( cart, link );
// We keep track of both so we can remount them on the other side.
}
// load the chunk!
WorldServer.class.cast( newWorld ).getChunkProvider().loadChunk( MathHelper.floor_double( link.x ) >> 4, MathHelper.floor_double( link.z ) >> 4 );
boolean difDest = newWorld != oldWorld;
if ( difDest )
{
if ( player != null )
{
if ( link.dim.provider instanceof StorageWorldProvider )
Achievements.SpatialIOExplorer.addToPlayer( player );
player.mcServer.getConfigurationManager().transferPlayerToDimension( player, link.dim.provider.dimensionId, new METeleporter( newWorld, link ) );
}
else
{
int entX = entity.chunkCoordX;
int entZ = entity.chunkCoordZ;
if ( (entity.addedToChunk) && (oldWorld.getChunkProvider().chunkExists( entX, entZ )) )
{
oldWorld.getChunkFromChunkCoords( entX, entZ ).removeEntity( entity );
oldWorld.getChunkFromChunkCoords( entX, entZ ).isModified = true;
}
Entity newEntity = EntityList.createEntityByName( EntityList.getEntityString( entity ), newWorld );
if ( newEntity != null )
{