tutorial:itemgroup
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:itemgroup [2023/06/11 08:46] – Update to 1.20 mcrafterzz | tutorial:itemgroup [2024/08/23 13:03] (current) – solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~REDIRECT> | ||
+ | |||
====== Item Groups ====== | ====== Item Groups ====== | ||
//This is the 1.20+ version of this tutorial. For the 1.19 version, see [[tutorial: | //This is the 1.20+ version of this tutorial. For the 1.19 version, see [[tutorial: | ||
- | So far, you have used ''/ | + | So far, you have used ''/ |
+ | * adding your item into an existing item group | ||
+ | * create | ||
- | ==== Adding to Item Groups | + | 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 ''< | 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 ''< | ||
Line 12: | Line 18: | ||
< | < | ||
- | ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { | + | public class ExampleMod implements ModInitializer { |
- | content.add(CUSTOM_ITEM); | + | @Override |
- | }); | + | public void onInitialize() { |
+ | | ||
+ | content.add(TutorialItems.CUSTOM_ITEM); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
</ | </ | ||
Line 24: | Line 35: | ||
< | < | ||
- | ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { | + | public class ExampleMod implements ModInitializer { |
- | content.addAfter(class_1802.field_8691, | + | @Override |
- | }); | + | public void onInitialize() { |
+ | | ||
+ | content.addAfter(class_1802.field_8691, | ||
+ | }); | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | ==== Creating an Item Group ==== | + | In practice, considering items you register may be in large quantities, it's recommended to place then in a particular method, instead of directly in your '' |
+ | |||
+ | < | ||
+ | public final class TutorialItems { | ||
+ | // [...] | ||
+ | |||
+ | 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 in your '' | ||
+ | < | ||
+ | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | TutorialItems.registerToVanillaItemGroups(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Create your own item group ===== | ||
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, | 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, | ||
Line 36: | Line 75: | ||
< | < | ||
- | private | + | public final class TutorialItemGroups { |
- | .icon(() -> new class_1799(CUSTOM_ITEM)) | + | public |
- | .displayName(Text.translatable(" | + | .icon(() -> new class_1799(TutorialItems.CUSTOM_ITEM)) |
- | .build(); | + | .displayName(class_2561.method_43469(" |
+ | | ||
+ | entries.add(TutorialItems.CUSTOM_ITEM); | ||
+ | }) | ||
+ | | ||
+ | } | ||
</ | </ | ||
+ | |||
+ | You can add entries to your item group within the '' | ||
It is important to set the display name, otherwise it will cause a crash. | It is important to set the display name, otherwise it will cause a crash. | ||
- | The next step is to register your itemGroup. | + | The next step is to register your item group. |
< | < | ||
- | Registry.register(Registries.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, new class_2960(" | ||
+ | } | ||
+ | } | ||
</ | </ | ||
- | You can use '' | + | 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, | ||
+ | | ||
+ | }) | ||
+ | .build()); | ||
+ | |||
+ | public static void initialize() { | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | Remember to statically load the class in your '' | ||
< | < | ||
- | ItemGroupEvents.modifyEntriesEvent(ITEM_GROUP).register(content -> { | + | public class ExampleMod implements ModInitializer { |
- | content.add(CUSTOM_ITEM); | + | @Override |
- | }); | + | public void onInitialize() { |
+ | | ||
+ | } | ||
+ | } | ||
</ | </ | ||
+ | |||
+ | :!: The screenshot below is outdated. | ||
{{: | {{: |
tutorial/itemgroup.1686473197.txt.gz · Last modified: 2023/06/11 08:46 by mcrafterzz