tutorial:itemgroup
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:itemgroup [2022/04/13 08:04] – map2fabricyarn daomephsta | tutorial:itemgroup [2023/09/28 21:15] – Use entries method for custom item group haykam | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Item Groups ====== | ====== Item Groups ====== | ||
- | ==== Creating a simple Item Group ==== | ||
- | To have your ''< | ||
- | < | ||
- | public class ExampleMod implements ModInitializer { | ||
- | public static final class_1761 ITEM_GROUP = FabricItemGroupBuilder.build( | + | //This is the 1.20+ version of this tutorial. For the 1.19 version, see [[tutorial: |
- | new class_2960(" | + | |
- | | + | |
- | public static final class_1761 OTHER_GROUP | + | So far, you have used ''/ |
- | new class_2960("tutorial", " | + | |
- | .icon(() -> new class_1799(class_1802.field_8428)) | + | ==== Adding to Item Groups ==== |
- | .build(); | + | |
- | // ... | + | 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 ''< |
- | } | + | |
+ | Next, you will have to create | ||
+ | |||
+ | < | ||
+ | ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content | ||
+ | content.add(CUSTOM_ITEM); | ||
+ | }); | ||
</ | </ | ||
- | Once '' | ||
- | Make sure you replace the arguments | + | The modification event also allows more fine-grained control such as placing your custom item in a specific location(eg. after of ''< |
- | === Adding your Items to your Item Group === | + | Items can be positioned relative |
- | When creating | + | |
- | < | + | For example, this event handler will place your mod's item after the oak door in the building blocks item group: |
- | public static final class_1792 YOUR_ITEM = new class_1792(new class_1792.class_1793().method_7892(ExampleMod.ITEM_GROUP)); | + | |
+ | < | ||
+ | ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { | ||
+ | content.addAfter(class_1802.field_8691, | ||
+ | }); | ||
</ | </ | ||
- | ==== Making | + | ==== Creating |
- | Call '' | + | |
- | < | + | |
- | 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 group. Your item group will be placed on a separate page of tabs, impacting its discoverability, and users may be confused if the item is not where similar items are in the creative inventory. |
- | new class_2960(" | + | |
- | () -> new class_1799(class_2246.field_10445)); | + | |
- | public | + | If you think that your own item group is needed, you can use the '' |
- | new class_2960(" | + | |
- | .icon(() -> new class_1799(class_1802.field_8428)) | + | < |
- | .appendItems(stacks -> { | + | private |
- | stacks.add(new class_1799(class_2246.field_10166)); | + | .icon(() -> new class_1799(CUSTOM_ITEM)) |
- | stacks.add(new class_1799(class_1802.field_8279)); | + | .displayName(Text.translatable(" |
- | | + | .entries((context, entries) -> { |
- | | + | |
- | stacks.add(new class_1799(class_1802.field_8699)); | + | |
}) | }) | ||
- | | + | .build(); |
- | // ... | + | |
- | } | + | |
</ | </ | ||
+ | |||
+ | You can add entries to your item group within the '' | ||
+ | |||
+ | It is important to set the display name, otherwise it will cause a crash. | ||
+ | |||
+ | The next step is to register your item group. | ||
+ | |||
+ | < | ||
+ | Registry.register(Registries.ITEM_GROUP, | ||
+ | </ | ||
+ | |||
{{: | {{: |
tutorial/itemgroup.txt · Last modified: 2023/10/01 03:21 by haykam