@@ -147,11 +147,11 @@ stack.resetData(DataComponentTypes.MAX_STACK_SIZE);
147147Some components are only flags and don't carry any sort of value:
148148
149149``` java
150- // Make the item unbreakable
151- stack. setData(DataComponentTypes . UNBREAKABLE );
150+ // Make the item a glider to be used like elytra (combined with the equippable component)
151+ stack. setData(DataComponentTypes . GLIDER );
152152
153- // Remove the unbreakable flag
154- stack. unsetData(DataComponentTypes . UNBREAKABLE );
153+ // Remove the glider flag
154+ stack. unsetData(DataComponentTypes . GLIDER );
155155```
156156
157157## Advanced usage with builders
@@ -161,57 +161,57 @@ Many data components have complex structures that require builders.
161161### Modifying prototype component values
162162
163163``` java
164- ItemStack itemStack = ItemStack . of(Material . DIAMOND_HELMET );
164+ ItemStack helmet = ItemStack . of(Material . DIAMOND_HELMET );
165165// Get the equippable component for this item, and make it a builder.
166166// Note: Not all types have .toBuilder() methods
167167// This is the prototype value of the diamond helmet.
168- Equippable . Builder builder = itemStack . getData(DataComponentTypes . EQUIPPABLE ). toBuilder();
168+ Equippable . Builder builder = helmet . getData(DataComponentTypes . EQUIPPABLE ). toBuilder();
169169
170170// Make the helmet look like netherite
171171// We get the prototype equippable value from NETHERITE_HELMET
172172builder. assetId(Material . NETHERITE_HELMET. getDefaultData(DataComponentTypes . EQUIPPABLE ). assetId());
173173// And give it a spooky sound when putting it on
174- builder. equipSound(Registry . SOUNDS . getKeyOrThrow( Sound . ENTITY_GHAST_HURT) );
174+ builder. equipSound(SoundEventKeys . ENTITY_GHAST_HURT );
175175
176176// Set our new item
177- itemStack . setData(DataComponentTypes . EQUIPPABLE , builder);
177+ helmet . setData(DataComponentTypes . EQUIPPABLE , builder);
178178```
179179This will create a diamond helmet that looks like a netherite helmet and plays a spooky ghast sound when equipped.
180180
181181### Example: Written book
182182
183183``` java
184- ItemStack writtenBook = ItemStack . of(Material . WRITTEN_BOOK );
185- WrittenBookContent . Builder bookBuilder = WrittenBookContent . writtenBookContent(" My Book" , " AuthorName" );
184+ ItemStack book = ItemStack . of(Material . WRITTEN_BOOK );
185+ WrittenBookContent . Builder builder = WrittenBookContent . writtenBookContent(" My Book" , " AuthorName" );
186186
187187// Add a page
188- bookBuilder . addPage(Component . text(" This is a new page!" ));
188+ builder . addPage(Component . text(" This is a new page!" ));
189189
190190// Add a page that shows differently for people who have swear filtering on
191191// Players who have disabled filtering, will see "I hate Paper!", while those with filtering on will see the "I love Paper!".
192- bookBuilder . addFilteredPage(
192+ builder . addFilteredPage(
193193 Filtered . of(Component . text(" I hate Paper!" ), Component . text(" I love Paper!" ))
194194);
195195
196196// Change generation
197- bookBuilder . generation(1 );
197+ builder . generation(1 );
198198
199199// Apply changes
200- writtenBook . setData(DataComponentTypes . WRITTEN_BOOK_CONTENT , bookBuilder . build());
200+ book . setData(DataComponentTypes . WRITTEN_BOOK_CONTENT , builder . build());
201201```
202202
203203### Example: Cool sword
204204
205205``` java
206- ItemStack itemStack = ItemStack . of(Material . DIAMOND_SWORD );
207- itemStack . setData(DataComponentTypes . LORE , ItemLore . lore(). addLine(Component . text(" Cool sword!" )). build());
208- itemStack . setData(DataComponentTypes . ENCHANTMENTS , ItemEnchantments . itemEnchantments(). add(Enchantment . SHARPNESS , 10 ). build());
209- itemStack . setData(DataComponentTypes . RARITY , ItemRarity . RARE );
206+ ItemStack sword = ItemStack . of(Material . DIAMOND_SWORD );
207+ sword . setData(DataComponentTypes . LORE , ItemLore . lore(). addLine(Component . text(" Cool sword!" )). build());
208+ sword . setData(DataComponentTypes . ENCHANTMENTS , ItemEnchantments . itemEnchantments(). add(Enchantment . SHARPNESS , 10 ). build());
209+ sword . setData(DataComponentTypes . RARITY , ItemRarity . RARE );
210210
211- itemStack . unsetData(DataComponentTypes . TOOL ); // Remove the tool component
211+ sword . unsetData(DataComponentTypes . TOOL ); // Remove the tool component
212212
213- itemStack . setData(DataComponentTypes . MAX_DAMAGE , 10 );
214- itemStack . setData(DataComponentTypes . ENCHANTMENT_GLINT_OVERRIDE , true ); // Make it glow!
213+ sword . setData(DataComponentTypes . MAX_DAMAGE , 10 );
214+ sword . setData(DataComponentTypes . ENCHANTMENT_GLINT_OVERRIDE , true ); // Make it glow!
215215```
216216
217217## Matching items without certain data components
@@ -223,10 +223,10 @@ method.
223223For example, here we compare two diamond swords whilst ignoring their durability:
224224
225225``` java
226- ItemStack originalSword = new ItemStack (Material . DIAMOND_SWORD );
227- ItemStack damagedSword = new ItemStack (Material . DIAMOND_SWORD );
226+ ItemStack originalSword = ItemStack . of (Material . DIAMOND_SWORD );
227+ ItemStack damagedSword = ItemStack . of (Material . DIAMOND_SWORD );
228228damagedSword. setData(DataComponentTypes . DAMAGE , 100 );
229229
230230boolean match = damagedSword. matchesWithoutData(originalSword, Set . of(DataComponentTypes . DAMAGE ), false );
231- logger. info(" Do the sword match? " + match); // true
231+ logger. info(" Do the sword match? " + match); // -> true
232232```
0 commit comments