Skip to content

Commit 6051e59

Browse files
committed
tutorial for new NBT modifier
1 parent fb50f7a commit 6051e59

File tree

1 file changed

+68
-42
lines changed

1 file changed

+68
-42
lines changed

src/modifier/nbt.md

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ nbt-data: <nbt>
2020
2121
## Example
2222
23+
:::tabs key:nbt-mode
24+
== Legacy
25+
2326
```yaml
2427
custom-model-chestplate:
2528
id: leather_chestplate
@@ -43,15 +46,45 @@ colored-leather-chestplate:
4346
position-y: 1
4447
```
4548
49+
== Data Component
50+
51+
```yaml
52+
custom-model-chestplate:
53+
id: leather_chestplate
54+
nbt:
55+
custom_model_data: 104230
56+
name: "&aCustom Model Chestplate"
57+
lore:
58+
- "This is a custom model chestplate"
59+
position-x: 1
60+
position-y: 1
61+
62+
colored-leather-chestplate:
63+
id: leather_chestplate
64+
nbt:
65+
dyed_color: 16175144
66+
name: "&aColored Leather Chestplate"
67+
lore:
68+
- "This is a colored leather chestplate"
69+
position-x: 2
70+
position-y: 1
71+
```
72+
73+
:::
74+
4675
## How to set NBT
4776
48-
This modifier uses a library to convert the YAML settings to a proper SNBT that can be used to apply to the item.
77+
BetterGUI automatically converts YAML-structured NBT settings into valid SNBT (Stringified Named Binary Tag) format. The following section describes the structure and syntax required for proper NBT configuration.
78+
79+
### Basic Conversion Rules
4980
50-
This will guide the basic of the YAML settings to set the NBT value
81+
YAML structure mapping to NBT equivalents:
5182
52-
### Basic Use
83+
- **Objects** → NBT compound tags (denoted by curly brackets `{}` in SNBT)
84+
- **Lists** → NBT list/array tags (denoted by square brackets `[]` in SNBT)
85+
- **Key-value pairs** → individual NBT entries
5386

54-
Let's start with an example. Suppose we want to apply the following NBT:
87+
#### Example 1: Primitive Value
5588

5689
:::tabs key:nbt-mode
5790
== Legacy
@@ -68,7 +101,7 @@ Let's start with an example. Suppose we want to apply the following NBT:
68101
69102
:::
70103
71-
The NBT settings would be:
104+
Corresponding YAML configuration:
72105
73106
:::tabs key:nbt-mode
74107
== Legacy
@@ -87,7 +120,7 @@ nbt:
87120
88121
:::
89122
90-
Now, what if we want to add some enchantments to the NBT? Let's add Unbreaking 1 and Sharpness 2 to the NBT
123+
#### Example 2: Compound Structures with List Elements
91124
92125
:::tabs key:nbt-mode
93126
== Legacy
@@ -104,6 +137,8 @@ Now, what if we want to add some enchantments to the NBT? Let's add Unbreaking 1
104137

105138
:::
106139

140+
Corresponding YAML configuration:
141+
107142
:::tabs key:nbt-mode
108143
== Legacy
109144

@@ -129,26 +164,15 @@ nbt:
129164
130165
:::
131166
132-
As you can see, the NBT settings are straight-forward without hacks.
133-
Since the entry in the SNBT consists of a key and a value, the NBT value in the settings will always follow the same
134-
format.
135-
A setting with multiple sub-settings will result in a compound in the SNBT (the part within the curly brackets `{}`).
136-
A setting with list entries (those with `-` before them) with result in a list in the SNBT (the part within the square
137-
brackets `[]`).
138-
139-
### Forced-Value Map
167+
### Type Enforcement with Forced-Value Maps
140168
141-
So far we can set the NBT value of Strings and Integers without anything more.
169+
In basic scenarios, string and integer values are inferred automatically from their YAML representation. However, when incorporating [Variables](/misc/variable) into NBT values, explicit type specification becomes necessary.
142170
143-
But now the question remains: What if we want to use [Variable](/misc/variable) in the NBT value?
171+
When a value is dynamic (contains a variable reference), use a forced-value map with `$type` and `$value` properties to explicitly declare the NBT data type. This ensures correct type conversion when the variable is resolved at runtime.
144172

145-
This is where "Forced-Value Map" comes into play.
173+
#### Example: Dynamic Enchantment Level
146174

147-
Let's take an example: Suppose we want to increase the Unbreaking level based on the player's level (with the variable
148-
`{level}`).
149-
150-
Since the enchantment level must be an integer, We will set the value to be a setting of `$type` for the type and
151-
`$value` for the value, like this:
175+
To set an enchantment level based on a player variable `{level}`
152176

153177
:::tabs key:nbt-mode
154178
== Legacy
@@ -174,24 +198,26 @@ nbt:
174198

175199
:::
176200

177-
Here is the full list of all the available `$type`:
178-
179-
- `byte`
180-
- `boolean`
181-
- `short`
182-
- `int` or `integer`
183-
- `long`
184-
- `float`
185-
- `double`
186-
- `string`
187-
- `raw`
188-
- `list`
189-
- `compound`
190-
- `byte_array`
191-
- `int_array`
192-
- `long_array`
193-
194-
For `byte_array`, `int_array` and `long_array`, the `$value` must be a list, like this:
201+
#### Supported Data Types
202+
203+
The following data types are available for the `$type` property:
204+
205+
- `byte` - Signed 8-bit integer
206+
- `boolean` - True/false value
207+
- `short` - Signed 16-bit integer
208+
- `int` or `integer` - Signed 32-bit integer
209+
- `long` - Signed 64-bit integer
210+
- `float` - 32-bit floating-point
211+
- `double` - 64-bit floating-point
212+
- `string` - Text string
213+
- `raw` - Raw SNBT string (parsed as-is)
214+
- `list` - Homogeneous list
215+
- `compound` - Compound tag (object)
216+
- `byte_array` - Array of bytes
217+
- `int_array` - Array of integers
218+
- `long_array` - Array of longs
219+
220+
For array types (`byte_array`, `int_array`, `long_array`), the `$value` must be specified as a list:
195221

196222
```yaml
197223
$type: "int_array"
@@ -201,9 +227,9 @@ $value:
201227
- "23"
202228
```
203229

204-
### Raw Data
230+
### Raw SNBT Strings
205231

206-
If you want to set the SNBT directly, you can set it directly as the value of the NBT setting, like this:
232+
For advanced use cases, SNBT can be specified directly as a string value instead of using structured YAML. This bypasses automatic type inference and conversion, allowing direct SNBT syntax:
207233

208234
:::tabs key:nbt-mode
209235
== Legacy

0 commit comments

Comments
 (0)