Search in sources :

Example 1 with EnchantmentProtection

use of net.minecraft.enchantment.EnchantmentProtection in project BloodMagic by WayofTime.

the class SpellHelper method applySpecialProtection.

public static float applySpecialProtection(EntityLivingBase entity, DamageSource source, float damage) {
    ItemStack[] armour = entity.getLastActiveItems();
    if (armour == null) {
        return damage;
    }
    int total = 0;
    for (int i = 0; i < armour.length; i++) {
        ItemStack stack = armour[i];
        if (stack != null) {
            NBTTagList nbttaglist = stack.getEnchantmentTagList();
            if (nbttaglist != null) {
                for (int j = 0; j < nbttaglist.tagCount(); ++j) {
                    short short1 = nbttaglist.getCompoundTagAt(i).getShort("id");
                    short short2 = nbttaglist.getCompoundTagAt(i).getShort("lvl");
                    if (Enchantment.enchantmentsList[short1] != null) {
                        Enchantment ench = Enchantment.enchantmentsList[short1];
                        if (ench instanceof EnchantmentProtection) {
                            total += ench.calcModifierDamage(short2, source);
                        }
                    }
                }
            }
        }
    }
    if (total > 0) {
        total = (total + 1 >> +1) + rand.nextInt(total + 1 >> +1);
        if (total <= 20) {
            return damage * (25 - total) / 25;
        } else {
            float factor = (float) (0.8 + 0.2 * (1 - Math.pow(protCoeff, Math.pow((total - 20), scalCoeff))));
            return damage * (1 - factor);
        }
    }
    return damage;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ItemStack(net.minecraft.item.ItemStack) Enchantment(net.minecraft.enchantment.Enchantment) EnchantmentProtection(net.minecraft.enchantment.EnchantmentProtection)

Aggregations

Enchantment (net.minecraft.enchantment.Enchantment)1 EnchantmentProtection (net.minecraft.enchantment.EnchantmentProtection)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagList (net.minecraft.nbt.NBTTagList)1