tutorial:itemgroup
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:itemgroup [2024/07/03 02:26] – solidblock | 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 | * adding your item into an existing item group | ||
| * create your own item group and add items | * create your own item group and add items | ||
| Line 16: | 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 28: | 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, | ||
| + | }); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | 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(); | ||
| + | } | ||
| + | } | ||
| </ | </ | ||
| Line 40: | Line 75: | ||
| < | < | ||
| - | private | + | public final class TutorialItemGroups { |
| - | .icon(() -> new class_1799(CUSTOM_ITEM)) | + | public |
| - | .displayName(class_2561.method_43469(" | + | .icon(() -> new class_1799(TutorialItems.CUSTOM_ITEM)) |
| + | .displayName(class_2561.method_43469(" | ||
| .entries((context, | .entries((context, | ||
| - | entries.add(CUSTOM_ITEM); | + | |
| - | }) | + | }) |
| - | .build(); | + | .build(); |
| + | } | ||
| </ | </ | ||
| Line 56: | Line 93: | ||
| < | < | ||
| - | // Since 1.21: | + | public final class TutorialItemGroups { |
| - | class_2378.method_10230(class_7923.field_44687, | + | // .... |
| + | |||
| + | public static void initialize() { | ||
| + | | ||
| + | class_2378.method_10230(class_7923.field_44687, | ||
| + | |||
| + | // Below 1.21: | ||
| + | class_2378.method_10230(class_7923.field_44687, | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| - | // Below 1.21: | + | Of course, you can directly register them when assigning the fields: |
| - | class_2378.method_10230(class_7923.field_44687, | + | < |
| + | 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.1719973566.txt.gz · Last modified: 2024/07/03 02:26 by solidblock