diff --git a/src/main/java/forestry/api/apiculture/IArmorApiarist.java b/src/main/java/forestry/api/apiculture/IArmorApiarist.java index f1775e80e..5957b49b0 100644 --- a/src/main/java/forestry/api/apiculture/IArmorApiarist.java +++ b/src/main/java/forestry/api/apiculture/IArmorApiarist.java @@ -25,6 +25,19 @@ public interface IArmorApiarist { */ boolean protectEntity(EntityLivingBase entity, ItemStack armor, String cause, boolean doProtect); + /** + * Called to determine how many pieces an armor "counts for". For instance, if this returns 4, the single piece will + * act as full protection. + * + * @param entity Entity being attacked + * @param armor Armor item + * @param cause Optional cause of attack, such as a bee effect identifier + * @return Amount of effective protected slots + */ + default int getProtectionCount(EntityLivingBase entity, ItemStack armor, String cause) { + return 1; + } + /** * Called when the apiarist's armor acts as protection against an attack. * diff --git a/src/main/java/forestry/apiculture/ArmorApiaristHelper.java b/src/main/java/forestry/apiculture/ArmorApiaristHelper.java index ba3fca33a..affa80f78 100644 --- a/src/main/java/forestry/apiculture/ArmorApiaristHelper.java +++ b/src/main/java/forestry/apiculture/ArmorApiaristHelper.java @@ -10,7 +10,6 @@ package forestry.apiculture; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import forestry.api.apiculture.IArmorApiarist; @@ -20,21 +19,14 @@ public class ArmorApiaristHelper implements IArmorApiaristHelper { @Override public boolean isArmorApiarist(ItemStack stack, EntityLivingBase entity, String cause, boolean doProtect) { - if (stack == null) { - return false; - } - Item item = stack.getItem(); - if (!(item instanceof IArmorApiarist)) { - return false; - } + if (stack == null || !(stack.getItem() instanceof IArmorApiarist armor)) return false; - IArmorApiarist armorApiarist = (IArmorApiarist) item; try { - return armorApiarist.protectEntity(entity, stack, cause, doProtect); + return armor.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); + return armor.protectPlayer((EntityPlayer) entity, stack, cause, doProtect); } else { return true; // fallback on assuming IArmorApiarist will protect the entity } @@ -48,11 +40,11 @@ public class ArmorApiaristHelper implements IArmorApiaristHelper { for (int i = 1; i <= 4; i++) { ItemStack armorItem = entity.getEquipmentInSlot(i); if (isArmorApiarist(armorItem, entity, cause, doProtect)) { - count++; + count += ((IArmorApiarist) armorItem.getItem()).getProtectionCount(entity, armorItem, cause); } } - return count; + return Math.min(count, 4); } @Override