NBT Path
When working with complex NBT tags, you can quickly require complex operator chains for reading deeply nested NBT values. In order to to simplify this task, String-based NBT Path expressions can be used to determine the path within an NBT tag.
The simplest NBT Path expression is made up of a chain of field selectors, such as .fieldName or .[”fieldName”].
For example, applying the expression ”.root.child1.child2” on the NBT tag { root: { child1: { child2: ”some value” } }} will output ”some value”.
Multiple fields can be selected by providing an array of field names or a wildcard, for example [fieldA,fieldB] or *
For example, applying the expression ”.a[b1,b2]*” on the NBT tag { a: { b1: { c: ”some value” } }} will output ”some value”.
When working with NBT lists, specific entries can be selected by specifying an index, such as [1].
For example, applying the expression ”.a[1]” on the NBT tag { a: [10,20] } will output ”20”.
Multiple list indexes can be selected using the slice operator: [start:end:step]. (Only start is required, the other elements may be omitted)
For example, applying the expression ”.a[1:4:2]” on the NBT tag { a: [0,1,2,3,4,5] } will output [1,3].
More advanced filter expressions are also possible using the filter syntax, for example [?(@.childName < 10)] (@ refers to the current tag, .. refers to the parent tag, $ refers to the root tag)
For example, applying the expression ”$.a[?(@ == 3)]” on the NBT tag { a: [0,1,2,3,4,5] } will output [3].
- String
- NBT
- NBT
- String
- NBT
- List
- String
- NBT
- Boolean