@@ -0,0 +1,3828 @@
+package net.darkhax.bookshelf.api.util;%0A%0Aimport net.minecraft.world.entity.EquipmentSlot;%0Aimport net.minecraft.world.entity.ai.attributes.Attribute;%0Aimport net.minecraft.world.entity.ai.attributes.AttributeModifier;%0Aimport net.minecraft.world.entity.ai.attributes.Attributes;%0Aimport net.minecraft.world.item.ItemStack;%0A%0Aimport java.util.Collection;%0A%0A/**%0A * This class contains static helper functions for working with entity attributes and calculating attribute values.%0A */%0Apublic final class AttributeHelper %7B%0A%0A    /**%0A     * Calculates the attack damage attribute value for a given ItemStack.%0A     *%0A     * @param stack The ItemStack to calculate values for.%0A     * @return The attack damage value for the ItemStack.%0A     */%0A    public static double getAttackDamage(ItemStack stack) %7B%0A%0A        return calculateValue(stack, Attributes.ATTACK_DAMAGE, EquipmentSlot.MAINHAND);%0A    %7D%0A%0A    /**%0A     * Calculates the attack speed attribute value for a given ItemStack.%0A     *%0A     * @param stack The ItemStack to calculate values for.%0A     * @return The attack speed value for the ItemStack.%0A     */%0A    public static double getAttackSpeed(ItemStack stack) %7B%0A%0A        return calculateValue(stack, Attributes.ATTACK_SPEED, EquipmentSlot.MAINHAND);%0A    %7D%0A%0A    /**%0A     * Calculates the attack knockback attribute value for a given ItemStack.%0A     *%0A     * @param stack The ItemStack to calculate values for.%0A     * @return The attack knockback value for the ItemStack.%0A     */%0A    public static double getAttackKnockback(ItemStack stack) %7B%0A%0A        return calculateValue(stack, Attributes.ATTACK_KNOCKBACK, EquipmentSlot.MAINHAND);%0A    %7D%0A%0A    /**%0A     * Calculates an attribute value for an ItemStack when used in a given slot.%0A     *%0A     * @param stack     The ItemStack to calculate values for.%0A     * @param attribute The attribute to calculate.%0A     * @param slot      The equipment slot to calculate for.%0A     * @return The calculated attribute value.%0A     */%0A    public static double calculateValue(ItemStack stack, Attribute attribute, EquipmentSlot slot) %7B%0A%0A        return calculateValue(attribute, stack.getAttributeModifiers(slot).get(attribute));%0A    %7D%0A%0A    /**%0A     * Calculates an attribute value using a collection of attribute modifiers.%0A     *%0A     * @param attribute The attribute to calculate a value for.%0A     * @param modifiers A collection of modifiers to process.%0A     * @return The calculated attribute value.%0A     */%0A    public static double calculateValue(Attribute attribute, Collection%3CAttributeModifier%3E modifiers) %7B%0A%0A        return attribute.sanitizeValue(calculateValue(modifiers, attribute.getDefaultValue()));%0A    %7D%0A%0A    /**%0A     * Calculates an attribute value using a collection of attribute modifiers.%0A     *%0A     * @param modifiers A collection of modifiers to process.%0A     * @param baseValue The base value to use for the calculation.%0A     * @return The calculated attribute value.%0A     */%0A    public static double calculateValue(Collection%3CAttributeModifier%3E modifiers, double baseValue) %7B%0A%0A        double baseTotal = baseValue;%0A%0A        for (AttributeModifier modifier : modifiers) %7B%0A%0A            if (modifier.getOperation() == AttributeModifier.Operation.ADDITION) %7B%0A%0A                baseTotal += modifier.getAmount();%0A            %7D%0A        %7D%0A%0A        double modifiedValue = baseTotal;%0A%0A        for (AttributeModifier modifier : modifiers) %7B%0A%0A            if (modifier.getOperation() == AttributeModifier.Operation.MULTIPLY_BASE) %7B%0A%0A                modifiedValue += baseTotal * modifier.getAmount();%0A            %7D%0A        %7D%0A%0A        for (AttributeModifier modifier : modifiers) %7B%0A%0A            if (modifier.getOperation() == AttributeModifier.Operation.MULTIPLY_TOTAL) %7B%0A%0A                modifiedValue *= 1 + modifier.getAmount();%0A            %7D%0A        %7D%0A%0A        return modifiedValue;%0A    %7D%0A%7D%0A

Add helper for working with entity attributes.