Skip to content

Commit fb50f7a

Browse files
committed
tutorial for new NBT modifier
1 parent 2e4fcf1 commit fb50f7a

File tree

1 file changed

+171
-11
lines changed

1 file changed

+171
-11
lines changed

src/modifier/nbt.md

Lines changed: 171 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ title: NBT
77
This modifier will apply the NBT data to the item.
88

99
::: warning
10-
This modifier will reset all item settings. Therefore, It's recommended to order the settings in the following pattern: `ID (Material)`, `NBT`, `other item settings`.
10+
This modifier will reset all item settings. Therefore, It's recommended to order the settings in the following pattern:
11+
`ID (Material)`, `NBT`, `other item settings`.
1112
:::
1213

1314
## Format
@@ -24,7 +25,6 @@ custom-model-chestplate:
2425
id: leather_chestplate
2526
nbt:
2627
CustomModelData: 104230
27-
#nbt: "{CustomModelData:104230}"
2828
name: "&aCustom Model Chestplate"
2929
lore:
3030
- "This is a custom model chestplate"
@@ -36,26 +36,186 @@ colored-leather-chestplate:
3636
nbt:
3737
display:
3838
color: 16175144
39-
#nbt: "{display:{color:16175144}}"
4039
name: "&aColored Leather Chestplate"
4140
lore:
4241
- "This is a colored leather chestplate"
4342
position-x: 2
4443
position-y: 1
4544
```
4645
47-
## Item Component
46+
## How to set NBT
4847
49-
In 1.20.5 and above, Mojang decided to replace NBT with their new Item Component.
50-
To use Item Component, you can use its square-bracket format `[]` as the value to the modifier.
48+
This modifier uses a library to convert the YAML settings to a proper SNBT that can be used to apply to the item.
5149
52-
For example, for a typical `/give` command like this:
50+
This will guide the basic of the YAML settings to set the NBT value
51+
52+
### Basic Use
53+
54+
Let's start with an example. Suppose we want to apply the following NBT:
55+
56+
:::tabs key:nbt-mode
57+
== Legacy
58+
59+
```
60+
{CustomModelData:12}
5361
```
54-
/give @s leather_helmet[dyed_color={rgb:456345,show_in_tooltip:false}]
62+
63+
== Data Component
64+
65+
```
66+
[custom_model_data=12]
5567
```
5668

57-
You can take this part `[dyed_color={rgb:456345,show_in_tooltip:false}]` and use it in the modifier like this:
69+
:::
70+
71+
The NBT settings would be:
72+
73+
:::tabs key:nbt-mode
74+
== Legacy
75+
76+
```yaml
77+
nbt:
78+
CustomModelData: 12
79+
```
80+
81+
== Data Component
5882
5983
```yaml
60-
nbt: "[dyed_color={rgb:456345,show_in_tooltip:false}]"
61-
```
84+
nbt:
85+
custom_model_data: 12
86+
```
87+
88+
:::
89+
90+
Now, what if we want to add some enchantments to the NBT? Let's add Unbreaking 1 and Sharpness 2 to the NBT
91+
92+
:::tabs key:nbt-mode
93+
== Legacy
94+
95+
```
96+
{CustomModelData:12,ench:[{lvl:2,id:sharpness},{lvl:1,id:unbreaking}]}
97+
```
98+
99+
== Data Component
100+
101+
```
102+
[custom_model_data=12,enchantments={sharpness:2,unbreaking:1}]
103+
```
104+
105+
:::
106+
107+
:::tabs key:nbt-mode
108+
== Legacy
109+
110+
```yaml
111+
nbt:
112+
CustomModelData: 12
113+
ench:
114+
- id: sharpness
115+
lvl: 2
116+
- id: unbreaking
117+
lvl: 1
118+
```
119+
120+
== Data Component
121+
122+
```yaml
123+
nbt:
124+
custom_model_data: 12
125+
enchantments:
126+
sharpness: 2
127+
unbreaking: 1
128+
```
129+
130+
:::
131+
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
140+
141+
So far we can set the NBT value of Strings and Integers without anything more.
142+
143+
But now the question remains: What if we want to use [Variable](/misc/variable) in the NBT value?
144+
145+
This is where "Forced-Value Map" comes into play.
146+
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:
152+
153+
:::tabs key:nbt-mode
154+
== Legacy
155+
156+
```yaml
157+
nbt:
158+
ench:
159+
- id: unbreaking
160+
lvl:
161+
$type: "integer"
162+
$value: "{level}"
163+
```
164+
165+
== Data Component
166+
167+
```yaml
168+
nbt:
169+
enchantments:
170+
unbreaking:
171+
$type: "integer"
172+
$value: "{level}"
173+
```
174+
175+
:::
176+
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:
195+
196+
```yaml
197+
$type: "int_array"
198+
$value:
199+
- "12"
200+
- "{level}"
201+
- "23"
202+
```
203+
204+
### Raw Data
205+
206+
If you want to set the SNBT directly, you can set it directly as the value of the NBT setting, like this:
207+
208+
:::tabs key:nbt-mode
209+
== Legacy
210+
211+
```yaml
212+
nbt: "{CustomModelData:12,ench:[{lvl:2,id:sharpness},{lvl:1,id:unbreaking}]}"
213+
```
214+
215+
== Data Component
216+
217+
```yaml
218+
nbt: "[custom_model_data=12,enchantments={sharpness:2,unbreaking:1}]"
219+
```
220+
221+
:::

0 commit comments

Comments
 (0)