There are two different ways that item attribute modifiers can display:
1. "Direct": where the final value of the attribute appears in green. This is used for vanilla tools to make them more intuitive.
[media]2. "Relative": where the value displays in blue, as a modifier with plus or minus. This is used for items where the additive nature of the attribute makes sense, like for armor.
[media]What determines which gets displayed? The modifier's UUID!
The game checks for the "base attribute" UUIDs, namely these ones:
CB3F55D3-645C-4F38-A497-9C13A33DB5CF
FA233E1C-4180-4865-B01B-BCCE9785ACA3
Therefore, it's expected that if you make a modifier that uses these UUIDs, your tooltip will display in green as a "final" attribute, not in blue as a relative one.
However, this does not work. This means there's no way to achieve an attribute display that's intuitive for weapons, besides recreating the tooltip with lore.
How to reproduce
/give @p diamond_sword{AttributeModifiers:[{Slot:mainhand,AttributeName:"generic.attack_damage",Operation:0,Amount:50d,UUID:[I;-885041709,1683771192,-1533567981,-1556236849]}]}
Expected result
Sword tooltip should show "51 Attack Damage" in green
Actual result
Sword tooltip shows "+50 Attack Damage" in blue
Code analysis
I'm pretty sure this is caused by a typo.
In ItemStack.getTooltipLines
, the line determining the attribute style is this:
if (attributeModifier.getId() == Item.BASE_ATTACK_DAMAGE_UUID) {
This doesn't actually compare the values of the two UUIDs, it checks for reference equality, meaning only attributes that use that exact static field in their constructor pass the check. If this is replaced with .equals
, it works properly for custom attributes that utilize this UUID.
Attachments
Comments 5
Perhaps a rework of when this deplays the "final" format should be done (eg just a separate field in the attribute modifier (finalDisplay:true/false or something) rather than making it based on the UUID, that'll also make someone able to use it on armor without being limited to 2 properly functioning pieces.
With the move from UUIDs to identifiers, this is possible now!
/give @p apple[attribute_modifiers=[{type:"generic.scale",operation:"add_value",amount:0.5d,id:"base_attack_damage"}]]
Can confirm this happens with components on 1.20.6. Reproducible with the following command:
/give @p minecraft:netherite_sword[minecraft:attribute_modifiers={modifiers:[{name: "Weapon modifier", amount: 8.0d, slot: "mainhand", type: "minecraft:generic.attack_damage", uuid: [I; -885041709, 1683771192, -1533567981, -1556236849], operation: "add_value"}]}]
Can confirm in 1.19 pre-2.