mojira.dev
MC-139625

In NBT paths, a list with an index cannot be followed by a compound

The bug

When specifying an NBT path you're unable to let a compound be followed by a list after specifying the index.

Examples

(1) /execute if data entity @s SelectedItem{id:"minecraft:stone"}
(2) /execute if data entity @s Inventory[0]{id:"minecraft:stone"}

(1) is allowed and tests whether the SelectedItem of the player is stone, (2) is not allowed but should test whether the first compound in the Inventory list has an id of minecraft:stone.

Linked issues

Comments 9

{...} part is not parsed on it's own, it only exist as part of key{...}. Allowing this syntax would complicate /data remove, so it does not seem worth the effort. If we add filtering on index+context, it will probably use different syntax.

NOTE: Of course there is exception to this rule: {...} can be used to match root, since there is no other syntax. This does not conflict, since you can't remove root anyway.

@ Bok, Does that mean the fact that `{}` doesn't work in `/data modify` is a bug?

Can you post example of that? Stuff like '/data modify block 28 56 158 {} merge from block 30 56 158 {Items:[{}]}' works without problems. But as I said, that's special case and only works on root. Also, you can't '/data modify {} set' or '/data remove ... {}'.

Ooh, I was using set, that explains why it didn't work. Nevermind me then!

This makes things like checking if a mob has a specific item in its offhand directly impossible. The only workaround I've found so far is copying the NBT somewhere else and then checking there. But that loses the reference to the entity.

It seems from your first comment, @unknown, that you plan to add such a behaviour in the future. Then why is this report closed as WAI?
A syntax like

HandItems[1]{id:"minecraft:stone"}

shouldn't collide with anything.

Allowing this syntax would complicate /data remove, so it does not seem worth the effort.

I read that, I replied to that comment, but how would that complicate anything?

Can you give an example command that would work now, but misbehave if that feature was added? I don't know which context your example was meant to be in.

AlexMCool

boq

Confirmed

Minecraft 18w46a, Minecraft 18w47a, Minecraft 18w47b

Retrieved