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

set_attributes item modifier can add the same attribute modifier twice

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 1.21 Pre-Release 1
    • 24w21b
    • None
    • Community Consensus
    • Commands
    • Important
    • Platform

      Summary
      set_attributes item modifier can add two attribute modifiers for the same attribute with the same ID to an item stack. Although an item stack with two equal modifiers can be created using other means, the item modifier previously did not add two modifiers with the same UUID twice, and this bug is likely due to a coding error.

      Steps to Reproduce

      1. Add the attached data pack.
      2. Get a carved pumpkin.
      3. Run the following command:
        /item modify entity @s hotbar.0 test:cursed_attribute
        
      4. Check the tooltip of the item in the inventory.

      Expected Result
      Only "+2 Armor" is displayed.

      Actual Result
      "+1 Armor" and "+2 Armor" are both displayed.

      Code analysis
      In AttributeModifiersComponent.Entry, an Identifier is compared against EntityAttributeModifier, which always returns false. This makes the check inside AttributeModifiersComponent#with, which should skip duplicate additions, useless.

        1. image-2024-05-24-13-09-27-990.png
          35 kB
          apple502j
        2. image-2024-05-24-13-09-48-822.png
          18 kB
          apple502j
        3. image-2024-05-24-13-10-20-564.png
          18 kB
          apple502j
        4. image-2024-05-25-14-29-34-871.png
          1.60 MB
          BugTracker
        5. Minecraft 24w21b - Singleplayer 2024-05-24 12-58-10.mp4
          4.60 MB
          apple502j

            gegy1000 [Mojang] Gegy
            apple502j apple502j
            Votes:
            3 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: