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 03:19] – solidblock | tutorial:itemgroup [2024/08/23 13:03] (current) – solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~REDIRECT> | ||
+ | |||
====== Item Groups ====== | ====== Item Groups ====== | ||
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: | ||
< | < | ||
- | public class ExampleMod implements ModInitializer | + | public class ExampleMod implements ModInitializer |
@Override | @Override | ||
public void onInitialize() { | public void onInitialize() { | ||
Line 35: | Line 42: | ||
}); | }); | ||
} | } | ||
+ | } | ||
</ | </ | ||
- | In practice, considering items you register | + | In practice, considering items you register |
+ | |||
+ | < | ||
+ | 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 ===== | ===== Create your own item group ===== | ||
Line 46: | 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 62: | 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.1719976794.txt.gz · Last modified: 2024/07/03 03:19 by solidblock