#Creating an item that buffs mainhand damage

6 messages · Page 1 of 1 (latest)

timid bough
#

I've made a weapon that buffs your damage when held in offhand, using the getAttributeModifiers method, but it isn't constant, and is overriden if an item is present in the mainhand. my code is:

 private final Multimap<EntityAttribute, EntityAttributeModifier> attributeModifiers;

    public KnifeItem(Settings settings) {
        super(settings);
        ImmutableMultimap.Builder<EntityAttribute, EntityAttributeModifier> builder = ImmutableMultimap.builder();
        builder.put(
                EntityAttributes.GENERIC_ATTACK_DAMAGE,
                new EntityAttributeModifier(ATTACK_DAMAGE_MODIFIER_ID, "Tool modifier", 90.0, EntityAttributeModifier.Operation.ADDITION)
        );
        this.attributeModifiers = builder.build();
    }


    public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) {
        return slot == EquipmentSlot.OFFHAND ? this.attributeModifiers : super.getAttributeModifiers(slot);
    } ```
#

I'd also like to get it when the mainhand does a fully charged attack(not spamming), but that comes after solving this

#

I was thinking of using mixin to make it check if the attack-buffing item is present in the offhand too, but im not too sure how to go about that

worn raft
#

use a different modifier ID

timid bough
#

also, I'd still like to figure out how to made the attribute do something, and I'd like it so I could make it run my own code whenever a player attacks with their mainhand (the item is held in offhand), depending on the custom item item in the offhand