Search in sources :

Example 1 with ISpecialArmor

use of net.minecraftforge.common.ISpecialArmor in project SpongeForge by SpongePowered.

the class StaticMixinForgeHelper method getProperties.

private static ISpecialArmor.ArmorProperties getProperties(EntityLivingBase base, ItemStack armorStack, DamageSource damageSource, double damage, int index) {
    if (armorStack.isEmpty()) {
        return null;
    }
    ISpecialArmor.ArmorProperties prop = null;
    if (armorStack.getItem() instanceof ISpecialArmor) {
        ISpecialArmor armor = (ISpecialArmor) armorStack.getItem();
        prop = armor.getProperties(base, armorStack, damageSource, damage / 25D, index).copy();
    } else if (armorStack.getItem() instanceof ItemArmor && !damageSource.isUnblockable()) {
        ItemArmor armor = (ItemArmor) armorStack.getItem();
        prop = new ISpecialArmor.ArmorProperties(0, armor.damageReduceAmount / 25D, Integer.MAX_VALUE);
    }
    if (prop != null) {
        prop.Slot = index;
        return prop;
    }
    return null;
}
Also used : ItemArmor(net.minecraft.item.ItemArmor) ISpecialArmor(net.minecraftforge.common.ISpecialArmor)

Example 2 with ISpecialArmor

use of net.minecraftforge.common.ISpecialArmor in project SpongeForge by SpongePowered.

the class StaticMixinForgeHelper method acceptArmorModifier.

public static void acceptArmorModifier(EntityLivingBase entity, DamageSource damageSource, DamageModifier modifier, double damage) {
    Optional<ISpecialArmor.ArmorProperties> property = modifier.getCause().getContext().get(ARMOR_PROPERTY);
    final NonNullList<ItemStack> inventory = entity instanceof EntityPlayer ? ((EntityPlayer) entity).inventory.armorInventory : entity.armorArray;
    if (property.isPresent()) {
        ItemStack stack = inventory.get(property.get().Slot);
        damage = Math.abs(damage) * 25;
        int itemDamage = (int) (damage / 25D < 1 ? 1 : damage / 25D);
        if (stack.getItem() instanceof ISpecialArmor) {
            ((ISpecialArmor) stack.getItem()).damageArmor(entity, stack, damageSource, itemDamage, property.get().Slot);
        } else {
            stack.damageItem(itemDamage, entity);
        }
        if (stack.isEmpty()) {
            // Totally unsure whether this is right....
            inventory.set(property.get().Slot, ItemStack.EMPTY);
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ISpecialArmor(net.minecraftforge.common.ISpecialArmor)

Example 3 with ISpecialArmor

use of net.minecraftforge.common.ISpecialArmor 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

ISpecialArmor (net.minecraftforge.common.ISpecialArmor)3 ItemArmor (net.minecraft.item.ItemArmor)2 ItemStack (net.minecraft.item.ItemStack)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ArmorProperties (net.minecraftforge.common.ISpecialArmor.ArmorProperties)1