public static float ApplyArmor(EntityLivingBase entity, ItemStack[] inventory, DamageSource source, double damage)
{
if (DEBUG)
{
System.out.println("Start: " + damage + " " + (damage * 25));
}
damage *= 25;
ArrayList<ArmorProperties> dmgVals = new ArrayList<ArmorProperties>();
for (int x = 0; x < inventory.length; x++)
{
ItemStack stack = inventory[x];
if (stack == null)
{
continue;
}
ArmorProperties prop = null;
if (stack.getItem() instanceof ISpecialArmor)
{
ISpecialArmor armor = (ISpecialArmor)stack.getItem();
prop = armor.getProperties(entity, stack, source, damage / 25D, x).copy();
}
else if (stack.getItem() instanceof ItemArmor && !source.isUnblockable())
{
ItemArmor armor = (ItemArmor)stack.getItem();
prop = new ArmorProperties(0, armor.damageReduceAmount / 25D, armor.getMaxDamage() + 1 - stack.getItemDamage());
}
if (prop != null)
{
prop.Slot = x;
dmgVals.add(prop);
}
}
if (dmgVals.size() > 0)
{
ArmorProperties[] props = dmgVals.toArray(new ArmorProperties[dmgVals.size()]);
StandardizeList(props, damage);
int level = props[0].Priority;
double ratio = 0;
for (ArmorProperties prop : props)
{
if (level != prop.Priority)
{
damage -= (damage * ratio);
ratio = 0;
level = prop.Priority;
}
ratio += prop.AbsorbRatio;
double absorb = damage * prop.AbsorbRatio;
if (absorb > 0)
{
ItemStack stack = inventory[prop.Slot];
int itemDamage = (int)(absorb / 25D < 1 ? 1 : absorb / 25D);
if (stack.getItem() instanceof ISpecialArmor)
{
((ISpecialArmor)stack.getItem()).damageArmor(entity, stack, source, itemDamage, prop.Slot);
}
else
{
if (DEBUG)
{
System.out.println("Item: " + stack.toString() + " Absorbed: " + (absorb / 25D) + " Damaged: " + itemDamage);
}
stack.damageItem(itemDamage, entity);
}
if (stack.stackSize <= 0)
{
/*if (entity instanceof EntityPlayer)
{
stack.onItemDestroyedByUse((EntityPlayer)entity);
}*/
inventory[prop.Slot] = null;
}
}
}
damage -= (damage * ratio);
}
if (DEBUG)
{
System.out.println("Return: " + (int)(damage / 25.0F) + " " + damage);
}
return (float)(damage / 25.0F);
}