tutorial:itemgroup
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:itemgroup [2022/04/13 08:04] – map2fabricyarn daomephsta | tutorial:itemgroup [2024/08/23 13:03] (current) – solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~REDIRECT> | ||
+ | |||
====== Item Groups ====== | ====== Item Groups ====== | ||
- | ==== Creating a simple Item Group ==== | + | |
- | To have your ''< | + | //This is the 1.20+ version of this tutorial. For the 1.19 version, see [[tutorial: |
+ | |||
+ | So far, you have used ''/ | ||
+ | * adding your item into an existing item group | ||
+ | * create your own item group and add items | ||
+ | |||
+ | All items added to any group will also be searchable within the creative inventory. | ||
+ | |||
+ | ===== Add items into existing 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 registry keys of vanilla item groups are stored in the ''< | ||
+ | |||
+ | Next, you will have to create | ||
< | < | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { | ||
+ | content.add(TutorialItems.CUSTOM_ITEM); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
- | public static final class_1761 ITEM_GROUP = FabricItemGroupBuilder.build( | + | The modification event also allows more fine-grained control such as placing your custom item in a specific location(eg. after of ''< |
- | new class_2960(" | + | |
- | () -> new class_1799(class_2246.field_10445)); | + | |
- | public static final class_1761 OTHER_GROUP = FabricItemGroupBuilder.create( | + | 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. |
- | | + | |
- | .icon(() -> new class_1799(class_1802.field_8428)) | + | For example, this event handler will place your mod's item after the oak door in the building blocks item group: |
- | | + | |
- | | + | < |
+ | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | | ||
+ | content.addAfter(class_1802.field_8691, TutorialItems.CUSTOM_ITEM); | ||
+ | | ||
+ | | ||
} | } | ||
</ | </ | ||
- | Once '' | ||
- | Make sure you replace the arguments ((Remember that the arguments you pass to the '' | + | In practice, considering items you register may be in large quantities, it's recommended |
- | === Adding your Items to your Item Group === | + | < |
- | When creating a custom Item, call ''< | + | public final class TutorialItems { |
- | < | + | // [...] |
- | public | + | |
+ | public static void registerToVanillaItemGroups() { | ||
+ | ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { | ||
+ | content.addAfter(class_1802.field_8691, | ||
+ | }); | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | + | Then, remember to refer to that method | |
- | ==== Making an Item Group display specific Items in a particular order ==== | + | < |
- | Call '' | + | |
- | < | + | |
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | TutorialItems.registerToVanillaItemGroups(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
- | public static final class_1761 ITEM_GROUP | + | ===== Create your own item group ===== |
- | new class_2960(" | + | |
- | () -> new class_1799(class_2246.field_10445)); | + | |
- | | + | 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, |
- | new class_2960(" | + | |
- | .icon(() -> new class_1799(class_1802.field_8428)) | + | If you think that your own item group is needed, you can use the '' |
- | .appendItems(stacks -> { | + | |
- | stacks.add(new class_1799(class_2246.field_10166)); | + | < |
- | stacks.add(new class_1799(class_1802.field_8279)); | + | public final class TutorialItemGroups { |
- | | + | |
- | | + | .icon(() -> new class_1799(TutorialItems.CUSTOM_ITEM)) |
- | stacks.add(new class_1799(class_1802.field_8699)); | + | .displayName(class_2561.method_43469(" |
+ | .entries((context, entries) -> { | ||
+ | | ||
}) | }) | ||
.build(); | .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. | ||
+ | |||
+ | < | ||
+ | public final class TutorialItemGroups { | ||
+ | // .... | ||
+ | | ||
+ | public static void initialize() { | ||
+ | // Since 1.21: | ||
+ | class_2378.method_10230(class_7923.field_44687, | ||
+ | | ||
+ | // Below 1.21: | ||
+ | class_2378.method_10230(class_7923.field_44687, | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Of course, you can directly register them when assigning the fields: | ||
+ | < | ||
+ | public final class TutorialItemGroups { | ||
+ | public static final class_1761 TEST_GROUP = class_2378.method_10230(class_7923.field_44687, | ||
+ | .icon(() -> new class_1799(CUSTOM_ITEM)) | ||
+ | .displayName(class_2561.method_43469(" | ||
+ | .entries((context, | ||
+ | entries.add(TutorialItems.CUSTOM_ITEM); | ||
+ | }) | ||
+ | .build()); | ||
+ | | ||
+ | public static void initialize() { | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Remember to statically load the class in your '' | ||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | TutorialItemGroups.initialize(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | :!: The screenshot below is outdated. | ||
+ | |||
{{: | {{: |
tutorial/itemgroup.1649837059.txt.gz · Last modified: 2022/04/13 08:04 by daomephsta