use of com.mraof.minestuck.tileentity.TileEntityTransportalizer in project Minestuck by mraof.
the class CommandTransportalizer method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 1 || args.length > 2)
throw new WrongUsageException(this.getUsage(sender));
String code;
// TODO make it possible to apply this command to more than just players
EntityPlayerMP player;
if (args.length == 1) {
code = args[0];
player = getCommandSenderAsPlayer(sender);
} else {
code = args[1];
player = getPlayer(server, sender, args[0]);
}
code = code.toUpperCase();
if (player == null)
throw new PlayerNotFoundException("commands.generic.player.unspecified");
Location location = TileEntityTransportalizer.transportalizers.get(code);
if (location == null || !DimensionManager.isDimensionRegistered(location.dim))
throw new CommandException("commands.tpz.notFound", code);
WorldServer world = server.getWorld(location.dim);
TileEntity te = world.getTileEntity(location.pos);
if (te == null || !(te instanceof TileEntityTransportalizer)) {
Debug.warn("Invalid transportalizer in map: " + code + " at " + location);
TileEntityTransportalizer.transportalizers.remove(code);
throw new CommandException("commands.tpz.notFound", code);
}
IBlockState block0 = world.getBlockState(location.pos.up());
IBlockState block1 = world.getBlockState(location.pos.up(2));
if (block0.getMaterial().blocksMovement() || block1.getMaterial().blocksMovement())
throw new CommandException("message.transportalizer.destinationBlocked");
boolean success = Teleport.teleportEntity(player, location.dim, null, te.getPos().getX() + 0.5, te.getPos().getY() + 0.6, te.getPos().getZ() + 0.5);
if (success) {
player.timeUntilPortal = 60;
notifyCommandListener(sender, this, "commands.tpz.success", player.getName(), code);
} else if (sender.sendCommandFeedback())
throw new CommandException("commands.tpz.failed");
}
use of com.mraof.minestuck.tileentity.TileEntityTransportalizer in project Minestuck by mraof.
the class ItemCruxiteArtifact method makeDestination.
@Override
public void makeDestination(Entity entity, WorldServer worldserver0, WorldServer worldserver1) {
if (entity instanceof EntityPlayerMP) {
// ((EntityPlayerMP) entity).addStat(MinestuckAchievementHandler.enterMedium);
Debug.infof("Starting entry for player %s", entity.getName());
int x = (int) entity.posX;
if (entity.posX < 0)
x--;
int y = (int) entity.posY;
int z = (int) entity.posZ;
if (entity.posZ < 0)
z--;
boolean creative = ((EntityPlayerMP) entity).interactionManager.isCreative();
int topY = MinestuckConfig.adaptEntryBlockHeight ? getTopHeight(worldserver0, x, y, z) : y + artifactRange;
int yDiff = 127 - topY;
// Set again, but with a more precise now that the y-coordinate is properly decided.
MinestuckDimensionHandler.setSpawn(worldserver1.provider.getDimension(), new BlockPos(x, y + yDiff, z));
Debug.debug("Loading spawn chunks...");
for (// Prevent anything to generate on the piece that we move
int chunkX = ((x - artifactRange) >> 4) - 1; // Prevent anything to generate on the piece that we move
chunkX <= ((x + artifactRange) >> 4) + 2; // Prevent anything to generate on the piece that we move
chunkX++) for (// from the overworld.
int chunkZ = ((z - artifactRange) >> 4) - 1; // from the overworld.
chunkZ <= ((z + artifactRange) >> 4) + 2; // from the overworld.
chunkZ++) worldserver1.getChunkProvider().provideChunk(chunkX, chunkZ);
Debug.debug("Placing blocks...");
long time = System.currentTimeMillis();
int bl = 0;
for (int blockX = x - artifactRange; blockX <= x + artifactRange; blockX++) {
int zWidth = (int) Math.sqrt((artifactRange + 0.5) * (artifactRange + 0.5) - (blockX - x) * (blockX - x));
for (int blockZ = z - zWidth; blockZ <= z + zWidth; blockZ++) {
Chunk chunk = worldserver1.getChunkFromChunkCoords(blockX >> 4, blockZ >> 4);
Chunk chunk2 = worldserver0.getChunkFromChunkCoords(blockX >> 4, blockZ >> 4);
int height = (int) Math.sqrt(artifactRange * artifactRange - (((blockX - x) * (blockX - x) + (blockZ - z) * (blockZ - z)) / 2));
for (int blockY = Math.max(0, y - height); blockY <= Math.min(topY, y + height); blockY++) {
BlockPos pos = new BlockPos(blockX, blockY, blockZ);
BlockPos pos1 = pos.up(yDiff);
IBlockState block = worldserver0.getBlockState(pos);
TileEntity te = worldserver0.getTileEntity(pos);
long t = System.currentTimeMillis();
if (block.getBlock() != Blocks.BEDROCK && block.getBlock() != Blocks.PORTAL) {
copyBlockDirect(chunk, chunk2, blockX & 15, blockY + yDiff, blockY, blockZ & 15);
} else {
worldserver1.setBlockState(new BlockPos(blockX, blockY + yDiff, blockZ), Blocks.AIR.getDefaultState(), 3);
}
bl += System.currentTimeMillis() - t;
if ((te) != null) {
TileEntity te1 = null;
try {
te1 = te.getClass().newInstance();
} catch (Exception e) {
e.printStackTrace();
continue;
}
NBTTagCompound nbt = new NBTTagCompound();
te.writeToNBT(nbt);
nbt.setInteger("y", pos1.getY());
te1.readFromNBT(nbt);
worldserver1.removeTileEntity(pos1);
worldserver1.setTileEntity(pos1, te1);
if (te instanceof TileEntityComputer)
SkaianetHandler.movingComputer((TileEntityComputer) te, (TileEntityComputer) te1);
}
}
for (int blockY = Math.min(topY, y + height) + yDiff + 1; blockY < 256; blockY++) worldserver1.setBlockState(new BlockPos(blockX, blockY, blockZ), Blocks.AIR.getDefaultState(), 0);
}
}
int total = (int) (System.currentTimeMillis() - time);
Debug.debugf("Total: %d, block: %d", total, bl);
Debug.debug("Teleporting entities...");
AxisAlignedBB entityTeleportBB = entity.getEntityBoundingBox().grow((double) artifactRange, artifactRange, (double) artifactRange);
List<Entity> list = worldserver0.getEntitiesWithinAABBExcludingEntity(entity, entityTeleportBB);
Iterator<Entity> iterator = list.iterator();
entity.setPositionAndUpdate(entity.posX, entity.posY + yDiff, entity.posZ);
while (iterator.hasNext()) {
Entity e = iterator.next();
if (MinestuckConfig.entryCrater || e instanceof EntityPlayer || !creative && e instanceof EntityItem) {
if (e instanceof EntityPlayer && ServerEditHandler.getData((EntityPlayer) e) != null)
ServerEditHandler.reset(ServerEditHandler.getData((EntityPlayer) e));
else {
Teleport.teleportEntity(e, worldserver1.provider.getDimension(), null, e.posX, e.posY + yDiff, e.posZ);
}
} else // Copy instead of teleport
{
Entity newEntity = EntityList.newEntity(entity.getClass(), worldserver1);
if (newEntity != null) {
NBTTagCompound nbttagcompound = new NBTTagCompound();
entity.writeToNBT(nbttagcompound);
nbttagcompound.removeTag("Dimension");
newEntity.readFromNBT(nbttagcompound);
newEntity.dimension = worldserver1.provider.getDimension();
newEntity.setPosition(newEntity.posX, newEntity.posY + yDiff, newEntity.posZ);
worldserver1.spawnEntity(newEntity);
}
}
}
Debug.debug("Removing old blocks...");
for (int blockX = x - artifactRange; blockX <= x + artifactRange; blockX++) {
int zWidth = (int) Math.sqrt(artifactRange * artifactRange - (blockX - x) * (blockX - x));
boolean isEdgeX = Math.abs(blockX - x) == artifactRange;
for (int blockZ = z - zWidth; blockZ <= z + zWidth; blockZ++) {
double radius = Math.sqrt(((blockX - x) * (blockX - x) + (blockZ - z) * (blockZ - z)) / 2);
int height = (int) (Math.sqrt(artifactRange * artifactRange - radius * radius));
int minY = y - height;
minY = minY < 0 ? 0 : minY;
int maxY = MinestuckConfig.entryCrater ? Math.min(topY, y + height) + 1 : 256;
boolean isEdgeZ = Math.abs(blockZ - z) == zWidth;
for (int blockY = minY; blockY < maxY; blockY++) {
BlockPos pos = new BlockPos(blockX, blockY, blockZ);
if (MinestuckConfig.entryCrater) {
if (worldserver0.getBlockState(pos).getBlock() != Blocks.BEDROCK) {
if (isEdgeX || isEdgeZ || blockY == minY || blockY == maxY - 1) {
worldserver0.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
} else {
worldserver0.setBlockState(pos, Blocks.AIR.getDefaultState(), 2);
}
}
} else {
TileEntity tileEntity = worldserver0.getTileEntity(pos);
if (tileEntity != null)
if (!creative)
worldserver0.setBlockState(pos, Blocks.AIR.getDefaultState(), 3);
else if (// Avoid duplicating computer data when a computer is kept in the overworld
tileEntity instanceof TileEntityComputer)
((TileEntityComputer) tileEntity).programData = new NBTTagCompound();
else if (tileEntity instanceof TileEntityTransportalizer)
worldserver0.removeTileEntity(pos);
}
}
}
}
SkaianetHandler.clearMovingList();
if (!creative || MinestuckConfig.entryCrater) {
// Normally only items in containers
Debug.debug("Removing entities created from removing blocks...");
list = worldserver0.getEntitiesWithinAABBExcludingEntity(entity, entityTeleportBB);
iterator = list.iterator();
while (iterator.hasNext()) if (MinestuckConfig.entryCrater)
iterator.next().setDead();
else {
Entity e = iterator.next();
if (e instanceof EntityItem)
e.setDead();
}
}
Debug.debug("Placing gates...");
GateHandler.findGatePlacement(worldserver1);
placeGate(1, new BlockPos(x, GateHandler.gateHeight1, z), worldserver1);
placeGate(2, new BlockPos(x, GateHandler.gateHeight2, z), worldserver1);
ServerEventHandler.tickTasks.add(new PostEntryTask(worldserver1.provider.getDimension(), x, y + yDiff, z, artifactRange, (byte) 0));
Debug.info("Entry finished");
}
}
Aggregations