mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-23 21:39:47 +00:00
Finished block protector handling
This commit is contained in:
1 parent
26587ab2c4
commit
4b48d55604
2 files changed
+33
-5
No files matched your search
@@ -114,23 +114,49 @@ public class TileBlockProtector extends TileJarFillable {
|
||||
|
||||
private static List<TileBlockProtector> protectors = new ArrayList<TileBlockProtector>();
|
||||
|
||||
public static boolean isSpotProtected(World world, double x, double y, double z) {
|
||||
public static boolean isSpotProtected(World world, final double x, final double y, final double z) {
|
||||
return isSpotProtected(world, new ProtectionHelper() {
|
||||
@Override
|
||||
public boolean checkProtection(TileBlockProtector tile) {
|
||||
return isSpotProtected(tile, x, y, z);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isSpotProtected(World world, final Entity entity) {
|
||||
return isSpotProtected(world, new ProtectionHelper() {
|
||||
@Override
|
||||
public boolean checkProtection(TileBlockProtector tile) {
|
||||
return isSpotProtected(tile, entity);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean isSpotProtected(World world, ProtectionHelper helper) {
|
||||
for (int i = 0; i < protectors.size(); i++) {
|
||||
TileBlockProtector protector = protectors.get(i);
|
||||
if (protector.isInvalid()) {
|
||||
protectors.remove(i);
|
||||
i--;
|
||||
} else if (protector.worldObj.isRemote == world.isRemote
|
||||
&& isSpotProtected(protector, x, y, z)) {
|
||||
&& helper.checkProtection(protector)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static interface ProtectionHelper {
|
||||
boolean checkProtection(TileBlockProtector tile);
|
||||
}
|
||||
|
||||
private static boolean isSpotProtected(TileBlockProtector tile, Entity entity) {
|
||||
AxisAlignedBB protectedAABB = AxisAlignedBB.getBoundingBox(tile.xCoord - tile.range, tile.yCoord - tile.range, tile.zCoord - tile.range, tile.xCoord + tile.range, tile.yCoord + tile.range, tile.zCoord + tile.range);
|
||||
return protectedAABB.intersectsWith(entity.getBoundingBox());
|
||||
AxisAlignedBB entityAABB = entity.getBoundingBox();
|
||||
if(entityAABB != null) {
|
||||
return protectedAABB.intersectsWith(entityAABB.addCoord(entity.posX, entity.posY, entity.posZ));
|
||||
}
|
||||
return isSpotProtected(tile, entity.posX, entity.posY, entity.posZ);
|
||||
}
|
||||
|
||||
private static boolean isSpotProtected(TileBlockProtector tile, double x, double y, double z) {
|
||||
|
||||
@@ -90,7 +90,7 @@ public class EventHandlerWorld {
|
||||
for(StackTraceElement element : elements) {
|
||||
if(element.getClassName().equals(EntityLivingBase.class.getName())
|
||||
&& (element.getMethodName().equals("func_70071_h") || element.getMethodName().equals("onUpdate"))) {
|
||||
return !TileBlockProtector.isSpotProtected(lastUpdated.worldObj, lastUpdated.posX, lastUpdated.posY, lastUpdated.posZ);
|
||||
return !TileBlockProtector.isSpotProtected(lastUpdated.worldObj, lastUpdated);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,9 @@ public class EventHandlerWorld {
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public void on(ExplosionEvent.Start e) {
|
||||
Explosion expl = e.explosion;
|
||||
if(expl.isSmoking && TileBlockProtector.isSpotProtected(e.world, expl.explosionX, expl.explosionY, expl.explosionZ)) {
|
||||
if(expl.isSmoking
|
||||
&& (expl.exploder != null ? TileBlockProtector.isSpotProtected(e.world, expl.exploder) :
|
||||
TileBlockProtector.isSpotProtected(e.world, expl.explosionX, expl.explosionY, expl.explosionZ))) {
|
||||
//why?
|
||||
//expl.isSmoking = false;
|
||||
e.setCanceled(true);
|
||||
|
||||
Reference in new issue
Block a user