🇬🇧 English
🇬🇧 English
Appearance
🇬🇧 English
🇬🇧 English
Appearance
This page is written for:
1.21
This page is written for:
1.21
Item groups are the tabs in the creative inventory that store items. You can create your own item group to store your items in a separate tab. This is pretty useful if your mod adds a lot of items and you want to keep them organized in one location for your players to easily access.
It's surprisingly easy to create an item group. Simply create a new static final field in your items class to store the item group and a registry key for it, you can then use the item group event similarly to how you added your items to the vanilla item groups:
public static final RegistryKey<ItemGroup> CUSTOM_ITEM_GROUP_KEY = RegistryKey.of(Registries.ITEM_GROUP.getKey(), Identifier.of(FabricDocsReference.MOD_ID, "item_group"));
public static final ItemGroup CUSTOM_ITEM_GROUP = FabricItemGroup.builder()
.icon(() -> new ItemStack(ModItems.GUIDITE_SWORD))
.displayName(Text.translatable("itemGroup.fabric_docs_reference"))
.build();
// Register the group.
Registry.register(Registries.ITEM_GROUP, CUSTOM_ITEM_GROUP_KEY, CUSTOM_ITEM_GROUP);
// Register items to the custom item group.
ItemGroupEvents.modifyEntriesEvent(CUSTOM_ITEM_GROUP_KEY).register(itemGroup -> {
itemGroup.add(ModItems.SUSPICIOUS_SUBSTANCE);
itemGroup.add(ModItems.POISONOUS_APPLE);
itemGroup.add(ModItems.GUIDITE_SWORD);
itemGroup.add(ModItems.GUIDITE_HELMET);
itemGroup.add(ModItems.GUIDITE_BOOTS);
itemGroup.add(ModItems.GUIDITE_LEGGINGS);
itemGroup.add(ModItems.GUIDITE_CHESTPLATE);
itemGroup.add(ModItems.LIGHTNING_STICK);
// ...
});
You should see the item group is now in the creative inventory menu. However, it is untranslated - you must add a translation key to your translations file - similarly to how you translated your first item.
If you used Text.translatable
for the displayName
method of the item group builder, you will need to add the translation to your language file.
{
"itemGroup.fabric_docs_reference": "Fabric Docs Reference"
}
Now, as you can see, the item group should be correctly named: