Search in sources :

Example 1 with ArmorProperties

use of net.minecraftforge.common.ISpecialArmor.ArmorProperties in project BloodMagic by WayofTime.

the class Utils method applyArmor.

public static float applyArmor(EntityLivingBase entity, ItemStack[] inventory, DamageSource source, double damage) {
    damage *= 25;
    ArrayList<ArmorProperties> dmgVals = new ArrayList<>();
    for (int x = 0; x < inventory.length; x++) {
        ItemStack stack = inventory[x];
        if (stack.isEmpty()) {
            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, Integer.MAX_VALUE);
        }
        if (prop != null) {
            prop.Slot = x;
            dmgVals.add(prop);
        }
    }
    if (dmgVals.size() > 0) {
        ArmorProperties[] props = dmgVals.toArray(new ArmorProperties[dmgVals.size()]);
        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;
        }
        damage -= (damage * ratio);
    }
    return (float) (damage / 25.0F);
}
Also used : ArmorProperties(net.minecraftforge.common.ISpecialArmor.ArmorProperties) ItemArmor(net.minecraft.item.ItemArmor) ItemStack(net.minecraft.item.ItemStack) ISpecialArmor(net.minecraftforge.common.ISpecialArmor)

Aggregations

ItemArmor (net.minecraft.item.ItemArmor)1 ItemStack (net.minecraft.item.ItemStack)1 ISpecialArmor (net.minecraftforge.common.ISpecialArmor)1 ArmorProperties (net.minecraftforge.common.ISpecialArmor.ArmorProperties)1