use of mcjty.lib.varia.GlobalCoordinate 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.GlobalCoordinate in project RFTools by McJty.
the class ForgeEventHandlers method getProtectors.
private Collection<GlobalCoordinate> getProtectors(World world, int x, int y, int z) {
Collection<GlobalCoordinate> protectors;
BlockProtectors blockProtectors = BlockProtectors.getProtectors(world);
if (blockProtectors == null) {
protectors = Collections.emptyList();
} else {
int id = world.provider.dimensionId;
protectors = blockProtectors.findProtectors(x, y, z, id, 2);
}
return protectors;
}
use of mcjty.lib.varia.GlobalCoordinate 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.GlobalCoordinate 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.GlobalCoordinate in project RFTools by McJty.
the class ForgeEventHandlers method onPlayerInteractEvent.
@SubscribeEvent
public void onPlayerInteractEvent(PlayerInteractEvent event) {
ItemStack heldItem = event.entityPlayer.getHeldItem();
if (heldItem == null || heldItem.getItem() == null) {
return;
}
if (event.entityPlayer.isSneaking() && WrenchChecker.isAWrench(heldItem.getItem())) {
// If the block is protected we prevent sneak-wrenching it.
World world = event.world;
int x = event.x;
int y = event.y;
int z = event.z;
Collection<GlobalCoordinate> protectors = getProtectors(world, x, y, z);
checkHarvestProtection(event, x, y, z, world, protectors);
}
}
Aggregations