Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-251252

Custom attribute modifiers that use the vanilla UUIDs don't display in tooltip properly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.18.2, 1.19 Pre-release 2, 1.19.2, 22w42a, 1.20.4
    • None
    • Confirmed
    • UI
    • Normal
    • Platform

      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.

      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.

      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.

            Unassigned Unassigned
            tryashtar [Mod] tryashtar
            Votes:
            12 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              CHK: