Integrated Dynamics - On the Dynamics of Integration

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].

Operator(运算符)
NBT Path Match FirstNBT.path_match_firstApply the given NBT Path expression on the given NBT value, and return the first match
  • String(字符串)
  • NBT
  • NBT
Global name: stringNbtPathMatchFirst(String(字符串)NBT) → NBTMethod name: String(字符串).nbtPathMatchFirst(NBT) → NBT
Operator(运算符)
NBT Path Match AllNBT.path_match_allApply the given NBT Path expression on the given NBT value, and return all matches as a list
  • String(字符串)
  • NBT
  • List(列表)
Global name: stringNbtPathMatchAll(String(字符串)NBT) → List(列表)Method name: String(字符串).nbtPathMatchAll(NBT) → List(列表)
Operator(运算符)
NBT Path TestNBT.path_testTest if the given NBT Path expression matches with the given NBT value
  • String(字符串)
  • NBT
  • Boolean(布尔)
Global name: stringNbtPathTest(String(字符串)NBT) → Boolean(布尔)Method name: String(字符串).nbtPathTest(NBT) → Boolean(布尔)