User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:itemgroup

Item Groups

Creating a simple Item Group

To have your ItemGroup properly show up in the creative menu, use the FabricItemGroupBuilder to create them:

  1. public class ExampleMod implements ModInitializer {
  2.  
  3. public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build(
  4. new Identifier("tutorial", "general"),
  5. () -> new ItemStack(Blocks.COBBLESTONE));
  6.  
  7. public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create(
  8. new Identifier("tutorial", "other"))
  9. .icon(() -> new ItemStack(Items.BOWL))
  10. .build();
  11. // ...
  12. }
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.

Adding your Items to your Item Group

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));

Making an Item Group display specific Items in a particular order

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.

  1. public class ExampleMod implements ModInitializer {
  2.  
  3. public static final ItemGroup ITEM_GROUP = FabricItemGroupBuilder.build(
  4. new Identifier("tutorial", "general"),
  5. () -> new ItemStack(Blocks.COBBLESTONE));
  6.  
  7. public static final ItemGroup OTHER_GROUP = FabricItemGroupBuilder.create(
  8. new Identifier("tutorial", "other"))
  9. .icon(() -> new ItemStack(Items.BOWL))
  10. .appendItems(stacks -> {
  11. stacks.add(new ItemStack(Blocks.BONE_BLOCK));
  12. stacks.add(new ItemStack(Items.APPLE));
  13. stacks.add(PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER));
  14. stacks.add(ItemStack.EMPTY);
  15. stacks.add(new ItemStack(Items.IRON_SHOVEL));
  16. })
  17. .build();
  18. // ...
  19. }

1)
Remember that the arguments you pass to the Identifier constructor can only contain certain characters.
Both arguments (the namespace & path) can contain lowercase letters, numbers, underscores, periods, or dashes. [a-z0-9_.-]
The second argument (the path) can also include slashes. [a-z0-9/._-]
Avoid using other symbols, else an InvalidIdentifierException would be thrown!
2)
The full translation key for the first example ItemGroup would be itemGroup.mod_id.general
tutorial/itemgroup.txt · Last modified: 2022/04/13 08:04 (external edit)