diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java index 4afe030f..3a4bd005 100644 --- a/src/main/java/crazypants/enderio/config/Config.java +++ b/src/main/java/crazypants/enderio/config/Config.java @@ -334,6 +334,7 @@ public final class Config { public static double killerJoeHooverXpWidth = 5; public static double killerJoeHooverXpLength = 10; public static int killerJoeMaxXpLevel = Integer.MAX_VALUE; + public static boolean killerJoeMustSee = false; public static boolean allowTileEntitiesAsPaintSource = true; @@ -1005,6 +1006,8 @@ public final class Config { "The distance from which XP will be gathered in front of Joe.").getDouble(killerJoeHooverXpWidth); killerJoeMaxXpLevel = config.get(sectionMisc.name, "killerJoeMaxXpLevel", killerJoeMaxXpLevel, "Maximum level of XP the killer joe can contain.").getInt(); + killerJoeMustSee = config.get(sectionKiller.name, "killerJoeMustSee", killerJoeMustSee, "Set whether the Killer Joe can attack through blocks.").getBoolean(); + isGasConduitEnabled = config.getString("isGasConduitEnabled", sectionItems.name, isGasConduitEnabled, "Can be set to 'auto', 'true' or 'false'. When set to auto the gas conduit will only be enabled when Mekanism is installed."); enableMEConduits = config.getBoolean("enableMEConduits", sectionItems.name, enableMEConduits, diff --git a/src/main/java/crazypants/enderio/machine/AbstractMachineEntity.java b/src/main/java/crazypants/enderio/machine/AbstractMachineEntity.java index 12183d5f..35a0c918 100644 --- a/src/main/java/crazypants/enderio/machine/AbstractMachineEntity.java +++ b/src/main/java/crazypants/enderio/machine/AbstractMachineEntity.java @@ -428,7 +428,7 @@ public abstract class AbstractMachineEntity extends TileEntityEio implements ISi @Override public void readCustomNBT(NBTTagCompound nbtRoot) { - facing = nbtRoot.getShort("facing"); + setFacing(nbtRoot.getShort("facing")); redstoneCheckPassed = nbtRoot.getBoolean("redstoneCheckPassed"); forceClientUpdate = nbtRoot.getBoolean("forceClientUpdate"); readCommon(nbtRoot); diff --git a/src/main/java/crazypants/enderio/machine/killera/TileKillerJoe.java b/src/main/java/crazypants/enderio/machine/killera/TileKillerJoe.java index 68b384e1..a514872d 100644 --- a/src/main/java/crazypants/enderio/machine/killera/TileKillerJoe.java +++ b/src/main/java/crazypants/enderio/machine/killera/TileKillerJoe.java @@ -6,11 +6,13 @@ import net.minecraft.command.IEntitySelector; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityXPOrb; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.Vec3; import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.ForgeDirection; @@ -46,6 +48,8 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle protected AxisAlignedBB killBounds; + private int[] frontFaceAndSides; + protected AxisAlignedBB hooverBounds; protected FakePlayer attackera; @@ -164,7 +168,9 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle if(!entsInBounds.isEmpty()) { for (EntityLivingBase ent : entsInBounds) { - if(!ent.isDead) { + if(!ent.isDead && !ent.isEntityInvulnerable()) { + if (ent instanceof EntityPlayer && ((EntityPlayer)ent).capabilities.disableDamage) continue; //Ignore players in creative, can't damage them; + if (Config.killerJoeMustSee && !canJoeSee(ent)) continue; FakePlayer fakee = getAttackera(); fakee.setCurrentItemOrArmor(0, getStackInSlot(0)); fakee.attackTargetEntityWithCurrentItem(ent); @@ -180,6 +186,25 @@ public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandle return false; } + private boolean canJoeSee(EntityLivingBase ent) + { + Vec3 entPos = Vec3.createVectorHelper(ent.posX, ent.posY + (double)ent.getEyeHeight(), ent.posZ); + for (int facing:frontFaceAndSides) + { + if (this.worldObj.rayTraceBlocks(Vec3.createVectorHelper(this.xCoord + faceMidPoints[facing][0], this.yCoord + +faceMidPoints[facing][1], this.zCoord + +faceMidPoints[facing][2]), entPos) == null) return true; + } + return false; + } + + @Override + public void setFacing(short facing) + { + super.setFacing(facing); + frontFaceAndSides = new int[]{this.facing,ForgeDirection.ROTATION_MATRIX[0][this.facing],ForgeDirection.ROTATION_MATRIX[1][this.facing]}; + } + + private static double[][] faceMidPoints = new double[][]{{0.5D,0.0D,0.5D},{0.5D,1.0D,0.5D},{0.5D,0.5D,0.0D},{0.5D,0.5D,1.0D},{0.0D,0.5D,0.5D},{1.0D,0.5D,0.5D}}; + //------------------------------- XP public ExperienceContainer getXpContainer() {