robmart Posted March 27, 2018 Posted March 27, 2018 (edited) 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 March 28, 2018 by robmart Quote
jabelar Posted March 27, 2018 Posted March 27, 2018 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. 1 Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
robmart Posted March 27, 2018 Author Posted March 27, 2018 On 3/27/2018 at 3:43 PM, 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. Expand 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. Quote
jabelar Posted March 27, 2018 Posted March 27, 2018 On 3/27/2018 at 3:49 PM, 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. Expand 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. 1 Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
robmart Posted March 27, 2018 Author Posted March 27, 2018 On 3/27/2018 at 4:35 PM, 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. Expand Alright, thanks. Quote
robmart Posted March 27, 2018 Author Posted March 27, 2018 (edited) @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 March 27, 2018 by robmart Quote
jabelar Posted March 27, 2018 Posted March 27, 2018 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. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
robmart Posted March 28, 2018 Author Posted March 28, 2018 On 3/27/2018 at 7:42 PM, diesieben07 said: @EventBusSubscriber only works for static event handler methods. Expand I feel ashamed for making that mistake... On 3/27/2018 at 8:30 PM, 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. Expand That was the point. Was going to change it after I confirmed that it worked. Quote
robmart Posted March 28, 2018 Author Posted March 28, 2018 On 3/27/2018 at 3:43 PM, 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. Expand 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? Quote
jabelar Posted March 28, 2018 Posted March 28, 2018 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. 1 Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
robmart Posted March 28, 2018 Author Posted March 28, 2018 On 3/28/2018 at 3:26 PM, 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. Expand 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. Quote
Recommended Posts
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.