CraftTweaker

CraftTweaker

151M 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)