Architectury API (Fabric/Forge/NeoForge)

Architectury API (Fabric/Forge/NeoForge)

158M Downloads

[1.21.1] Creative Tabs and Creative Tab Items order is completely random

JimiIT92 opened this issue ยท 1 comments

commented

When registering some Creative Tabs, the order in which they appear in the Creative Menu is different from the order they are registered.

I'm using this method to register a Creative Tab

private static final DeferredRegister<CreativeModeTab> CREATIVE_TABS = DeferredRegister.create("modid", Registries.CREATIVE_MODE_TAB);

private static RegistrySupplier<CreativeModeTab> registerTab(final String name, final Supplier<ItemStack> iconSupplier, final Supplier<ItemLike>... content) {
        return CREATIVE_TABS.register(ResourceLocation.fromNamespaceAndPath("modid", name), Suppliers.memoize(() -> CreativeTabRegistry.create(
                builder -> builder
                        .title(Component.translatable("itemGroup.modid." + name))
                        .icon(iconSupplier)
                        .displayItems((context, entries) -> entries.acceptAll(Arrays.stream(content).map(x -> x.get().asItem().getDefaultInstance()).collect(Collectors.toSet())))
        )));
    }

And calling it like so

public static final RegistrySupplier<CreativeModeTab> BUILDING_BLOCKS = registerTab(
            "building_blocks",
            Suppliers.memoize(() -> Blocks.STRUCTURE_VOID.asItem().getDefaultInstance()),
            Suppliers.memoize(() -> Blocks.STRUCTURE_VOID)
    );
    
public static final RegistrySupplier<CreativeModeTab> FOOD = registerTab(
            "food",
            Suppliers.memoize(() -> Blocks.STRUCTURE_VOID.asItem().getDefaultInstance()),
            Suppliers.memoize(() -> Items.APPLE),
            Suppliers.memoize(() -> Items.GOLDEN_APPLE),
            Suppliers.memoize(() -> Items.CARROT)
    );

public static final RegistrySupplier<CreativeModeTab> COMBAT = registerTab(
            "combat",
            Suppliers.memoize(() -> Blocks.STRUCTURE_VOID.asItem().getDefaultInstance()),
            Suppliers.memoize(() -> Items.NETHERITE_SWORD)
    );

When launching the game I expect to see the tabs in this order:

BUILDING_BLOCKS
FOOD
COMBAT

However it seems like they are sorted alphabetically, so they appear like this

BUILDING_BLOCKS
COMBAT
FOOD

Also, the content inside the Creative Tab itself gets sorted randomly.
In the example above, the FOOD tab has 3 items: APPLE, GOLDEN_APPLE and CARROT.
The expected behavior is to find these items in this exact order in the Creative Tab. However this is not guaranteed and sometimes they get placed randomly (like CARROT, APPLE and GOLDEN_APPLE).

I don't know if that's a bug on the API side or there's something wrong in how the Tabs are created and/or the items are added to them

commented
  1. Are you sure that the tabs aren't just sorted by the tab id (alphabetically) by the loader?
  2. You are collecting the display items as a set, that's an unordered collection