User Tools

Site Tools


tutorial:itemgroup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorial:itemgroup [2020/06/09 23:44] – formatting changes (newline -> same line brackets) draylartutorial:itemgroup [2022/04/13 08:04] – map2fabricyarn daomephsta
Line 1: Line 1:
 ====== Item Groups ====== ====== Item Groups ======
 ==== Creating a simple Item Group ==== ==== Creating a simple Item Group ====
-To have your ''ItemGroup'' properly show up in the creative menu, use the ''FabricItemGroupBuilder'' to create them: +To have your ''<yarn class_1761>'' properly show up in the creative menu, use the ''FabricItemGroupBuilder'' to create them: 
-<code java [enable_line_numbers="true"]>+<yarncode java [enable_line_numbers="true"]>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
  
- public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( +    public static final class_1761 ITEM_GROUP = FabricItemGroupBuilder.build( 
- new Identifier("tutorial", "general"), +        new class_2960("tutorial", "general"), 
- () -> new ItemStack(Blocks.COBBLESTONE)); +        () -> new class_1799(class_2246.field_10445)); 
-  + 
- public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( +    public static final class_1761 OTHER_GROUP = FabricItemGroupBuilder.create( 
- new Identifier("tutorial", "other")) +        new class_2960("tutorial", "other")) 
- .icon(() -> new ItemStack(Items.BOWL)) +        .icon(() -> new class_1799(class_1802.field_8428)) 
- .build(); +        .build(); 
- // ...+    // ...
 } }
-</code>+</yarncode>
 Once ''FabricItemGroupBuilder#build'' is called, your group will be added to the list of item groups in the creative menu. Once ''FabricItemGroupBuilder#build'' is called, your group will be added to the list of item groups in the creative menu.
  
-Make sure you replace the arguments ((Remember that the arguments you pass to the ''Identifier'' constructor can only contain certain characters.\\ Both arguments (the ''namespace'' & ''path'') can contain //lowercase letters//, //numbers//, //underscores//, //periods//, or //dashes//. ''[a-z0-9_.-]''\\ The second argument (the ''path'') can also include //slashes//. ''[a-z0-9/._-]''\\ Avoid using other symbols, else an ''InvalidIdentifierException'' would be thrown!)) you pass to the ''Identifier'' constructor with your actual mod ID and the translation key you want to give your item group for localization ((The full translation key for the first example ''ItemGroup'' would be ''itemGroup.mod_id.general'')) later on.+Make sure you replace the arguments ((Remember that the arguments you pass to the ''<yarn class_2960>'' constructor can only contain certain characters.\\ Both arguments (the ''namespace'' & ''path'') can contain //lowercase letters//, //numbers//, //underscores//, //periods//, or //dashes//. ''[a-z0-9_.-]''\\ The second argument (the ''path'') can also include //slashes//. ''[a-z0-9/._-]''\\ Avoid using other symbols, else an ''<yarn class_151>'' would be thrown!)) you pass to the ''<yarn class_2960>'' constructor with your actual mod ID and the translation key you want to give your item group for localization ((The full translation key for the first example ''<yarn class_1761>'' would be ''itemGroup.mod_id.general'')) later on.
  
 === Adding your Items to your Item Group === === Adding your Items to your Item Group ===
-When creating a custom Item, call ''Item.Settings#group'' on your settings and pass in your custom group: +When creating a custom Item, call ''<yarn class_1792.class_1793>#<yarn method_7892>'' on your settings and pass in your custom group: 
-<code java> +<yarncode java> 
-public static final Item YOUR_ITEM = new Item(new Item.Settings().group(ExampleMod.ITEM_GROUP)); +public static final class_1792 YOUR_ITEM = new class_1792(new class_1792.class_1793().method_7892(ExampleMod.ITEM_GROUP)); 
-</code>+</yarncode>
  
 ==== Making an Item Group display specific Items in a particular order ==== ==== Making an Item Group display specific Items in a particular order ====
-Call ''FabricItemGroupBuilder#appendItems'' and pass any ''Consumer<List<ItemStack//>//>''. You can then add whatever stacks you want to the given list in some order. ''ItemStack.EMPTY'' can be used to place empty spaces in your group. +Call ''FabricItemGroupBuilder#appendItems'' and pass any ''Consumer<List%%<%%<yarn class_1799>//>//>''. You can then add whatever stacks you want to the given list in some order. ''<yarn class_1799.field_8037>'' can be used to place empty spaces in your group. 
-<code java [enable_line_numbers="true",highlight_lines_extra="11,12,13,14,15,16,17,18"]>+<yarncode java [enable_line_numbers="true",highlight_lines_extra="11,12,13,14,15,16,17,18"]>
 public class ExampleMod implements ModInitializer { public class ExampleMod implements ModInitializer {
-  + 
- public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( +    public static final class_1761 ITEM_GROUP = FabricItemGroupBuilder.build( 
- new Identifier("tutorial", "general"), +        new class_2960("tutorial", "general"), 
- () -> new ItemStack(Blocks.COBBLESTONE)); +        () -> new class_1799(class_2246.field_10445)); 
-  + 
- public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( +    public static final class_1761 OTHER_GROUP = FabricItemGroupBuilder.create( 
- new Identifier("tutorial", "other")) +        new class_2960("tutorial", "other")) 
- .icon(() -> new ItemStack(Items.BOWL)) +        .icon(() -> new class_1799(class_1802.field_8428)) 
- .appendItems(stacks -> { +        .appendItems(stacks -> { 
- stacks.add(new ItemStack(Blocks.BONE_BLOCK)); +            stacks.add(new class_1799(class_2246.field_10166)); 
- stacks.add(new ItemStack(Items.APPLE)); +            stacks.add(new class_1799(class_1802.field_8279)); 
- stacks.add(PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER)); +            stacks.add(class_1844.method_8061(new class_1799(class_1802.field_8574), class_1847.field_8991)); 
- stacks.add(ItemStack.EMPTY); +            stacks.add(class_1799.field_8037); 
- stacks.add(new ItemStack(Items.IRON_SHOVEL)); +            stacks.add(new class_1799(class_1802.field_8699)); 
- }) +        }) 
- .build(); +        .build(); 
- // ...+    // ...
 } }
-</code>+</yarncode>
 {{:tutorial:item_group_append_items.png?nolink&400|}} {{:tutorial:item_group_append_items.png?nolink&400|}}
tutorial/itemgroup.txt · Last modified: 2023/10/01 03:21 by haykam