Fix custom creative tabs with search listing all items instead of just their own.

This commit is contained in:
LexManos committed 2024-08-01 17:21:35 -07:00
1 parent 72f98dc4a3
commit decaace84a
4 files changed
+39 -18

No files matched your search

@@ -16,6 +16,7 @@ import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.DyeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
@@ -32,6 +33,8 @@ public class CreativeModeTabTest {
private static final ResourceKey<CreativeModeTab> LOGS = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "logs"));
private static final ResourceKey<CreativeModeTab> STONE = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "stone"));
private static final ResourceKey<CreativeModeTab> COLORS = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "colors"));
private static final ResourceKey<CreativeModeTab> SEARCH = ResourceKey.create(Registries.CREATIVE_MODE_TAB, ResourceLocation.fromNamespaceAndPath(MOD_ID, "search"));
public CreativeModeTabTest() {
if (!ENABLED)
@@ -58,7 +61,8 @@ public class CreativeModeTabTest {
})
.build());
helper.register(STONE, CreativeModeTab.builder().icon(() -> new ItemStack(Blocks.STONE))
helper.register(STONE, CreativeModeTab.builder()
.icon(() -> new ItemStack(Blocks.STONE))
.title(Component.literal("Stone"))
.withLabelColor(0x0000FF)
.displayItems((params, output) -> {
@@ -67,16 +71,29 @@ public class CreativeModeTabTest {
output.accept(new ItemStack(Blocks.DIORITE));
output.accept(new ItemStack(Blocks.ANDESITE));
})
.withTabsAfter(CreativeModeTabs.BUILDING_BLOCKS)
.withTabsBefore(LOGS)
.build());
helper.register(ResourceLocation.fromNamespaceAndPath(MOD_ID, "colors"), CreativeModeTab.builder().title(Component.literal("Colors"))
helper.register(COLORS, CreativeModeTab.builder()
.title(Component.literal("Colors"))
.displayItems((params, output) -> {
for (DyeColor color : DyeColor.values())
output.accept(DyeItem.byColor(color));
})
.withTabFactory(CreativeModeColorTab::new)
.withTabsBefore(CreativeModeTabs.COLORED_BLOCKS)
.withTabsBefore(STONE)
.build()
);
helper.register(SEARCH, CreativeModeTab.builder()
.title(Component.literal("Search"))
.icon(() -> new ItemStack(Items.BOOKSHELF))
.displayItems((params, output) -> {
for (DyeColor color : DyeColor.values())
output.accept(DyeItem.byColor(color));
})
.withTabsBefore(COLORS)
.withSearchBar()
.build()
);