Class FabricItemGroupBuilder

java.lang.Object
net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder

public final class FabricItemGroupBuilder extends Object
A builder for ItemGroup. Item groups are used to group items in the creative inventory.

Example of creating an empty group (recommended for modded item-only group):


 MY_GROUP = FabricItemGroupBuilder.build(
 	new Identifier("my_mod", "example_group"),
 	() -> new ItemStack(MY_ITEM);
 );
 // Use item settings to assign a group. Otherwise, it won't appear on creative inventory
 // search result.
 MY_ITEM = new Item(new Item.Settings().group(MY_GROUP));
 

Example of creating a group with vanilla item stacks:


 ItemGroup myGroup = FabricItemGroupBuilder.create(new Identifier("my_mod", "group_2"))
 	.icon(Items.STONE::getDefaultStack)
 	.appendItems((stacks) -> {
 	   stacks.add(new ItemStack(Items.STONE));
 	   stacks.add(new ItemStack(Items.COBBLESTONE));
 	})
 	.build();
 

Creative inventory search is implemented as a special item group. Adding items with the builder by default does not add them to the search result; to make the item searchable, set the item group via Item.Settings.group(ItemGroup) as well. If there are multiple searchable item stacks of the item (such as colored variants or ones with different NBT), override Item.appendStacks(ItemGroup, DefaultedList) on your item as well. This should be called by appendItems(BiConsumer) to actually add items to your item group.