#Item attack damage 1.21.X

7 messages · Page 1 of 1 (latest)

stone jacinth
#
double attackDmg = stack.getComponents()
                    .getOrDefault(DataComponentTypes.ATTRIBUTE_MODIFIERS, AttributeModifiersComponent.DEFAULT)
                    .modifiers().stream()
                    .filter(entry -> entry.attribute().matchesId(Item.BASE_ATTACK_DAMAGE_MODIFIER_ID))
                    .map(entry -> entry.modifier().value())
                    .findFirst()
                    .orElse(0.0); // idk, some other val

For the love of Mojank, is this really how we're supposed to access the damage a weapon/item deals as of 1.21.3?
It used to be as simple as swordItem.getMaterial().getAttackDamage() for example concernedtater

devout rock
stone jacinth
# devout rock Use EnchantmentHelper

EnchantmentHelper.getItemDamage()?

public static int getItemDamage(ServerWorld world, ItemStack stack, int baseItemDamage) {
        MutableFloat mutableFloat = new MutableFloat((float)baseItemDamage);
        forEachEnchantment(stack, (enchantment, level) -> enchantment.value().modifyItemDamage(world, level, stack, mutableFloat));
        return mutableFloat.intValue();
    }
#

I am not sure that would work, the item damage is set inside ATTRIBUTE_MODIFIERS afaik

stone jacinth
#

I'd need that alongside my previous code to get the total damage I think

devout rock