Array Filters for <path> in /execute store, /data get, etc. - search for data within arrays!
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 different 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. (I just used the logic from JsonPath here).
Basically, "?" is the searching class. Using it in place of the integer within the path would look something like this:
?( @.<path> == "nbt data")
Where if the nbt data is correct within the path is correct, it will get the data from that specific array.
In addition "@" is the array itself, meaning you could do something like this:
/data get entity @s SelectedItem.tag.display.Lore[?(@ == "It's lore!")]
Which would get the data of a lore nbt tag if it contains "It's Lore!" string.
There could be more extendability to, like allowing the use of "*" as a wildcard or ".." as a deep scan.
Please sign in to leave a comment.