use of net.minecraft.world.Teleporter in project SpongeCommon by SpongePowered.
the class MixinTeleporter method findPortal.
@Override
public Optional<Location<World>> findPortal(Location<World> searchLocation) {
double closest = -1.0D;
boolean addToCache = true;
BlockPos portalPosition = BlockPos.ORIGIN;
// Sponge - use the chunk coords instead of block coords
Vector3i chunkPosition = searchLocation.getChunkPosition();
long targetPosition = ChunkPos.asLong(chunkPosition.getX(), chunkPosition.getZ());
if (this.destinationCoordinateCache.containsKey(targetPosition)) {
Teleporter.PortalPosition teleporter$portalposition = this.destinationCoordinateCache.get(targetPosition);
closest = 0.0D;
portalPosition = teleporter$portalposition;
teleporter$portalposition.lastUpdateTime = this.world.getTotalWorldTime();
addToCache = false;
} else {
BlockPos blockSearchPosition = ((IMixinLocation) (Object) searchLocation).getBlockPos();
for (int i1 = -this.searchRadius; i1 <= this.searchRadius; ++i1) {
BlockPos blockpos2;
for (int j1 = -this.searchRadius; j1 <= this.searchRadius; ++j1) {
for (BlockPos blockpos1 = blockSearchPosition.add(i1, this.world.getActualHeight() - 1 - blockSearchPosition.getY(), j1); blockpos1.getY() >= 0; blockpos1 = blockpos2) {
blockpos2 = blockpos1.down();
if (this.world.getBlockState(blockpos1).getBlock() == Blocks.PORTAL) {
while (this.world.getBlockState(blockpos2 = blockpos1.down()).getBlock() == Blocks.PORTAL) {
blockpos1 = blockpos2;
}
double distance = blockpos1.distanceSq(blockSearchPosition);
if (closest < 0.0D || distance < closest) {
closest = distance;
portalPosition = blockpos1;
}
}
}
}
}
}
if (closest >= 0.0D) {
if (addToCache) {
this.destinationCoordinateCache.put(targetPosition, ((Teleporter) (Object) this).new PortalPosition(portalPosition, this.world.getTotalWorldTime()));
}
return Optional.of(new Location<World>(searchLocation.getExtent(), VecHelper.toVector3d(portalPosition)));
}
return Optional.empty();
}
use of net.minecraft.world.Teleporter in project Tropicraft by Tropicraft.
the class TropicraftWorldUtils method teleportPlayer.
public static void teleportPlayer(EntityPlayerMP player) {
long time = System.currentTimeMillis();
if (player.dimension == TROPICS_DIMENSION_ID) {
Teleporter tropicsTeleporter = new TeleporterTropics(player.getServer().getWorld(0));
PlayerList pl = player.getServer().getPlayerList();
pl.transferPlayerToDimension(player, 0, tropicsTeleporter);
} else {
Teleporter tropicsTeleporter = new TeleporterTropics(player.getServer().getWorld(TROPICS_DIMENSION_ID));
PlayerList pl = player.getServer().getPlayerList();
pl.transferPlayerToDimension(player, TROPICS_DIMENSION_ID, tropicsTeleporter);
}
long time2 = System.currentTimeMillis();
System.out.printf("It took %f seconds to teleport\n", (time2 - time) / 1000.0F);
}
use of net.minecraft.world.Teleporter in project minecolonies by Minecolonies.
the class TeleportToColony method teleportPlayer.
/**
* Method used to teleport the player.
*
* @param colID the senders colony ID.
* @param playerToTeleport the player which shall be teleported.
*/
private static void teleportPlayer(final EntityPlayer playerToTeleport, final int colID, final ICommandSender sender) {
final Colony colony = ColonyManager.getColony(colID);
final BuildingTownHall townHall = colony.getBuildingManager().getTownHall();
if (townHall == null) {
sender.sendMessage(new TextComponentString(NO_TOWNHALL));
return;
}
playerToTeleport.sendMessage(new TextComponentString("We got places to go, kid..."));
final BlockPos position = townHall.getLocation();
final int dimension = playerToTeleport.getEntityWorld().provider.getDimension();
final int colonyDimension = townHall.getColony().getDimension();
if (colID < MIN_COLONY_ID) {
playerToTeleport.sendMessage(new TextComponentString(CANT_FIND_COLONY));
return;
}
final EntityPlayerMP entityPlayerMP = (EntityPlayerMP) sender;
if (dimension != colonyDimension) {
playerToTeleport.sendMessage(new TextComponentString("Buckle up buttercup, this ain't no joy ride!!!"));
final MinecraftServer server = sender.getEntityWorld().getMinecraftServer();
final WorldServer worldServer = server.getWorld(colonyDimension);
// Vanilla does that as well.
entityPlayerMP.connection.sendPacket(new SPacketEffect(SOUND_TYPE, BlockPos.ORIGIN, 0, false));
entityPlayerMP.addExperience(0);
entityPlayerMP.setPlayerHealthUpdated();
playerToTeleport.sendMessage(new TextComponentString("Hold onto your pants, we're going Inter-Dimensional!"));
worldServer.getMinecraftServer().getPlayerList().transferPlayerToDimension(entityPlayerMP, colonyDimension, new Teleporter(worldServer));
if (dimension == 1) {
worldServer.spawnEntity(playerToTeleport);
worldServer.updateEntityWithOptionalForce(playerToTeleport, false);
}
}
entityPlayerMP.connection.setPlayerLocation(position.getX(), position.getY() + 2.0, position.getZ(), entityPlayerMP.rotationYaw, entityPlayerMP.rotationPitch);
}
use of net.minecraft.world.Teleporter in project takumicraft by TNTModders.
the class BlockTakumiPortalFrame method changeDim.
private boolean changeDim(EntityPlayer playerIn) {
MinecraftServer server = playerIn.world.getMinecraftServer();
if (server != null) {
PlayerList playerList = server.getPlayerList();
int i = playerIn.dimension == DimensionType.OVERWORLD.getId() ? TakumiWorldCore.TAKUMI_WORLD.getId() : DimensionType.OVERWORLD.getId();
Teleporter teleporter = new TakumiTeleporter(server.getWorld(i));
if (playerIn instanceof EntityPlayerMP) {
playerList.transferPlayerToDimension((EntityPlayerMP) playerIn, i, teleporter);
} else {
int origin = playerIn.dimension;
playerIn.dimension = i;
playerIn.world.removeEntityDangerously(playerIn);
playerIn.isDead = false;
playerList.transferEntityToWorld(playerIn, origin, server.getWorld(origin), server.getWorld(i), teleporter);
}
}
return true;
}
use of net.minecraft.world.Teleporter in project Random-Things by lumien231.
the class EntityReviveCircle method onUpdate.
@Override
public void onUpdate() {
super.onUpdate();
age++;
if (!world.isRemote) {
if (this.reviver == null || this.reviver.isDead || this.reviver.getDistanceSq(this.getPosition()) > 25 || this.reviver.dimension != this.dimension || toRevive == null || toRevive.isDead) {
this.setDead();
}
if (this.world.getTotalWorldTime() % 20 == 0) {
EntityPlayerMP player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(toRevive.playerName);
if (player == null) {
this.setDead();
}
}
if (this.age >= 220 && this.world.getTotalWorldTime() % 10 == 0) {
reviver.attackEntityFrom(DamageSource.MAGIC, 1f);
}
if (this.age >= 400) {
toRevive.setDead();
this.setDead();
EntityPlayerMP player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().getPlayerByUsername(toRevive.playerName);
if (player != null) {
if (player.getHealth() <= 0) {
EntityPlayerMP revived = player.connection.player = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().recreatePlayerEntity(player, 0, false);
if (revived.world.provider.getDimension() != this.dimension) {
FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerList().transferPlayerToDimension(revived, this.world.provider.getDimension(), new Teleporter((WorldServer) this.world));
}
revived.connection.setPlayerLocation(posX, posY, posZ, revived.rotationYaw, revived.rotationPitch);
revived.setPositionAndUpdate(posX, posY, posZ);
}
}
}
} else {
if (this.age >= 200) {
world.spawnParticle(EnumParticleTypes.REDSTONE, this.posX + Math.random() - 0.5f, this.posY + Math.random(), this.posZ + Math.random() - 0.5f, 0, 0, 0, 1);
}
}
}
Aggregations