use of com.mraof.minestuck.util.Location 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.util.Location in project Minestuck by mraof.
the class TileEntityTransportalizer method loadTransportalizers.
public static void loadTransportalizers(NBTTagCompound tagCompound) {
for (Object id : tagCompound.getKeySet()) {
NBTTagCompound locationTag = tagCompound.getCompoundTag((String) id);
put((String) id, new Location(locationTag.getInteger("x"), locationTag.getInteger("y"), locationTag.getInteger("z"), locationTag.getInteger("dim")));
}
}
use of com.mraof.minestuck.util.Location in project Minestuck by mraof.
the class TileEntityTransportalizer method teleport.
public void teleport(Entity entity) {
Location location = transportalizers.get(this.destId);
if (!enabled) {
entity.timeUntilPortal = entity.getPortalCooldown();
if (entity instanceof EntityPlayerMP)
entity.sendMessage(new TextComponentTranslation("message.transportalizer.transportalizerDisabled"));
return;
}
if (location != null && location.pos.getY() != -1) {
WorldServer world = entity.getServer().getWorld(location.dim);
TileEntityTransportalizer destTransportalizer = (TileEntityTransportalizer) world.getTileEntity(location.pos);
if (destTransportalizer == null) {
Debug.warn("Invalid transportalizer in map: " + this.destId + " at " + location);
transportalizers.remove(this.destId);
this.destId = "";
return;
}
// Fail silently to make it look as though the player entered an ID that doesn't map to a transportalizer.
if (!destTransportalizer.getEnabled()) {
return;
}
for (int id : MinestuckConfig.forbiddenDimensionsTpz) if (this.world.provider.getDimension() == id || location.dim == id) {
entity.timeUntilPortal = entity.getPortalCooldown();
if (entity instanceof EntityPlayerMP)
entity.sendMessage(new TextComponentTranslation(this.world.provider.getDimension() == id ? "message.transportalizer.forbidden" : "message.transportalizer.forbiddenDest"));
return;
}
IBlockState block0 = this.world.getBlockState(this.pos.up());
IBlockState block1 = this.world.getBlockState(this.pos.up(2));
if (block0.getMaterial().blocksMovement() || block1.getMaterial().blocksMovement()) {
entity.timeUntilPortal = entity.getPortalCooldown();
if (entity instanceof EntityPlayerMP)
entity.sendMessage(new TextComponentTranslation("message.transportalizer.blocked"));
return;
}
block0 = world.getBlockState(location.pos.up());
block1 = world.getBlockState(location.pos.up(2));
if (block0.getMaterial().blocksMovement() || block1.getMaterial().blocksMovement()) {
entity.timeUntilPortal = entity.getPortalCooldown();
if (entity instanceof EntityPlayerMP)
entity.sendMessage(new TextComponentTranslation("message.transportalizer.destinationBlocked"));
return;
}
Teleport.teleportEntity(entity, location.dim, null, destTransportalizer.pos.getX() + 0.5, destTransportalizer.pos.getY() + 0.6, destTransportalizer.pos.getZ() + 0.5);
entity.timeUntilPortal = entity.getPortalCooldown();
}
}
use of com.mraof.minestuck.util.Location in project Minestuck by mraof.
the class TileEntityTransportalizer method saveTransportalizers.
public static void saveTransportalizers(NBTTagCompound tagCompound) {
NBTTagCompound transportalizerTagCompound = new NBTTagCompound();
Iterator<Map.Entry<String, Location>> it = transportalizers.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Location> entry = it.next();
Location location = entry.getValue();
NBTTagCompound locationTag = new NBTTagCompound();
locationTag.setInteger("x", location.pos.getX());
locationTag.setInteger("y", location.pos.getY());
locationTag.setInteger("z", location.pos.getZ());
locationTag.setInteger("dim", location.dim);
transportalizerTagCompound.setTag(entry.getKey(), locationTag);
}
tagCompound.setTag("transportalizers", transportalizerTagCompound);
}
use of com.mraof.minestuck.util.Location in project Minestuck by mraof.
the class GateHandler method teleport.
public static void teleport(int gateId, int dim, EntityPlayerMP player) {
Location location = null;
// Basically to avoid message spam when something goes wrong
player.timeUntilPortal = player.getPortalCooldown();
if (gateId == 1) {
BlockPos pos = getGatePos(-1, dim);
Random rand = player.world.rand;
BlockPos spawn = player.world.provider.getSpawnPoint();
if (pos != null)
do {
int radius = 160 + rand.nextInt(60);
double d = rand.nextDouble();
int i = radius * radius;
int x = (int) Math.sqrt(i * d);
int z = (int) Math.sqrt(i * (1 - d));
if (rand.nextBoolean())
x = -x;
if (rand.nextBoolean())
z = -z;
BlockPos placement = pos.add(x, 0, z);
if (player.world.getBiomeForCoordsBody(placement) == BiomeMinestuck.mediumNormal)
location = new Location(player.world.getTopSolidOrLiquidBlock(placement), dim);
} while (// TODO replace with a more friendly version without a chance of freezing the game
location == null);
else
Debug.errorf("Unexpected error: Couldn't find position for land gate for dimension %d.", dim);
} else if (gateId == 2) {
SburbConnection landConnection = SburbHandler.getConnectionForDimension(dim);
if (landConnection != null) {
SburbConnection clientConnection = SkaianetHandler.getMainConnection(landConnection.getClientIdentifier(), false);
if (clientConnection != null && clientConnection.enteredGame() && MinestuckDimensionHandler.isLandDimension(clientConnection.getClientDimension())) {
int clientDim = clientConnection.getClientDimension();
BlockPos gatePos = getGatePos(-1, clientDim);
WorldServer world = player.mcServer.getWorld(clientDim);
if (gatePos == null) {
findGatePlacement(world);
gatePos = getGatePos(-1, clientDim);
if (gatePos == null) {
Debug.errorf("Unexpected error: Can't initiaize land gate placement for dimension %d!", clientDim);
return;
}
}
if (gatePos.getY() == -1) {
world.getChunkProvider().provideChunk(gatePos.getX() - 8 >> 4, gatePos.getZ() - 8 >> 4);
world.getChunkProvider().provideChunk(gatePos.getX() + 8 >> 4, gatePos.getZ() - 8 >> 4);
world.getChunkProvider().provideChunk(gatePos.getX() - 8 >> 4, gatePos.getZ() + 8 >> 4);
world.getChunkProvider().provideChunk(gatePos.getX() + 8 >> 4, gatePos.getZ() + 8 >> 4);
gatePos = getGatePos(-1, clientDim);
if (gatePos.getY() == -1) {
Debug.errorf("Unexpected error: Gate didn't generate after loading chunks! Dim: %d, pos: %s", clientDim, gatePos);
return;
}
}
location = new Location(gatePos, clientDim);
} else
player.sendMessage(new TextComponentTranslation("message.gateMissingLand"));
} else
Debug.errorf("Unexpected error: Can't find connection for dimension %d!", dim);
} else if (gateId == -1) {
SburbConnection landConnection = SburbHandler.getConnectionForDimension(dim);
if (landConnection != null) {
SburbConnection serverConnection = SkaianetHandler.getMainConnection(landConnection.getServerIdentifier(), true);
if (// Last shouldn't be necessary, but just in case something goes wrong elsewhere...
serverConnection != null && serverConnection.enteredGame() && MinestuckDimensionHandler.isLandDimension(serverConnection.getClientDimension())) {
int serverDim = serverConnection.getClientDimension();
location = new Location(getGatePos(2, serverDim), serverDim);
} else
player.sendMessage(new TextComponentTranslation("message.gateMissingLand"));
} else
Debug.errorf("Unexpected error: Can't find connection for dimension %d!", dim);
} else
Debug.errorf("Unexpected error: Gate id %d is out of bounds!", gateId);
if (location != null) {
if (gateId != 1) {
WorldServer world = player.mcServer.getWorld(location.dim);
IBlockState block = world.getBlockState(location.pos);
if (block.getBlock() != MinestuckBlocks.gate) {
Debug.debugf("Can't find destination gate at %s. Probably destroyed.", location);
player.sendMessage(new TextComponentTranslation("message.gateDestroyed"));
return;
}
}
Teleport.teleportEntity(player, location.dim, null, location.pos);
}
}
Aggregations