Accessories

Accessories

4M Downloads

Bug: [1.21.4] Adding attribute modifiers in getDynamicModifiers allows accessories to be equipped in any slot

ThatPreston opened this issue · 3 comments

commented

What Feature Types Apply to This Bug?

API

Feature Type

No response

What Type of Bug Is This?

Unexpected Behavior

Minecraft Version

1.21.4

Mod Loader

Fabric

Mod Loader API Version

Fabric loader: 0.16.7, Fabric API: 0.119.2+1.21.4

The Accessories Version

1.2.19-beta+1.21.4

What Compatibility layer are you using?

None

The Compatibility Version

No response

Is This Bug a Conflict With Another Mod?

No response

Client Log

No response

Crash Report (if applicable)

No response

Steps to Reproduce

My mod's item is a necklace, so to let it be worn in the necklace slot, I added this file:

data/accessories/tags/item/necklace.json

{
  "replace": false,
  "values": [
    "mermod:sea_necklace"
  ]
}

To register the accessory, I use this code:

        AccessoryRegistry.register(RegistryHandler.SEA_NECKLACE.get(), new Accessory() {
            @Override
            public void getDynamicModifiers(ItemStack stack, SlotReference reference, AccessoryAttributeBuilder builder) {
                Accessory.super.getDynamicModifiers(stack, reference, builder);
                builder.addExclusive(Attributes.SUBMERGED_MINING_SPEED, new AttributeModifier(ResourceLocation.fromNamespaceAndPath(Mermod.MOD_ID, "submerged_mining_speed_modifier"), 4, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));
            }
        });

What You Expect To Happen

I expect that I should be able register the accessory and add attribute modifiers without affecting which slot the necklace can be equipped in.

What Actually Happened

For some reason, any use of builder.addExclusive allows the necklace to be equipped in any slot instead of just the necklace slot. Commenting out that single line makes everything work fine.

Additional Details

If I'm using getDynamicModifiers wrong please let me know. The attribute modifier itself seems to work fine, it just interferes with which slots the necklace can be equipped in. This is also reflected in the tooltip. With the attribute modifier, it says "Slot: Any," and without it, it says "Slot: Necklace" like it should.

Please Read and Confirm The Following

  • I have confirmed this bug is on the most recently supported version of Minecraft.
  • I have confirmed the details provided in this report are concise as possible and does not contain vague information (ie. Versions are properly recorded, answers to questions are clear).
  • I have confirmed this bug is unique and has not been reported already.
  • If playing on a modpack, I have reported this bug to their issue tracker already.
commented

Such a fix has been pushed for 1.21.5 and up, requiring that the person adding the attributes sets that such should allow equip checks on it.

commented

As yes, so there is a validator called accessories:attribute which uses the attributes desired slot target as a way to indicate what slots a given item may work in, and was added as a default validator in 1.21.4 since I did not see much harm in such. I did not think of this as an issue since you could check what slot you want attributes to work on, but I now see that could be an issue if you were already managing it via another validator...

I believe I have a fix for 1.21.5 and up with a better way of indicating the use case of the validator.

commented

After more testing I realized this was happening because I was ignoring the SlotReference param. If I check if the slot name is "necklace" before adding the modifier, it fixes the issue. Is this intentional? I would never have expected attribute modifiers to also control what slots an accessory can be equipped in; I thought that was controlled by tags. Either way I think more documentation would be nice for this.