Add support for Apiarist Armor on any EntityLivingBase

This commit is contained in:
mezz committed 2015-11-17 02:11:35 -08:00
1 parent 2f16ca5828
commit efd9cd06f6
3 files changed
+32 -6

No files matched your search

@@ -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);
}
}