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 [2022/04/13 08:04] – external edit 127.0.0.1tutorial:itemgroup [2022/12/11 22:06] – Update to 1.19.3 item group API haykam
Line 1: Line 1:
 ====== Item Groups ====== ====== Item Groups ======
-==== 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 class_1761 ITEM_GROUP = FabricItemGroupBuilder.build( +So far, you have used ''/give @s tutorial:custom_item'' to obtain your item. To make obtaining your item easieryou can add it to item groups within the creative inventory. You can also add your own item group. All items added to any group will also be searchable within the creative inventory.
-        new class_2960("tutorial""general"), +
-        () -> new class_1799(class_2246.field_10445));+
  
-    public static final class_1761 OTHER_GROUP FabricItemGroupBuilder.create( +==== Adding to Item Groups ====
-        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.+
  
-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.+First, choose the item group that the item should be added to. For this examplethat item group will be the building blocks groupThe vanilla item groups are stored in the ''<yarn class_7706>'' class.
  
-=== Adding your Items to your Item Group === +Next, in your ''onInitialize'' method, add the event handler for that item group. Each item group that you would like to modify requires its own event handler, but the same event handler can be used to add multiple items to one item group. 
-When creating custom Itemcall ''<yarn class_1792.class_1793>#<yarn method_7892>'' on your settings and pass in your custom group: + 
-<yarncode java> +Items can be positioned relative to the existing vanilla items. Think carefully about where your mod's users would expect the item to be. For example, if you are adding new type of woodplacing your item after the existing types of wood would make the most sense. 
-public static final class_1792 YOUR_ITEM = new class_1792(new class_1792.class_1793().method_7892(ExampleMod.ITEM_GROUP));+ 
 +For example, this event handler will place your mod's item after the oak door in the building blocks item group: 
 + 
 +<yarncode java [enable_line_numbers="true"]
 +ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { 
 + content.addAfter(class_1802.field_8691, CUSTOM_ITEM)
 +});
 </yarncode> </yarncode>
  
-==== Making an Item Group display specific Items in a particular order ==== +==== Creating an Item 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. +
-<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( +Before you create an item group, determine whether it would have enough content to warrant its own groupYour item group will be placed on a separate page of tabsimpacting its discoverabilityand users may be confused if the item is not where similar items are in the creative inventory.
-        new class_2960("tutorial""general"), +
-        () -> new class_1799(class_2246.field_10445));+
  
-    public static final class_1761 OTHER_GROUP FabricItemGroupBuilder.create( +If you think that your own item group is needed, you can use the ''FabricItemGroup.builder'' method to create a builder for an item group. Make sure to call the ''build'' method as well: 
-        new class_2960("tutorial", "other")) + 
-        .icon(() -> new class_1799(class_1802.field_8428)) +<yarncode java [enable_line_numbers="true"]> 
-        .appendItems(stacks -> { +private static final class_1761 ITEM_GROUP FabricItemGroup.builder(new class_2960("tutorial", "test_group")) 
-            stacks.add(new class_1799(class_2246.field_10166)); + .icon(() -> new class_1799(CUSTOM_ITEM)) 
-            stacks.add(new class_1799(class_1802.field_8279)); + .build();
-            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> </yarncode>
 +
 +You can use ''ITEM_GROUP'' to modify entries just like a vanilla item group. Note that you must add the items in order since there are no vanilla items to position them relative to:
 +
 +<yarncode java [enable_line_numbers="true"]>
 +ItemGroupEvents.modifyEntriesEvent(ITEM_GROUP).register(content -> {
 + content.add(CUSTOM_ITEM);
 +});
 +</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