Jump to content

1.18.1 sorting custom items in vanilla creativeTabs


Jeuxt

Recommended Posts

Here is my code 

public static final RegistryObject<Item> Example = Items.register("example",() -> new Item(new Item.Properties().food(Example).tab(CreativeModeTab.TAB_FOOD)));

anyone know how to put it after apple in minecraft CreativeModeTab.TAB_FOOD?

Link to comment
Share on other sites

  • 4 weeks later...

I don't think that's possible easily without accessing the vanilla classes (using an AT and some Mixins).
If 1.18 is not a requirement (quick note: 1.18 is no longer supported), you can upgrade to 1.20.x and listen for the BuildCreativeModeTabContentsEvent.
 

In this event you can check when a Creative Tab is being "constructed" (either a Vanilla Tab or a Modded Tab) and decide if you want to do something with it (tipically add an Item to that tab).

In your case you could add your Item before the vanilla Apple using the putBefore / putAfter  methods.

For instance, here I'm adding an Apple before the Bone Meal in the Ingredients Tab
 

@SubscribeEvent
public static void onTabBuildContents(final BuildCreativeModeTabContentsEvent event) {
	final ResourceKey<CreativeModeTab> tab = event.getTabKey();
  	if(tab.equals(CreativeModeTabs.INGREDIENTS)) {
      event.getEntries().putBefore(Items.BONE_MEAL.getDefaultInstance(), Items.APPLE.getDefaultInstance(), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
    }
}

And in game, if we open the Ingredients tab, we get this result

spacer.png

 

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

  • 2 weeks later...

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.