Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JimiIT92 opened this issue Sep 9, 2024 · 1 comment

Comments

@JimiIT92
Copy link

JimiIT92 commented Sep 9, 2024

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

@shedaniel
Copy link
Member

  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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants