use of mcjty.rftools.blocks.environmental.modules.PeacefulEModule in project RFTools by McJty.
the class PeacefulAreaManager method isPeaceful.
public static boolean isPeaceful(GlobalCoordinate coordinate) {
if (areas.isEmpty()) {
return false;
}
List<GlobalCoordinate> toRemove = new ArrayList<>();
boolean peaceful = false;
long curtime = System.currentTimeMillis() - 10000;
for (Map.Entry<GlobalCoordinate, PeacefulArea> entry : areas.entrySet()) {
PeacefulArea area = entry.getValue();
GlobalCoordinate entryCoordinate = entry.getKey();
if (area.in(coordinate, entryCoordinate)) {
peaceful = true;
}
if (area.getLastTouched() < curtime) {
// Hasn't been touched for at least 10 seconds. Probably no longer valid.
// To be sure we will first check this by testing if the environmental controller is still active and running.
WorldServer world = DimensionManager.getWorld(entryCoordinate.getDimension());
if (world != null) {
BlockPos c = entryCoordinate.getCoordinate();
// If the world is not loaded we don't do anything and we also don't remove the area since we have no information about it.
if (RFToolsTools.chunkLoaded(world, c)) {
boolean removeArea = true;
TileEntity te = world.getTileEntity(c);
if (te instanceof EnvironmentalControllerTileEntity) {
EnvironmentalControllerTileEntity controllerTileEntity = (EnvironmentalControllerTileEntity) te;
for (EnvironmentModule module : controllerTileEntity.getEnvironmentModules()) {
if (module instanceof PeacefulEModule) {
if (((PeacefulEModule) module).isActive()) {
removeArea = false;
break;
}
}
}
}
if (removeArea) {
toRemove.add(entryCoordinate);
}
}
}
}
}
for (GlobalCoordinate globalCoordinate : toRemove) {
areas.remove(globalCoordinate);
}
return peaceful;
}
Aggregations