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 revision
Previous revision
Next revisionBoth sides next revision
tutorial:itemgroup [2019/02/21 13:17] mcrafterzztutorial:itemgroup [2022/04/13 08:04] – map2fabricyarn daomephsta
Line 1: Line 1:
-====== Adding an item group ====== +====== Item Groups ====== 
-Do you want your blocks and items blocks to have their own group in the creative inventory? Then that can easly be fixed. The most common way to create one is to use //FabricItemGroupBuilder.create//. Like items and blocks this has to be done in //onInitialize// method to work correctly.+==== Creating a simple Item Group ==== 
 +To have your ''<yarn class_1761>'' properly show up in the creative menu, use the ''FabricItemGroupBuilder'' to create them: 
 +<yarncode java [enable_line_numbers="true"]> 
 +public class ExampleMod implements ModInitializer {
  
-   public static final ItemGroup ITEM_GROUP +    public static final class_1761 ITEM_GROUP = FabricItemGroupBuilder.build( 
-   @Override +        new class_2960("tutorial", "general")
-   public void onInitialize() { +        () -> new class_1799(class_2246.field_10445));
-       ITEM_GROUP = FabricItemGroupBuilder.create(new Identifier("modid", "name")})).icon(() -> new ItemStack(block)).build(); +
-   }+
  
-The modid is the id of your modname is the name of the creative tabs (must be lowercase to not crash). The icon is should be an itemstack, created with either an item or a block like in this case for example //Blocks.Grass//. To add blocks to your item group use //.itemGroup(itemGroup)// when creating it.+    public static final class_1761 OTHER_GROUP = FabricItemGroupBuilder.create( 
 +        new class_2960("tutorial""other")) 
 +        .icon(() -> new class_1799(class_1802.field_8428)) 
 +        .build(); 
 +    // ... 
 +
 +</yarncode> 
 +Once ''FabricItemGroupBuilder#build'' is called, your group will be added to the list of item groups in the creative menu.
  
-   public static final Item FABRIC_ITEM = new Item(new Item.Settings().itemGroup(ITEM_GROUP));+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.
  
-Creating an item group is as easy as that!+=== Adding your Items to your Item Group === 
 +When creating a custom Item, call ''<yarn class_1792.class_1793>#<yarn method_7892>'' on your settings and pass in your custom group: 
 +<yarncode java> 
 +public static final class_1792 YOUR_ITEM = new class_1792(new class_1792.class_1793().method_7892(ExampleMod.ITEM_GROUP)); 
 +</yarncode> 
 + 
 +==== Making an Item Group display specific Items in a particular order ==== 
 +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
 +<yarncode java [enable_line_numbers="true",highlight_lines_extra="11,12,13,14,15,16,17,18"]> 
 +public class ExampleMod implements ModInitializer { 
 + 
 +    public static final class_1761 ITEM_GROUP = FabricItemGroupBuilder.build( 
 +        new class_2960("tutorial", "general"), 
 +        () -> new class_1799(class_2246.field_10445)); 
 + 
 +    public static final class_1761 OTHER_GROUP = FabricItemGroupBuilder.create( 
 +        new class_2960("tutorial", "other")) 
 +        .icon(() -> new class_1799(class_1802.field_8428)) 
 +        .appendItems(stacks -> { 
 +            stacks.add(new class_1799(class_2246.field_10166)); 
 +            stacks.add(new class_1799(class_1802.field_8279)); 
 +            stacks.add(class_1844.method_8061(new class_1799(class_1802.field_8574), class_1847.field_8991)); 
 +            stacks.add(class_1799.field_8037); 
 +            stacks.add(new class_1799(class_1802.field_8699)); 
 +        }) 
 +        .build(); 
 +    // ... 
 +
 +</yarncode> 
 +{{:tutorial:item_group_append_items.png?nolink&400|}}
tutorial/itemgroup.txt · Last modified: 2024/06/17 12:49 by solidblock