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

/data modify copies source nbt to destination nbt as reference

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Minecraft 18w49a
    • Minecraft 18w45a, Minecraft 18w46a
    • None
    • Confirmed

      The bug

      /data modify and /execute store seem to copy NBT by reference. For most NBT this has no effect, but for NBT in the tag tag of items, it results in a link between the two, where later modifying one affects the other (other examples in MC-114104).

      How to reproduce

      Get an item with NBT, summon a mob, and data modify your item into its hand:

      /replaceitem entity @p weapon.mainhand diamond_sword{Damage:5}
      /summon husk
      /data modify entity @e[type=husk,sort=nearest,limit=1] HandItems[0] set from entity @p SelectedItem
      /enchant @p sharpness

      →  The husk's sword is enchanted as well.

       

      This link will persist until either the destination or source is reloaded for any reason.

      Additional test

      Attached is a datapack that uses a jukebox to store a list of data, and a command block used to compare two strings. Using a temporary list, the object that contains the matching string within the jukebox's RecordItem tag also contains an ID tag which is type int. After finding the correct object, the item's Item.tag.ID is set from here, then to show the bug the ID of the source is changed to 42 (from 6).

      Expected behavior: The item's ID tag is set to 6.

      Actual behavior: The item's ID tag is set to 42.

      To test, start a new world and go to 0,0 before loading the datapack. Then run /function lookup:test

            boq [Mojang] Bartosz Bok
            nigathan Scott
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: