diff --git a/api/forestry b/api/forestry index 22a2117ad..0aab3badc 160000 --- a/api/forestry +++ b/api/forestry @@ -1 +1 @@ -Subproject commit 22a2117adf9dfb8ef4af665ce79d42503c3fa4f4 +Subproject commit 0aab3badcc3d8c4648fcf245c25fc557fa53f0f7 diff --git a/src/main/java/forestry/apiculture/ArmorApiaristHelper.java b/src/main/java/forestry/apiculture/ArmorApiaristHelper.java index 0a83f1cbf..6b4fd448e 100644 --- a/src/main/java/forestry/apiculture/ArmorApiaristHelper.java +++ b/src/main/java/forestry/apiculture/ArmorApiaristHelper.java @@ -10,6 +10,7 @@ ******************************************************************************/ package forestry.apiculture; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -20,7 +21,7 @@ import forestry.api.apiculture.IArmorApiaristHelper; public class ArmorApiaristHelper implements IArmorApiaristHelper { @Override - public boolean isArmorApiarist(ItemStack stack, EntityPlayer player, String cause, boolean doProtect) { + public boolean isArmorApiarist(ItemStack stack, EntityLivingBase entity, String cause, boolean doProtect) { if (stack == null) { return false; } @@ -31,19 +32,38 @@ public class ArmorApiaristHelper implements IArmorApiaristHelper { } IArmorApiarist armorApiarist = (IArmorApiarist) item; - return armorApiarist.protectPlayer(player, stack, cause, doProtect); + try { + return armorApiarist.protectEntity(entity, stack, cause, doProtect); + } catch (Throwable ignored) { // protectEntity is new to the API and may not be implemented by the armor + if (entity instanceof EntityPlayer) { + return armorApiarist.protectPlayer((EntityPlayer) entity, stack, cause, doProtect); + } else { + return true; // fallback on assuming IArmorApiarist will protect the entity + } + } } @Override - public int wearsItems(EntityPlayer player, String cause, boolean doProtect) { + public int wearsItems(EntityLivingBase entity, String cause, boolean doProtect) { int count = 0; - for (ItemStack armorItem : player.inventory.armorInventory) { - if (isArmorApiarist(armorItem, player, cause, doProtect)) { + for (int i = 1; i <= 4; i++) { + ItemStack armorItem = entity.getEquipmentInSlot(i); + if (isArmorApiarist(armorItem, entity, cause, doProtect)) { count++; } } return count; } + + @Override + public boolean isArmorApiarist(ItemStack stack, EntityPlayer player, String cause, boolean doProtect) { + return isArmorApiarist(stack, (EntityLivingBase) player, cause, doProtect); + } + + @Override + public int wearsItems(EntityPlayer player, String cause, boolean doProtect) { + return wearsItems((EntityLivingBase) player, cause, doProtect); + } } diff --git a/src/main/java/forestry/apiculture/items/ItemArmorApiarist.java b/src/main/java/forestry/apiculture/items/ItemArmorApiarist.java index eaf97bb3c..bc2d202d1 100755 --- a/src/main/java/forestry/apiculture/items/ItemArmorApiarist.java +++ b/src/main/java/forestry/apiculture/items/ItemArmorApiarist.java @@ -12,6 +12,7 @@ package forestry.apiculture.items; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemStack; @@ -72,6 +73,11 @@ public class ItemArmorApiarist extends ItemArmor implements IArmorApiarist, IArm return false; } + @Override + public boolean protectEntity(EntityLivingBase entity, ItemStack armor, String cause, boolean doProtect) { + return true; + } + @Override public boolean protectPlayer(EntityPlayer player, ItemStack armor, String cause, boolean doProtect) { return true;