Jump to content

[Solved][1.12.2] Is it possible to remove a specific instance of an item from a creative tab


robmart

Recommended Posts

Let's say I wanted to get rid of the strength potion. I could of course do

Items.POTIONITEM.setCreativeTab(null);

but that would get rid of all of the other potions as well. Is there a better way to do this?

 

 

e: Also the title probably could have been worded better but the words escaped me ¯\_(ツ)_/¯

Edited by robmart
Link to comment
Share on other sites

There might be a clever way to do it, but it looks tricky. The key method is actually the getSubItems() method. It takes in a list that is provided by the creative tab gui and populates it with all the variants of the item. I'm not aware of a good Forge hook for it. Basically, Minecraft seems to be strongly coded such that all variants of an item are intended to go on the same creative tab().

 

I think the "easiest" way is to actually create your own extension of the creative tab GUI and use the GuiOpenEvent to replace the vanilla one with yours. In yours you could filter out the results of the getSubTypes() method in any way you wished.

  • Thanks 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

2 minutes ago, jabelar said:

There might be a clever way to do it, but it looks tricky. The key method is actually the getSubItems() method. It takes in a list that is provided by the creative tab gui and populates it with all the variants of the item. I'm not aware of a good Forge hook for it. Basically, Minecraft seems to be strongly coded such that all variants of an item are intended to go on the same creative tab().

 

I think the "easiest" way is to actually create your own extension of the creative tab GUI and use the GuiOpenEvent to replace the vanilla one with yours. In yours you could filter out the results of the getSubTypes() method in any way you wished.

That sounds good, I'll try experimenting.

 

e: Also, would would it be possible to remove all the potions and add the ones I want back? That just seems like less of a hassle.

Link to comment
Share on other sites

43 minutes ago, robmart said:

e: Also, would would it be possible to remove all the potions and add the ones I want back? That just seems like less of a hassle.

No, as I mentioned the vanilla coding is strongly inclined towards and "all or nothing". Basically the Item gets a creative tab and the getSubTypes() populates the list with all the variants. For your own Item classes you have full control over the getSubTypes() but not for the vanilla classes. The only publicly accessible control is at the Item level and even reflection won't help because the return values are coded right in the methods -- there are not fields that can be manipulated.

  • Thanks 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Just now, jabelar said:

No, as I mentioned the vanilla coding is strongly inclined towards and "all or nothing". Basically the Item gets a creative tab and the getSubTypes() populates the list with all the variants. For your own Item classes you have full control over the getSubTypes() but not for the vanilla classes. The only publicly accessible control is at the Item level and even reflection won't help because the return values are coded right in the methods -- there are not fields that can be manipulated.

Alright, thanks.

Link to comment
Share on other sites

@jabelar

For some reason the GuiOpenEvent doesn't seem to be doing anything.

I have this code as a test

@GameRegistry.ObjectHolder(Reference.MOD_ID)
@Mod.EventBusSubscriber(modid = Reference.MOD_ID)
@SuppressWarnings("unused")
public class CreativeTabHandler {

    @SubscribeEvent
    public void onGuiOpen(GuiOpenEvent event){
        event.setGui(new GuiChat("Test"));
    }
}

but it doesn't do anything. I've tried other things but I just can't seem to get the event to work. Am I doing something wrong?

 

P.S: Sorry for the constant barrage of messages.

Edited by robmart
Link to comment
Share on other sites

13 hours ago, diesieben07 said:

@EventBusSubscriber only works for static event handler methods.

I feel ashamed for making that mistake...

 

13 hours ago, jabelar said:

Also be careful with your test code as that will replace ALL GUIs with your GUI. You should probably test the GUI type before replacing with yours.

That was the point. Was going to change it after I confirmed that it worked.

Link to comment
Share on other sites

22 hours ago, jabelar said:

I think the "easiest" way is to actually create your own extension of the creative tab GUI and use the GuiOpenEvent to replace the vanilla one with yours. In yours you could filter out the results of the getSubTypes() method in any way you wished.

1

Right so I have my custom creative tab GUI and I've replaced the vanilla one with it. My only problem is that I can't seem to figure out *where* to filter the stuff out. In fact, I can't find where or how stuff is added to the tab in the first place. Would you mind pointing me in the right direction?

Link to comment
Share on other sites

You should learn to use the Call Hierarchy to figure out such things. I didn't know the answer but just used that to find out myself. Programmers don't usually know this stuff off the top of their head, but rather know how to use their IDE (I use Eclipse) to quickly confirm and follow code.

 

Anyway, in this case your creative tab class should have a method called displayAllRelevantItems() or if your class doesn't have it you should @Override it from the parent class. That method takes in a list as parameter that gets populated with the items, so you could just use standard list methods for filtering or removing items.

  • Thanks 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

1 hour ago, jabelar said:

You should learn to use the Call Hierarchy to figure out such things. I didn't know the answer but just used that to find out myself. Programmers don't usually know this stuff off the top of their head, but rather know how to use their IDE (I use Eclipse) to quickly confirm and follow code.

 

Anyway, in this case your creative tab class should have a method called displayAllRelevantItems() or if your class doesn't have it you should @Override it from the parent class. That method takes in a list as parameter that gets populated with the items, so you could just use standard list methods for filtering or removing items.

I try to do that but I'm a bit crap at it... Turns out this time I was just searching in the wrong place entirely lol.

 

Well, I got it all figured out now, thanks for the help.

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.