You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/modifier/nbt.md
+68-42Lines changed: 68 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,9 @@ nbt-data: <nbt>
20
20
21
21
## Example
22
22
23
+
:::tabs key:nbt-mode
24
+
== Legacy
25
+
23
26
```yaml
24
27
custom-model-chestplate:
25
28
id: leather_chestplate
@@ -43,15 +46,45 @@ colored-leather-chestplate:
43
46
position-y: 1
44
47
```
45
48
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
+
46
75
## How to set NBT
47
76
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
49
80
50
-
This will guide the basic of the YAML settings to set the NBT value
81
+
YAML structure mapping to NBT equivalents:
51
82
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
53
86
54
-
Let's start with an example. Suppose we want to apply the following NBT:
87
+
#### Example 1: Primitive Value
55
88
56
89
:::tabs key:nbt-mode
57
90
== Legacy
@@ -68,7 +101,7 @@ Let's start with an example. Suppose we want to apply the following NBT:
68
101
69
102
:::
70
103
71
-
The NBT settings would be:
104
+
Corresponding YAML configuration:
72
105
73
106
:::tabs key:nbt-mode
74
107
== Legacy
@@ -87,7 +120,7 @@ nbt:
87
120
88
121
:::
89
122
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
91
124
92
125
:::tabs key:nbt-mode
93
126
== Legacy
@@ -104,6 +137,8 @@ Now, what if we want to add some enchantments to the NBT? Let's add Unbreaking 1
104
137
105
138
:::
106
139
140
+
Corresponding YAML configuration:
141
+
107
142
:::tabs key:nbt-mode
108
143
== Legacy
109
144
@@ -129,26 +164,15 @@ nbt:
129
164
130
165
:::
131
166
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
140
168
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.
142
170
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.
144
172
145
-
This is where "Forced-Value Map" comes into play.
173
+
#### Example: Dynamic Enchantment Level
146
174
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}`
152
176
153
177
:::tabs key:nbt-mode
154
178
== Legacy
@@ -174,24 +198,26 @@ nbt:
174
198
175
199
:::
176
200
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:
195
221
196
222
```yaml
197
223
$type: "int_array"
@@ -201,9 +227,9 @@ $value:
201
227
- "23"
202
228
```
203
229
204
-
### Raw Data
230
+
### Raw SNBT Strings
205
231
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:
0 commit comments