diff --git a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileBlockProtector.java b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileBlockProtector.java index b80aca1..ed8087e 100644 --- a/src/main/java/makeo/gadomancy/common/blocks/tiles/TileBlockProtector.java +++ b/src/main/java/makeo/gadomancy/common/blocks/tiles/TileBlockProtector.java @@ -114,23 +114,49 @@ public class TileBlockProtector extends TileJarFillable { private static List protectors = new ArrayList(); - 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) { diff --git a/src/main/java/makeo/gadomancy/common/events/EventHandlerWorld.java b/src/main/java/makeo/gadomancy/common/events/EventHandlerWorld.java index e6d40b0..7e2eaa2 100644 --- a/src/main/java/makeo/gadomancy/common/events/EventHandlerWorld.java +++ b/src/main/java/makeo/gadomancy/common/events/EventHandlerWorld.java @@ -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);