Skip to content

Instantly share code, notes, and snippets.

@gigaherz
Last active March 11, 2023 15:17
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gigaherz/c94a40311ed974349bbda8699b6fe085 to your computer and use it in GitHub Desktop.
Save gigaherz/c94a40311ed974349bbda8699b6fe085 to your computer and use it in GitHub Desktop.

New tab

Use the CreativeModeTabEvent.Register event to register your tab, the items will appear in the order you declare them. The accept method has an optional parameter to specify if the items also appear in the search tab or not. Defaults to appearing in both.

    public static CreativeModeTab MY_TAB;

    private void registerTabs(CreativeModeTabEvent.Register event)
    {
        MY_TAB = event.registerCreativeModeTab(new ResourceLocation(MODID, "main_tab"), builder -> builder
                .icon(() -> new ItemStack(ITEM1.get()))
                .title(Component.translatable("tabs.modid.main_tab"))
                .displayItems((featureFlags, output, hasOp) -> {
                    output.accept(ITEM1.get());
                    output.accept(ITEM2.get(), CreativeModeTab.TabVisibility.SEARCH_TAB_ONLY);
                })
        );
    }

Add to existing tab

Use the CreativeModeTabEvent.BuildContents event to register your tab, the items will appear in the order you declare them. The accept method has an optional parameter to specify if the items also appear in the search tab or not. Defaults to appearing in both. You can insert ordered by using event.getEntries().putBefore or putAfter.

    private void addItemsToTabs(CreativeModeTabEvent.BuildContents event)
    {
        if (event.getTab() == CreativeModeTabs.TOOLS_AND_UTILITIES)
        {
            event.accept(ITEM1);
            event.accept(ITEM2, CreativeModeTab.TabVisibility.SEARCH_TAB_ONLY);
        }
    }
@dcox45
Copy link

dcox45 commented Jan 10, 2023

Where would you recommend adding these functions? Also, where are we expected to call these functions?

@gigaherz
Copy link
Author

@dcox45 Those are event handlers, you put them wherever you like to put the event handlers. In my mods they are in the main mod class.

@BlueSmithStudio
Copy link

Is there something that has changed since the last versions? I'm trying to add my items to an existing tab but I can't get it to work for me?!
I'm in version 44.1.0. The item is registered and I can /give them to myself but it doesn't show up in the creative tabs...

@RageAShadey
Copy link

after adding to an existing tab it says that there is "no usage" how do I fix that?

@gigaherz
Copy link
Author

Sounds like you forgot to register the event handler.

See this page for more info: https://forge.gemwire.uk/wiki/Events

events diagram

@RageAShadey
Copy link

RageAShadey commented Jan 19, 2023

Yea you're right. In the updated forge mdk it automatically places the CreativeModeTabs in the right section it's supposed to be. I was putting it in the wrong spot and the proceeding not to correctly call it. funny thing is i posted this question to you literally seconds after you got off. yesterday. XD

@dcox45
Copy link

dcox45 commented Feb 1, 2023

I got mine working! For anybody else stuck, you can check out my project's main: https://github.com/dcox45/twmcmod

@criminalduck
Copy link

@gigaherz Hey, how do you do the lang of the tab, because i tried using "itemGroup.modid.item": "Name" but it didnt work, do you know how?

@criminalduck
Copy link

@gigaherz Hey, how do you do the lang of the tab, because i tried using "itemGroup.modid.item": "Name" but it didnt work, do you know how?
Nvm, I found it, I thought the .title was the registry name not the actual name, sorry for bothering

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment