Jump to content

[SOLVED][1.19.4] How to order/place mod tabs inside the inventory?


JimiIT92

Recommended Posts

In my mod I add several new creative tabs, and I want them to be displayed in a specific order. Specifically, I register these tabs inside the CreativeModeTabEvent.Register event

@SubscribeEvent
public static void register(CreativeModeTabEvent.Register event) {
  BUILDING_BLOCKS = registerTab(event, "building_blocks", () -> new ItemStack(BLBlocks.RUBY_BLOCK.get()));
  COLORED_BLOCKS = registerTab(event, "colored_blocks", () -> new ItemStack(BLBlocks.YELLOW_CONCRETE_STAIRS.get()));
  NATURAL = registerTab(event, "natural", () -> new ItemStack(BLBlocks.HOLLOW_BIRCH_LOG.get()));
  FUNCTIONAL = registerTab(event, "functional", () -> new ItemStack(Items.PAINTING));
  REDSTONE = registerTab(event, "redstone", () -> new ItemStack(BLBlocks.COPPER_BUTTON.get()));
  TOOLS = registerTab(event, "tools", () -> new ItemStack(BLItems.EMERALD_PICKAXE.get()));
  COMBAT = registerTab(event, "combat", () -> new ItemStack(BLItems.KATANA.get()));
  FOOD_AND_DRINK = registerTab(event, "food_and_drink", () -> new ItemStack(BLItems.SASHIMI.get()));
  INGREDIENTS = registerTab(event, "ingredients", () -> new ItemStack(BLItems.RUBY.get()));
  SPAWN_EGGS = registerTab(event, "spawn_eggs", () -> new ItemStack(BLItems.COPPER_GOLEM_SPAWN_EGG.get()));
}

private static CreativeModeTab registerTab(CreativeModeTabEvent.Register event, String name, Supplier<ItemStack> iconSupplier) {
  return event.registerCreativeModeTab(new ResourceLocation(BlazersMod.MOD_ID, name),
                                       builder -> builder
                                       .icon(iconSupplier)
                                       .title(Component.translatable("itemGroup." + BlazersMod.MOD_ID + "." + name))
                                       .build());
}

and I thought they were displayed in this order, so the first mod tab would be building blocks, the next would be colored blocks etc...
However when I load the game they are misplaced. Specifically the first tab I see is the mod's spawn eggs tab, which is the last one registered, than the mod's ingredients tab and then the tools tabs, so isn't in the reverse registration order. If I intercept the CreativeModeTabEvent.BuildContents event to see when those tabs are populated I get the same wrong ordering, so it makes sense that in game they are ordered like this. Do I need to specify something to make them ordered in the same order as they are registered?

Edited by JimiIT92
solved

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

  • JimiIT92 changed the title to [SOLVED][1.19.4] How to order/place mod tabs inside the inventory?

Sure, the only difference is that I'm now passing the previous tab to the method I use to register all my tabs. So now I have this
 

BUILDING_BLOCKS = registerTab(event, "building_blocks", CreativeModeTabs.SPAWN_EGGS, () -> new ItemStack(BLBlocks.RUBY_BLOCK.get()));
COLORED_BLOCKS = registerTab(event, "colored_blocks", BUILDING_BLOCKS,()  -> new ItemStack(BLBlocks.YELLOW_CONCRETE_STAIRS.get()));
NATURAL = registerTab(event, "natural", COLORED_BLOCKS, () -> new ItemStack(BLBlocks.HOLLOW_BIRCH_LOG.get()));
FUNCTIONAL = registerTab(event, "functional", NATURAL, () -> new ItemStack(Items.PAINTING));
REDSTONE = registerTab(event, "redstone", FUNCTIONAL, () -> new ItemStack(BLBlocks.COPPER_BUTTON.get()));
TOOLS = registerTab(event, "tools", REDSTONE, () -> new ItemStack(BLItems.EMERALD_PICKAXE.get()));
COMBAT = registerTab(event, "combat", TOOLS, () -> new ItemStack(BLItems.KATANA.get()));
FOOD_AND_DRINK = registerTab(event, "food_and_drink", COMBAT, () -> new ItemStack(BLItems.SASHIMI.get()));
INGREDIENTS = registerTab(event, "ingredients", FOOD_AND_DRINK, () -> new ItemStack(BLItems.RUBY.get()));
SPAWN_EGGS = registerTab(event, "spawn_eggs", INGREDIENTS, () -> new ItemStack(BLItems.COPPER_GOLEM_SPAWN_EGG.get()));

where I pass the previous tab to all the registerTab methods.
So my register tab method now simply adds the provided the tab to the "afterTab" list parameter provided to the registerCreativeModeTab function

private static CreativeModeTab registerTab(CreativeModeTabEvent.Register event, String name, CreativeModeTab afterTab, Supplier<ItemStack> iconSupplier) {
  return event.registerCreativeModeTab(new ResourceLocation(BlazersMod.MOD_ID, name),
                                       List.of(),
                                       List.of(afterTab),
                                       builder -> builder
                                       .icon(iconSupplier)
                                       .title(Component.translatable("itemGroup." + BlazersMod.MOD_ID + "." + name))
                                       .build());
}

It would be cool if the ordering was automatic like it was before, but I guess is not the end of the world to provide an extra parameter 😅

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.