-
Notifications
You must be signed in to change notification settings - Fork 65
JsonNBT
For anyone who's dealt with loot tables and predicates for long enough, you know the pain of writing SNBT. Single-line, frequent escaping, the nightmare of unmatching brackets... well, no more! Introducing:
This is a custom format that Spectrum is using to simplify writing NBT in Json files. However, it does have a few constraints, which are noted below. Spectrum also accepts standard SNBT to maintain compatability.
Bytes (8-bit signed values) are represented as Json strings, with the format "[0-9]+[bB]"
. Additionally, the boolean values true
and false
map to 1b
and 0b
, respectively. For example:
{
"NBTBytes": [
"127b",
"-128B",
true,
false
]
}
Shorts (16-bit signed values) are represented as Json strings, with the format "[0-9]+[sS]"
. For example:
{
"NBTShorts": [
"32767s",
"-32768S"
]
}
Integers (32-bit signed values) are represented as Json numbers, with the format [0-9]+
. As mentioned in Limitations, decimal points are also valid as long as the number is whole. Additionally, to help with specificity, JsonNBT interprets "[0-9]+[iI]"
as integers as well. For example:
{
"NBTInts": [
"2147483647i",
"-2147483648I",
12,
-3.00
]
}
Longs (64-bit signed values) are represented as Json strings, with the format "[0-9]+[lL]"
. For example:
{
"NBTLongs": [
"9223372036854775807l",
"-9223372036854775808L"
]
}
Floats (32-bit floating-point values) are represented as Json strings, with the suffix f
or F
. For example:
{
"NBTFloats": [
"3.40282346639e+38f",
"-3.40282346639E+38F"
]
}
Doubles (64-bit floating-point values) are represented as Json strings, with the suffix d
or D
. Additionally, Json numbers that have a fractional component or are larger than an integer will be parsed as a double. For example:
{
"NBTDoubles": [
"1.7976931348623157e+308d",
"-1.7976931348623157E+308D",
0.5,
1000000000000
]
}
Strings are represented as Json strings, when none of the other formats apply. For example:
{
"NBTStrings": [
"Hello, world!",
"This is a string"
]
}
Lists are represented as Json arrays. Note that each element in the array must be parsed to the same NBT type. For example:
{
"NBTList": [
"1b",
"2b",
true
]
}
Compounds are represented as Json objects. The only difference from SNBT is that the keys are quoted. For example:
{
"NBTCompound": {
"key1": "value1",
"key2": "value2"
}
}
Byte arrays are the same as a list of bytes, but with the first element being "B;". For example:
{
"NBTByteArray": [
"B;",
"1b",
"2b",
true
]
}
Int arrays are the same as a list of integers, but with the first element being "I;". For example:
{
"NBTIntArray": [
"I;",
30,
171,
-10
]
}
Long arrays are the same as a list of longs, but with the first element being "L;". For example:
{
"NBTLongArray": [
"L;",
"12135L",
"-43L"
]
}
Unfortunately, since Json is less specific than SNBT, this format is not without its limitations. Specifically, since strings are being used to add type information, it's possible that a string may be interpreted as a number even when you don't want it to. Of course, it's unlikely that you'll be using strings such as "B;"
and "13d"
, and we still support standard SNBT in that case.
Another limitation is that some NBT contains Json within itself (e.g. CustomName
), which currently must be expressed in a string. We may revisit this in the future, but for now, the complexity isn't worth it.
Also, since Json doesn't differentiate between integers and floating-point numbers, there isn't a good way to handle plain numbers. We currently just check if it can fit into an integer, so both 123
and 1.0
are integers, but 0.5
and 1000000000000
are doubles. If your number is ambiguous, you can specify its type explicitly via a string with the i/I
and d/D
suffixes.
If you have any suggestions, please feel free to mention them! This format is meant to simplify things in Minecraft's increasingly data-driven model, so any feedback is appreciated.
General
For Players
- Getting Started
- Mixing Colors
- Stuck on how to progress?
- Main Progression Steps (MAJOR SPOILERS)
For Server Admins / Modpack Creators
- Integrating into Modpacks
- Adjusting Progression
- Advancement Criteria
- 1.7.x: Patchouli Pages
- 1.7.x: Patchouli Recipe Pages
- 1.8.x: Modonomicon Pages
- 1.8.x: Modonomicon Recipe Pages
- Commands
- Type Specific Predicates
- JsonNBT
For Map Makers
Recipe Types
- Custom Pigment Pedestal Recipes
- Custom Anvil Crushing Recipes
- Custom Fusion Shrine Recipes
- Custom Enchanter Recipes
- Custom Enchantment Upgrade Recipes
- Custom Potion Workshop Brewing Recipes
- Custom Potion Workshop Crafting Recipes
- Custom Potion Workshop Reagents
- Custom Spirit Instiller Recipes
- Custom Liquid Dipping Recipes
- Custom Ink Converting Recipes
- Custom Crystallarieum Recipes
- Custom Cinderhearth Recipes
- Custom Titration Barrel Recipes
- Fluid Ingredients
Loot Tables
More Customisation
- Adding Nature's Staff Conversions
- Adding Entity Fishing Entries
- Adding Resonance Drops
- Adding Crystal Apothecary Harvestables
- Adding Particle Spawner Particles
For Contributors