Setup
Basics
- Conventions and Terminology
- Registries
- Development Tools
To have your ItemGroup
properly show up in the creative menu, use the FabricItemGroupBuilder
to create them:
public class ExampleMod implements ModInitializer { public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( new Identifier("tutorial", "general"), () -> new ItemStack(Blocks.COBBLESTONE)); public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( new Identifier("tutorial", "other")) .icon(() -> new ItemStack(Items.BOWL)) .build(); // ... }
Once FabricItemGroupBuilder#build
is called, your group will be added to the list of item groups in the creative menu.
Make sure you replace the arguments 1) you pass to the Identifier
constructor with your actual mod ID and the translation key you want to give your item group for localization 2) later on.
When creating a custom Item, call Item.Settings#group
on your settings and pass in your custom group:
public static final Item YOUR_ITEM = new Item(new Item.Settings().group(ExampleMod.ITEM_GROUP));
Call FabricItemGroupBuilder#appendItems
and pass any Consumer<List<ItemStack>>
. You can then add whatever stacks you want to the given list in some order. ItemStack.EMPTY
can be used to place empty spaces in your group.
public class ExampleMod implements ModInitializer { public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build( new Identifier("tutorial", "general"), () -> new ItemStack(Blocks.COBBLESTONE)); public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create( new Identifier("tutorial", "other")) .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), Potions.WATER)); stacks.add(ItemStack.EMPTY); stacks.add(new ItemStack(Items.IRON_SHOVEL)); }) .build(); // ... }
Identifier
constructor can only contain certain characters.namespace
& path
) can contain lowercase letters, numbers, underscores, periods, or dashes. [a-z0-9_.-]
path
) can also include slashes. [a-z0-9/._-]
InvalidIdentifierException
would be thrown!ItemGroup
would be itemGroup.mod_id.general