From 4b364a93db53720e20b244e09be9026b7ef8fdad Mon Sep 17 00:00:00 2001 From: FourIsTheNumber <33456283+FourIsTheNumber@users.noreply.github.com> Date: Wed, 1 Jul 2026 18:27:50 -0400 Subject: [PATCH] Use extended interface (#125) --- .../api/apiculture/IArmorApiarist.java | 13 ------------ .../api/apiculture/IArmorApiaristMulti.java | 20 +++++++++++++++++++ .../apiculture/ArmorApiaristHelper.java | 6 +++++- 3 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 src/main/java/forestry/api/apiculture/IArmorApiaristMulti.java diff --git a/src/main/java/forestry/api/apiculture/IArmorApiarist.java b/src/main/java/forestry/api/apiculture/IArmorApiarist.java index 5957b49b0..f1775e80e 100644 --- a/src/main/java/forestry/api/apiculture/IArmorApiarist.java +++ b/src/main/java/forestry/api/apiculture/IArmorApiarist.java @@ -25,19 +25,6 @@ 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/api/apiculture/IArmorApiaristMulti.java b/src/main/java/forestry/api/apiculture/IArmorApiaristMulti.java new file mode 100644 index 000000000..965ee4cb8 --- /dev/null +++ b/src/main/java/forestry/api/apiculture/IArmorApiaristMulti.java @@ -0,0 +1,20 @@ +package forestry.api.apiculture; + +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.item.ItemStack; + +public interface IArmorApiaristMulti extends IArmorApiarist { + + /** + * 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; + } +} diff --git a/src/main/java/forestry/apiculture/ArmorApiaristHelper.java b/src/main/java/forestry/apiculture/ArmorApiaristHelper.java index affa80f78..ecbe5ae65 100644 --- a/src/main/java/forestry/apiculture/ArmorApiaristHelper.java +++ b/src/main/java/forestry/apiculture/ArmorApiaristHelper.java @@ -10,10 +10,12 @@ 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; import forestry.api.apiculture.IArmorApiaristHelper; +import forestry.api.apiculture.IArmorApiaristMulti; public class ArmorApiaristHelper implements IArmorApiaristHelper { @@ -40,7 +42,9 @@ public class ArmorApiaristHelper implements IArmorApiaristHelper { for (int i = 1; i <= 4; i++) { ItemStack armorItem = entity.getEquipmentInSlot(i); if (isArmorApiarist(armorItem, entity, cause, doProtect)) { - count += ((IArmorApiarist) armorItem.getItem()).getProtectionCount(entity, armorItem, cause); + Item item = armorItem.getItem(); + if (item instanceof IArmorApiaristMulti am) count += am.getProtectionCount(entity, armorItem, cause); + else count++; } }