Class FabricItemGroupBuilder
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 searching
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.
-
Method Summary
Modifier and TypeMethodDescriptionappendItems
(BiConsumer<List<ItemStack>, ItemGroup> stacksForDisplay) Sets the item stacks of this item group, by having the consumer add them to the passed list.appendItems
(Consumer<List<ItemStack>> stacksForDisplay) Sets the item stacks of this item group, by having the consumer add them to the passed list.build()
Creates an instance of the ItemGroup.static ItemGroup
build
(Identifier identifier, Supplier<ItemStack> stackSupplier) This is a single method that makes creating an empty ItemGroup with an icon one call.static FabricItemGroupBuilder
create
(Identifier identifier) Creates a new item group builder.Sets an icon for the group.stacksForDisplay
(Consumer<List<ItemStack>> appender) Deprecated.
-
Method Details
-
create
Creates a new item group builder.- Parameters:
identifier
- the id of the ItemGroup, to be used as the translation key- Returns:
- a new builder
-
icon
Sets an icon for the group. This is displayed on the creative inventory tab.- Parameters:
stackSupplier
- the supplier that returns the item stack to be used as an icon- Returns:
- this builder
-
stacksForDisplay
Deprecated.This allows for a custom list of items to be displayed in a tab, this enabled tabs to be created with a custom set of items.- Parameters:
appender
- Add ItemStack's to this list to show in the ItemGroup- Returns:
- a reference to the FabricItemGroupBuilder
-
appendItems
Sets the item stacks of this item group, by having the consumer add them to the passed list. This bypassesItem.appendStacks(net.minecraft.item.ItemGroup, net.minecraft.util.collection.DefaultedList<net.minecraft.item.ItemStack>)
, and by default, does not append the stack to the search result. To add modded items, consider setting the group via item groups in addition to this, as that adds the item stack to the search result. See the creative inventory searching section for details.Calling this multiple times overwrites the previously set stacks.
- Parameters:
stacksForDisplay
- a callback that adds item stacks to the passed list- Returns:
- this builder
-
appendItems
Sets the item stacks of this item group, by having the consumer add them to the passed list. This bypassesItem.appendStacks(net.minecraft.item.ItemGroup, net.minecraft.util.collection.DefaultedList<net.minecraft.item.ItemStack>)
, and by default, does not append the stack to the search result. To add modded items, consider setting the group via item groups in addition to this, as that adds the item stack to the search result. See the creative inventory searching section for details.Compared to the other overload, this one also passes the new ItemGroup. This allows you to call
Item.appendStacks(net.minecraft.item.ItemGroup, net.minecraft.util.collection.DefaultedList<net.minecraft.item.ItemStack>)
yourself if you want.Calling this multiple times overwrites the previously set stacks.
- Parameters:
stacksForDisplay
- a callback that adds item stacks to the passed list- Returns:
- this builder
-
build
This is a single method that makes creating an empty ItemGroup with an icon one call. Items should be added using item settings. Useful for modded item-only group.- Parameters:
identifier
- the id of the ItemGroup, to be used as the translation keystackSupplier
- the supplier that returns the item stack to be used as an icon- Returns:
- an instance of the built ItemGroup
-
build
Creates an instance of the ItemGroup.- Returns:
- an instance of the built ItemGroup
-
appendItems(Consumer)