CraftTweaker

CraftTweaker

186M Downloads

1.21.1 Bug: ItemDefinition::addAttributeModifier replaces all existing modifiers instead of adding.

Silvertide7 opened this issue ยท 2 comments

commented

Issue description

I am trying to add a modifier to an existing item, say a netherite chestplate. Here is the data on that before any modification:
Image

I am using this method:

function applyModifier(itemDef as ItemDefinition, attribute as Attribute, value as double, operation as AttributeOperation, slot as EquipmentSlotGroup) as void {
    val modifier = AttributeModifier.create(<resource:reverie:modification>, value, operation);
    itemDef.addAttributeModifier(attribute, modifier, slot);
}

applyModifier(<item:minecraft:netherite_chestplate>, <attribute:minecraft:generic.armor>, 2.0, <constant:minecraft:attribute/operation:add_value>, <constant:minecraft:equipmentslot/group:chest>);

I am adding this modifier under the reverie:modification resource path to ideally add a new attribute.
Here is the item after the modification:

Image

It completely removes ALL other attributes, not just the armor, and replaces it with my new armor modification. I do realize I added it to the head equipment slot instead of chest in this picture, but I tried it again right after with chest and it did the same thing.
I would assume that all old attributes, including the old armor attribute, would still be applied to the item, and my new armor attribute modification would be added on, resulting in 10.0 total armor.

It would be nice however to be able to overwrite the existing modifications as well. Say if I had used the namespace minecraft:armor.chestplate as my resource key for my modifier it would replace the existing one there.

Steps to reproduce

No response

Script used

Method pasted above, the script works fine.

The crafttweaker.log file

No log errors exist.

Minecraft version

1.21.1

Modloader

NeoForge

Modloader version

21.1.145

CraftTweaker version

21.0.24

Other relevant information

No response

The latest.log file

Logs show no errors.

commented

Mojang is doing some stupid stuff with how they deal with attributes on Armor items, your script actually works perfectly fine when used on any other item, like an Iron Axe for example.

I've pushed a new version that should fix this

It would be nice however to be able to overwrite the existing modifications as well. Say if I had used the namespace minecraft:armor.chestplate as my resource key for my modifier it would replace the existing one there.

That should already be a thing, just replace <resource:reverie:modification> with <resource:minecraft:armor.chestplate> and it should override the value.

commented

Hey so I just tried this same script with the updated version of craft tweaker (21.0.26) and it had the same outcome, overwrote all of my armors attributes and added just the new one.