mojira.dev
MC-130043

Unexpected error when giving '/data get' a negative index

The bug

When I use /data get with a path of an array with a negative index, it says An unexpected error occurred trying to execute that command. There isn't any further information in the logs.

How to reproduce

Type in that command for example:

/data get entity @s Inventory[-1]

Comments 5

affects 1.13-pre5

I enchanted a sword with tag:

Enchantments:[
  {lvl: 5s, id: "minecraft:bane_of_arthropods"}, 
  {lvl: 2s, id: "minecraft:knockback"}, 
  {lvl: 2s, id: "minecraft:fire_aspect"}, 
  {lvl: 3s, id: "minecraft:looting"}
]

/data get entity @s SelectedItem.tag.Enchantments[-1].lvl

Command should result in 3 but gives an error.

I will also make one comment: with an increasing number of id's withing the game becoming strings instead of values, I feel like it might be a good idea to add filter expressions to use within /date get and /execute store.  It's currently impossible to specifically select an entry from an array based on string ids.  Previously you could just use /execute store and identify the entry based on the value, but now it's impossible to do this as string ids can have the same character lengths.

Here's what a basic filter expression might look like:

/data get entity @s SelectedItem.tag.Enchantments[?(@.id == "minecraft:looting")].lvl

Which would search for entries in the array containing "id":"minecraft:looting" with the filter and return 3.  (I just used the logic from JsonPath).

affects 1.13-pre6

affects 1.13-pre7

affects 1.13-pre8

affects 1.13-pre9

affects 1.13-pre10

affects 1.13 full release

Since 18w43a negative indices start from the end of a list.

Maximilian Herczegh

(Unassigned)

Confirmed

Minecraft 18w20c, Minecraft 1.13-pre3, Minecraft 1.13-pre5, Minecraft 1.13-pre6, Minecraft 1.13-pre7, ..., Minecraft 1.13-pre10, Minecraft 1.13, Minecraft 18w31a, Minecraft 1.13.1-pre1, Minecraft 1.13.1

Retrieved