When using the following command in a command block that has an empty chest on top, it correctly adds a stack of iron ingots.
/data modify block ~ ~1 ~ Items append value {id:"iron_ingot",Count:64b}
ACTUAL
Executing it another time does nothing. The command still outputs "Modified block data of x, y, z".
I assume that's because items gain a default Slot
tag when added to a container, and that is always 1
, instead of being incremented to the next free slot.
⚠️ This is not a duplicate of MC-150999.
It's not intuitive that the command requires a Slot
tag for every other time. It also doesn't make sense, when using a command named append
, which in all other contexts adds an item to the end of a list, whatever it's current size. (same for prepend with the start of the list)
On top of that, Slot
isn't part of the normal Item NBT (e.g. item entities don't have a Slot). It's only a property of containers (or inventories) to give items a temporary and virtual Slot
tag When an item is removed from a container, it'll immediately lose the Slot
tag.
EXPECTED
It should add another stack of iron ingots to the chest (in the next free slot).
Linked issues
Comments 9
@violine1101 how do you know that Mojang planned it to be this way? The name append
implies that well.. the item gets appended, not that a Slot tag gets magically created with a value of 0
and thus sets the item in the first slot, instead of appending the provided item.
The container knows what items it contains, so it *does* know where to place the item.. in the next empty slot.
append
just means that the command will append an NBT object to an NBT list. That's it. It won't change the default values of the attributes inside of that object.
Anything claiming that default behaviour should be otherwise is a feature request.
But it doesn't "append" an NBT object. It replaces / sets an NBT object, at the first slot.
Have you spoken with the Java devs or why are you so sure that it's the intended behavior?
"insert" and "prepend" exist for a reason, but with the current behavior they are useless for containers, since you always need to manually prepare a static Slot value. (i.e. They all do the same with containers.)
@violine1101 I'd like to speak with your manager.
Okay, but seriously 😉, is there a chance we could get an official statement from a Mojang dev about whether this is by design?
You need
Slot
to specify what slot the item is in.Yes, it is part of the normal item NBT. Without it, the container doesn't know what slot to put it in.