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

Villager inventory data tag has inconsistent behavior

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • None
    • Minecraft 18w08b
    • None
    • Unconfirmed

      Modifying the inventory of a villager entity using either the /data command or /execute...store... shows inconsistent behavior overall. For instance, if you try to use /data remove entity to remove either Inventory[0] or just the entire Inventory tag of a villager, it will say the NBT was modified, but the tag will still be there intact with no changes. Even worse, if you try to use /execute...store... to change the Count of an item in the inventory, rather than replacing the Count as expected, it will simply add the original count to the new value and store that instead.

      *Example*

      I found this issue while working on a datapack, so I'll just copy the function that showed it to me here:

      setblock ~ ~0.2 ~ minecraft:nether_wart[age=0]
      tellraw @a ["Attempting to plant wart with previous value ",{"score":{"name":"@s","objective":"WartCount"}}]
      execute store result score @s WartCount run data get entity @s Inventory[0].Count
      tellraw @a ["Attempting to plant wart with old count ",{"score":{"name":"@s","objective":"WartCount"}}]
      scoreboard players remove @s WartCount 1
      tellraw @a ["Attempting to plant wart with new count ",{"score":{"name":"@s","objective":"WartCount"}}]
      data remove entity @s Inventory[0]
      execute as @s[scores={WartCount=1..}] run data merge entity @s {Inventory:[{id:"minecraft:nether_wart",Count:0b}]}
      execute as @s[scores={WartCount=1..}] store result entity @s Inventory[0].Count byte 1.0 run scoreboard players get @s WartCount
      execute store result score @s WartCount run data get entity @s Inventory[0].Count
      tellraw @a ["Attempting to plant wart with super new count ",{"score":{"name":"@s","objective":"WartCount"}}]
      tellraw @a ["----------"]
      

      After just modifying the Count didn't work, I tried adding the /data remove line, which also didn't work for the reasons stated above. If you have a villager who has 2 Nether Wart in its inventory (via commands), when you run this on him, the "old count" will be 2, the "new count" will be 1, but the "super new count" will be 3. Run it again, and it'll output 3, 2, 5. Then 5, 4, 9. Etc. Every time, the tag is not removed, and the count is added instead of replaced.

            Unassigned Unassigned
            IceMetalPunk Daniel Burnett
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: