NBTs
#
General SyntaxIn Sandstone, NBTs are regular JavaScript objects. JavaScript objects are very close to NBTs: they have arrays, objects, keys and values, numbers and strings.
For example, to summon an invisible armor stand with the "hello" tag and a pumpkin on his head, you would do the following command:
#
Units#
UsefulnessDespite JavaScript objects and NBTs being close, there is one thing missing from JavaScript objects that is required in NBTs: specifying units.
For example, to summon an armor stand with a given rotation, you need to specify that the values are floats.
With this command, you get the expected result:
Omit the unit, and the armor stand rotation will be wrong:
Here, specifying that the values are floats is mandatory. However, this isn't possible to do it with a normal JavaScript object.
#
Unit SyntaxTo specify a unit, you must call the corresponding method under the NBT
object. For all units, there are 2 possible calls:
- With a single number. It will add the given unit to the number.
- With an array of numbers. It will add the given unit to all numbers in the array.
For example, to summon an armor stand with Invisible: 1b
and Rotation: [90f, 0f]
, you must write:
#
All unitsHere is a summary of all units and their corresponding methods.
type | unit | method |
---|---|---|
float | 'f' | NBT.float |
double | 'd' | NBT.double |
byte | 'b' | NBT.byte |
short | 's' | NBT.short |
long | 'l' | NBT.long |
int array | 'I;' | NBT.integerArray |
long array | 'L;' | NBT.longArray |
Integer array and Long array are different from arrays of integers and arrays of longs. These types were added recently, and are use in a few specific places. They are represented this way:
Integer arrays are used in custom player heads IDs, and in several Villager NBTs storing locations.
Long arrays are used to store chunk data.
#
Unit-free SyntaxAnother syntax exists. It's more compact, easier to read, but has absolutely no type safety and no validation. It uses the template string syntax:
caution
Please note than no validation is performed. For example, missing a bracket will result in an invalid command.
The above snippet results in the following invalid command: