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 [2020/06/09 23:44] – formatting changes (newline -> same line brackets) draylar | tutorial:itemgroup [2023/03/02 10:58] – [Adding to Item Groups] Add information about group(ItemGroup) method in FabricItemSettings dayo05 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Item Groups ====== | ====== Item Groups ====== | ||
- | ==== Creating a simple Item Group ==== | ||
- | To have your '' | ||
- | <code java [enable_line_numbers=" | ||
- | public class ExampleMod implements ModInitializer { | ||
- | public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( | + | So far, you have used '' |
- | new Identifier(" | + | |
- | () -> new ItemStack(Blocks.COBBLESTONE)); | + | |
- | + | ||
- | public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( | + | |
- | new Identifier(" | + | |
- | .icon(() -> new ItemStack(Items.BOWL)) | + | |
- | .build(); | + | |
- | // ... | + | |
- | } | + | |
- | </ | + | |
- | Once '' | + | |
- | Make sure you replace the arguments ((Remember that the arguments you pass to the '' | + | ==== Adding |
- | === Adding | + | 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 vanilla item groups are stored in the ''< |
- | When creating a custom Item, call '' | + | |
- | <code java> | + | Next, you can simply use '' |
- | public | + | |
- | </code> | + | But if you want to put your custom item in other location(eg. after of ''< |
+ | |||
+ | Items can be positioned relative | ||
+ | |||
+ | For example, this event handler will place your mod's item after the oak door in the building blocks item group: | ||
+ | |||
+ | < | ||
+ | ItemGroupEvents.modifyEntriesEvent(class_7706.field_40195).register(content -> { | ||
+ | content.addAfter(class_1802.field_8691, | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | ==== Creating an 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 | ||
+ | |||
+ | If you think that your own item group is needed, you can use the '' | ||
+ | |||
+ | <yarncode | ||
+ | private | ||
+ | .icon(() -> new class_1799(CUSTOM_ITEM)) | ||
+ | .build(); | ||
+ | </ | ||
+ | |||
+ | You can use '' | ||
+ | |||
+ | < | ||
+ | ItemGroupEvents.modifyEntriesEvent(ITEM_GROUP).register(content -> { | ||
+ | content.add(CUSTOM_ITEM); | ||
+ | }); | ||
+ | </yarncode> | ||
- | ==== Making an Item Group display specific Items in a particular order ==== | ||
- | Call '' | ||
- | <code java [enable_line_numbers=" | ||
- | public class ExampleMod implements ModInitializer { | ||
- | |||
- | public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( | ||
- | new Identifier(" | ||
- | () -> new ItemStack(Blocks.COBBLESTONE)); | ||
- | |||
- | public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( | ||
- | new Identifier(" | ||
- | .icon(() -> new ItemStack(Items.BOWL)) | ||
- | .appendItems(stacks -> { | ||
- | stacks.add(new ItemStack(Blocks.BONE_BLOCK)); | ||
- | stacks.add(new ItemStack(Items.APPLE)); | ||
- | stacks.add(PotionUtil.setPotion(new ItemStack(Items.POTION), | ||
- | stacks.add(ItemStack.EMPTY); | ||
- | stacks.add(new ItemStack(Items.IRON_SHOVEL)); | ||
- | }) | ||
- | .build(); | ||
- | // ... | ||
- | } | ||
- | </ | ||
{{: | {{: |
tutorial/itemgroup.txt · Last modified: 2024/06/17 12:49 by solidblock