mojira.dev
MC-141876

/data modify with multiple values nbt remove an item on Slot:0b

How to reproduced (Video):
1. Place items inside the container (in this test I use water bottle)
2. run at least two /data modify command in the same tick

/data modify block <container> Items[{tag:{Potion:"minecraft:water"}}].tag set value {Value:"foo"}
/data modify block <container> Items[{tag:{Potion:"minecraft:water"}}].tag set value {Value:"bar"}

3. The item at Slot:0b will be removed even if the previous command returns nothing

What doesn't affect by this:
1. Items[index].tag work just fine
2. other commands such as /data get, etc.

Actual commands I use:

/data modify block ~-1 ~ ~ Items[{tag:{Potion:"minecraft:water"}}] set value {Value:"foo"}
/data modify block ~-1 ~-1 ~ Items[{tag:{Potion:"minecraft:water"}}] set value {Value:"bar"}

Linked issues

Comments 3

The video has been removed, and you forgot  .tag  in the third and fourth commands.

The commands don't need to run in the same tick.

 

The first command removes the Potion tag, so the second command finds no entry to modify.

Therefore, it creates a new entry at the end of the list.

At first, its value is {tag:{Potion:"minecraft:water"}}

Then, it is set to {tag:{Value:"bar"}}

The added entry does not contain Slot, so its value defaults to 0.

It overwrites the other item with Slot:0b because the new entry is at the end of the list and therefore loaded after.

The new item is missing id and Count, so it is removed.

The missing tag in the 3rd and 4th command is probably just my mistake when copying it over but ignoring that, your explanation is not correct.

The Slot NBT is not stored inside the {tag: {... }} field so it cannot be removed even if the field was set by the /data  command and in those commands, nothing is being created, it simply modifies the NBT value that already exists in the container that it can find with the given predicate.

Though it has been far too long for me to remember what this bug report was about so if no one else has reported the same issue, it should be fine to close it.

data modify does create a new matching list element if it can't find one with the given predicate.

You can test it in storage instead of a container, or modify the predicate to contain a valid id and Count, which will create a new item.

Boomber

(Unassigned)

Confirmed

Commands

Minecraft 18w50a, Minecraft 19w12b, Minecraft 19w13b, Minecraft 19w14a, Minecraft 19w14b, ..., Minecraft 1.14.2 Pre-Release 3, 1.15.2, 20w08a, 1.20.4, 1.20.5 Release Candidate 2

Retrieved