mojira.dev
MC-138106

/data modify doesn't create a list item if it can't find any

The bug

When you use `/data modify` and it doesn't find the thing specified in the path, it creates that tag. However, if that path contains a list (that doesn't exist) with an index, it doesn't create the list.

How to reproduce

  1. Set a chest with an item

    /setblock ~1 ~ ~ minecraft:chest{Items:[{Slot:0b,Count:1b,id:"minecraft:dirt"}]}
    /setblock ~1 ~ ~ minecraft:chest{Items:[{Slot:0b,Count:1b,id:"minecraft:dirt"}]}
  2. Try to give the item lore by `set`ting `Lore[0]`, this fails because the `Lore` list doesn't exist

    /data modify block ~1 ~ ~ Items[0].tag.display.Lore[0] set value "\"hi\""
    /data modify block ~1 ~ ~ Items[0].tag.display.Lore[0] set value "\"hi\""

Comments 5

WAIsh. It is unclear, what would happen when you try to set `Items[1]` on non-existing list. Filling to default value would probably work, but it may be error-prone. And what about `Items[-2]`?

Note that this behavior existed before, since `execute store` worked same way.

Execute store also doesn’t create non-list tags if they don’t exist. 

But I understand that’s list creating upon non-existence can cause a lot of inconsistencies/problems/unintuivities

Yes, that's what I said: no changes in behavior. This makes it feature request.

`append` and others have pretty clear semantics. On the other hand, writing to non-existing slot does not have one.

Wait ignore my previous comment. I got confused with /execute storeing into a list rather than a non-list item (I misremebered the behavior I got in a testworld a few days ago). I agree on your statement that it’s WAI. It  probably creates more problems than that it solves. 

AlexMCool

boq

Confirmed

/data-modify

Minecraft 18w43c

Retrieved