CraftTweaker

CraftTweaker

177M Downloads

Issues with Global Attribute Modifiers

averagemodenjoyer opened this issue ยท 4 comments

commented

Issue description

Using global attribute modifiers to edit the attributes of a weapon/armor causes the stats in the tooltip to be displayed in a random order. For example a weapon would display Attack Speed over Attack Damage. The order seems to be different on restarting the game, but unaffected by /reload.
2024-11-01_20 07 51
2024-11-01_20 07 58
(Diamond Sword with script, Iron Sword without script)
Removing the innate attributes of a weapon and replacing them with new ones seems to mess up the order of stats displayed on every weapon/tool/armor. Similarly it's unaffected by /reload and any changes made to the code require a full restart to take effect
2024-11-01_20 25 08
2024-11-01_20 25 10
2024-11-01_20 25 12
2024-11-01_20 25 13
2024-11-01_20 27 33
(Weapons, tools and even armor of all kinds being affected by a script that should only modify the Diamond Sword)
Basically Crafttweaker doesn't sort these attributes, instead they're sorted randomly. A feature that sorts them automatically (in the vanilla order) or allows users to sort them manually should fix this issue.

Steps to reproduce

  1. Create a .zs file using the script provided below
  2. Load into a world
  3. Check the tooltips of weapons, tools and armor

Script used

https://gist.github.com/averagemodenjoyer/8d1f052b568198e444a58711ace20a53#file-gistfile1-txt

The crafttweaker.log file

https://gist.github.com/averagemodenjoyer/197e56e83fe705fb706a00874c1dd1e8#file-gistfile1-txt

Minecraft version

1.20.1

Modloader

Forge

Modloader version

47.3.0

CraftTweaker version

14.0.43

Other relevant information

No response

The latest.log file

https://gist.github.com/averagemodenjoyer/75d274fef2cdc038e2644f0d1d6eb611#file-gistfile1-txt

commented

You shouldn't have to remove the default attributes to apply your own, doing this:

import crafttweaker.api.item.IItemStack;
import crafttweaker.api.entity.attribute.AttributeOperation;

<item:minecraft:diamond_sword>.addGlobalAttributeModifier(<attribute:minecraft:generic.attack_damage>, IItemStack.BASE_ATTACK_DAMAGE_UUID, "Extra Power", 6, AttributeOperation.ADDITION, [<constant:minecraft:equipmentslot:mainhand>]);
<item:minecraft:diamond_sword>.addGlobalAttributeModifier(<attribute:minecraft:generic.attack_speed>, IItemStack.BASE_ATTACK_SPEED_UUID, "Extra Speed", -2.4, AttributeOperation.ADDITION, [<constant:minecraft:equipmentslot:mainhand>]);

Should do what you want to achieve, can you test if this keeps the order of the attributes please.

commented

I did this exact script before trying to remove the default attributes. However the order of attributes on the affected item is incorrect (other items are unaffected)

commented

I'm unable to reproduce this, using the script you provided here https://gist.github.com/averagemodenjoyer/8d1f052b568198e444a58711ace20a53#file-gistfile1-txt

Each time I reload the game, the order that the attributes are applied stays the same, in this case it is always Attack Speed and then Attack Damage, like in your screenshots.
Attributes on other items are not affected by the script at all.

As for the order of the attributes, unfortunately I am unable to change the order of them.

The game uses a HashMultimap to store attributes it reads from NBT(which CraftTweaker hooks into), which does not store entries in insertion order, or any order that can be changed.

The reason that the rest of the items have the correct order of Attack Damage then Attack Speed is because items with default attributes use a different, order preserving map.

So unfortunately there is nothing I can do to solve either of your issues.

Try with just CraftTweaker and see if you can reproduce the randomized ordering of the attributes on the diamond sword, I have a feeling it is another mod that is messing with the attributes on the other items.

commented

Well that's a bummer. But I found an even bigger problem with Global Attribute Modifiers: #1778