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
tutorial:itemgroup [2023/06/11 08:33] – Add link to 1.19 version mcrafterzztutorial:itemgroup [2023/10/01 03:21] (current) – Remove semicolon to nowhere haykam
Line 7: Line 7:
 ==== Adding to Item Groups ==== ==== Adding to Item Groups ====
  
-First, choose the item group that the item should be added to. For this example, that item group will be the building blocks group. The vanilla item groups are stored in the ''<yarn class_7706>'' class.+First, choose the item group that the item should be added to. For this example, that item group will be the building blocks group. The registry keys of vanilla item groups are stored in the ''<yarn class_7706>'' class.
  
-Next, you can simply use ''group'' method in ''FabricItemSettings'' with Fabric API. This will locate your custom item on last of item group+Next, you will have to create an event handler for modifying item groups.
  
-But if you want to put your custom item in other location(eg. after of ''<yarn field_8691>'') or other advanced modification, you can register the event handler for each item group that you would like to modify in your ''onInitialize'' method. 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.+<yarncode java [enable_line_numbers="true"]> 
 +ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { 
 + content.add(CUSTOM_ITEM); 
 +}); 
 +</yarncode> 
 + 
 +The modification event also allows more fine-grained control such as placing your custom item in a specific location(eg. after of ''<yarn field_8691>'') or other advanced modification, you can register the event handler for each item group that you would like to modify in your ''onInitialize'' method. 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.
  
 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 a new type of wood, placing your item after the existing types of wood would make the most sense. 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 a new type of wood, placing your item after the existing types of wood would make the most sense.
Line 30: Line 36:
  
 <yarncode java [enable_line_numbers="true"]> <yarncode java [enable_line_numbers="true"]>
-private static final class_1761 ITEM_GROUP = FabricItemGroup.builder(new class_2960("tutorial", "test_group"))+private static final class_1761 ITEM_GROUP = FabricItemGroup.builder()
  .icon(() -> new class_1799(CUSTOM_ITEM))  .icon(() -> new class_1799(CUSTOM_ITEM))
 + .displayName(class_2561.method_43469("itemGroup.tutorial.test_group"))
 +        .entries((context, entries) -> {
 + entries.add(CUSTOM_ITEM);
 + })
  .build();  .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:+You can add entries to your item group within the ''entries'' callback method. Note that unlike vanilla item groups, where you can add items relative to existing items, you must add items to your own item group in order since there are no vanilla items to position your items relative to
 + 
 +It is important to set the display name, otherwise it will cause a crash. 
 + 
 +The next step is to register your item group.
  
 <yarncode java [enable_line_numbers="true"]> <yarncode java [enable_line_numbers="true"]>
-ItemGroupEvents.modifyEntriesEvent(ITEM_GROUP).register(content -> { +class_2378.method_10230(class_7923.field_44687, new class_2960("tutorial", "test_group"), ITEM_GROUP);
- content.add(CUSTOM_ITEM)+
-});+
 </yarncode> </yarncode>
  
 {{:tutorial:item_group_append_items.png?nolink&400|}} {{:tutorial:item_group_append_items.png?nolink&400|}}
tutorial/itemgroup.1686472439.txt.gz · Last modified: 2023/06/11 08:33 by mcrafterzz