use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class TeleportDestinations method cleanupInvalid.
public void cleanupInvalid(World world) {
Set<GlobalCoordinate> keys = new HashSet<GlobalCoordinate>(destinations.keySet());
for (GlobalCoordinate key : keys) {
World transWorld = RfToolsDimensionManager.getDimensionManager(world).getWorldForDimension(key.getDimension());
boolean removed = false;
if (transWorld == null) {
Logging.log("Receiver on dimension " + key.getDimension() + " removed because world can't be loaded!");
removed = true;
} else {
Coordinate c = key.getCoordinate();
TileEntity te;
try {
te = transWorld.getTileEntity(c.getX(), c.getY(), c.getZ());
} catch (Exception e) {
te = null;
}
if (!(te instanceof MatterReceiverTileEntity)) {
Logging.log("Receiver at " + c + " on dimension " + key.getDimension() + " removed because there is no receiver there!");
removed = true;
}
}
if (removed) {
destinations.remove(key);
}
}
}
use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class MatterTransmitterBlock method addInformation.
@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean whatIsThis) {
super.addInformation(itemStack, player, list, whatIsThis);
NBTTagCompound tagCompound = itemStack.getTagCompound();
if (tagCompound != null) {
String name = tagCompound.getString("tpName");
list.add(EnumChatFormatting.GREEN + "Name: " + name);
boolean dialed = false;
Coordinate c = Coordinate.readFromNBT(tagCompound, "dest");
if (c != null && c.getY() >= 0) {
dialed = true;
} else if (tagCompound.hasKey("destId")) {
if (tagCompound.getInteger("destId") != -1) {
dialed = true;
}
}
if (dialed) {
int destId = tagCompound.getInteger("destId");
if (System.currentTimeMillis() - lastTime > 500) {
lastTime = System.currentTimeMillis();
RFToolsMessages.INSTANCE.sendToServer(new PacketGetDestinationInfo(destId));
}
String destname = "?";
if (ReturnDestinationInfoHelper.id != null && ReturnDestinationInfoHelper.id == destId) {
destname = ReturnDestinationInfoHelper.name;
}
list.add(EnumChatFormatting.YELLOW + "[DIALED to " + destname + "]");
}
boolean once = tagCompound.getBoolean("once");
if (once) {
list.add(EnumChatFormatting.YELLOW + "[ONCE]");
}
}
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
list.add(EnumChatFormatting.WHITE + "If you place this block near a Dialing Device then");
list.add(EnumChatFormatting.WHITE + "you can dial it to a Matter Receiver. Make sure to give");
list.add(EnumChatFormatting.WHITE + "it sufficient power!");
list.add(EnumChatFormatting.WHITE + "Use a Destination Analyzer adjacent to this block");
list.add(EnumChatFormatting.WHITE + "to check destination status (red is bad, green ok,");
list.add(EnumChatFormatting.WHITE + "yellow is unknown).");
list.add(EnumChatFormatting.WHITE + "Use a Matter Booster adjacent to this block");
list.add(EnumChatFormatting.WHITE + "to be able to teleport to unpowered receivers.");
list.add(EnumChatFormatting.YELLOW + "Infusing bonus: reduced power consumption and");
list.add(EnumChatFormatting.YELLOW + "increased teleportation speed.");
} else {
list.add(EnumChatFormatting.WHITE + RFTools.SHIFT_MESSAGE);
}
}
use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class ForgeEventHandlers method onDetonate.
@SubscribeEvent
public void onDetonate(ExplosionEvent.Detonate event) {
Explosion explosion = event.explosion;
Collection<GlobalCoordinate> protectors = getProtectors(event.world, (int) explosion.explosionX, (int) explosion.explosionY, (int) explosion.explosionZ);
if (protectors.isEmpty()) {
return;
}
List<ChunkPosition> affectedBlocks = event.getAffectedBlocks();
List<ChunkPosition> toremove = new ArrayList<ChunkPosition>();
Vec3 explosionVector = Vec3.createVectorHelper(explosion.explosionX, explosion.explosionY, explosion.explosionZ);
int rf = 0;
for (GlobalCoordinate protector : protectors) {
int cx = protector.getCoordinate().getX();
int cy = protector.getCoordinate().getY();
int cz = protector.getCoordinate().getZ();
TileEntity te = event.world.getTileEntity(cx, cy, cz);
if (te instanceof BlockProtectorTileEntity) {
BlockProtectorTileEntity blockProtectorTileEntity = (BlockProtectorTileEntity) te;
for (ChunkPosition block : affectedBlocks) {
Coordinate relative = blockProtectorTileEntity.absoluteToRelative(block.chunkPosX, block.chunkPosY, block.chunkPosZ);
boolean b = blockProtectorTileEntity.isProtected(relative);
if (b) {
Vec3 blockVector = Vec3.createVectorHelper(block.chunkPosX, block.chunkPosY, block.chunkPosZ);
double distanceTo = explosionVector.distanceTo(blockVector);
int rfneeded = blockProtectorTileEntity.attemptExplosionProtection((float) (distanceTo / explosion.explosionSize), explosion.explosionSize);
if (rfneeded > 0) {
toremove.add(block);
rf += rfneeded;
} else {
blockProtectorTileEntity.removeProtection(relative);
}
}
}
}
}
for (ChunkPosition block : toremove) {
affectedBlocks.remove(block);
}
Logging.logDebug("RF Needed for one explosion:" + rf);
}
use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class ForgeEventHandlers method checkHarvestProtection.
private void checkHarvestProtection(Event event, int x, int y, int z, World world, Collection<GlobalCoordinate> protectors) {
for (GlobalCoordinate protector : protectors) {
int cx = protector.getCoordinate().getX();
int cy = protector.getCoordinate().getY();
int cz = protector.getCoordinate().getZ();
TileEntity te = world.getTileEntity(cx, cy, cz);
if (te instanceof BlockProtectorTileEntity) {
BlockProtectorTileEntity blockProtectorTileEntity = (BlockProtectorTileEntity) te;
Coordinate relative = blockProtectorTileEntity.absoluteToRelative(x, y, z);
boolean b = blockProtectorTileEntity.isProtected(relative);
if (b) {
if (blockProtectorTileEntity.attemptHarvestProtection()) {
event.setCanceled(true);
} else {
blockProtectorTileEntity.removeProtection(relative);
}
return;
}
}
}
}
use of mcjty.lib.varia.Coordinate in project RFTools by McJty.
the class MachineInformationClientScreenModule method setupCoordinateFromNBT.
protected void setupCoordinateFromNBT(NBTTagCompound tagCompound, int dim, int x, int y, int z) {
coordinate = Coordinate.INVALID;
if (tagCompound.hasKey("monitorx")) {
this.dim = tagCompound.getInteger("dim");
if (dim == this.dim) {
Coordinate c = new Coordinate(tagCompound.getInteger("monitorx"), tagCompound.getInteger("monitory"), tagCompound.getInteger("monitorz"));
int dx = Math.abs(c.getX() - x);
int dy = Math.abs(c.getY() - y);
int dz = Math.abs(c.getZ() - z);
if (dx <= 64 && dy <= 64 && dz <= 64) {
coordinate = c;
}
}
}
}
Aggregations