Foreign ladies and gentle ladies and welcome back to another Forge modding tutorial for Minecraft 1.20 and in this tutorial we are going to be creating a creative tab so as I’m sure some of you are aware creative tabs have changed a lot recently from 1.19.2 to 1.19.3 I think They also changed a bit in 1.19.4 and now they’ve changed again in 1.20 and they’ve changed pretty massively again this time so let’s get started and I’ll show you how you can make one yourself and how we can add to a vanilla one so firstly we’re actually going to Create an initialization or a registry class for this because now you actually register creative tabs which is a really interesting concept because I wouldn’t really consider them a registry but they are now so perhaps what we use so same as with blocks and with items we Just call this our creative tab in it and in here we’re just same as before going to want a public static final deferred register if you don’t know what a deferred register is obviously you can check out my previous tutorials on items and blocks which you would kind of need to Watch if you’re going to add a creative tab anyways so I’m sure you already know what this is but if not go check those tutorials out now this will be of type creative mode tab as I’m sure you can guess and we’ll call it tabs and that is equal deferred register dot create Now here we usually do something like Forge registries Dot and then one of these now you see if we put creative mode tab in here it doesn’t pop up there’s also four treasures dot Keys which we’ll use in the future but once again creative tabs don’t pop up in there So how do we actually register a creative mode tab well you can actually see that there are three different options for what we can put in this create method so we can give it an iforged registry which would be the forge Registries dot Etc we can give it a resource key which is Like Forge restrees.keys dot whatever and you can also give it a resource location which is for example if you’re going to create a custom registry then you would give it the resource location of whatever you named that registry now vanilla actually has their own registry classes in a class called registries If you come in here you can see a bunch of different things but the important thing to note is that these are resource keys so we can just do Registries dot creative mode tab and that will work that’ll work perfectly fine obviously we need to give our mod ID of course And boom you see that works we don’t have any errors so fantastic from there we’re going to do same as we have with blocks and items we’re going to want the registry object of type creative mode tab I’m going to call mine example app is equal tabs dot register then we give It a name same as I’ve been saying before we don’t have spaces we don’t have special characters we just keep it A to Z numbers underscores forward slashes and dots but mine will just be example tap and then we can come down on a new Line and we want a supplier of a new creative mode tab but that’s actually not right so we don’t actually do a new something in this segment starts we actually do creative mode tab dot Builder and then on that Builder we can supply all of the different properties that are creative Mode tab should use so the first property and possibly the most important one is the title and effectively this will be whatever the name of the tab is when it shows up in the creative tabs tab selection screen so what we want here generally is to do a component Dot translatable and this Creates a text component that can be translated in your language file so for example our en underscore us.json we would put whatever is in here in that Json and it would get translated for us alternatively you can put a component.literal which will just be a literal string of your tab name Generally you don’t want to do this though because that means it can’t be translated which obviously isn’t very good and you would only use that for something like if it was just a number or something maybe then it wouldn’t need to be translated so yeah but we’ll keep it as component dot Translatable now you see there are actually other components in here as well some of which you can use for this if you want I’m not sure exactly what all of these do I’m only familiar with empty literal and translatable but I’m sure maybe some of the others could be useful I’m not sure But we’ll do translatable and in here we just want to give it a string now we do in the string item group and make sure you do a capital G well actually you don’t have to you don’t have to do it this way this is just what Vanilla does you’ll see here this is the Minecraft Dev plugin that’s doing this autocomplete here by the way and you will see that it’s showing me all of the existing ones that follow this schema so you’ll see all the vanilla ones here are using item group with a capital G That’s just what vanilla does um I guess you did you don’t have to do it like that you could just do like tab dot something I’m gonna stick with vanilla though and do kind of the vanilla thing so item group Dot and then effectively it’s just going To be the name of your tab once again so mine was example tab now something you will notice here is it’s a capital right and we said that you can’t have capitals now that is true except for keys inside of language files they can have any case you can have capitals or lowercase Generally you should have it lowercase but for some reason vanilla has an exception here where they use capitals I don’t really know why I think that’s just a mojank thing but obviously for your actual registry name here that must be lowercase it’s just the component the translation component here that can have caps Then moving on from the title we can specify other properties too and I’m not going to go through all of these different properties and you can kind of figure them out by yourself most of them should be fairly self-explanatory so for example you can set an icon you can tell It to have a search bar and you can tell it to have a search bar with a specific width you can say that it should be aligned to the right you can give it a background you can give hide the title you can say that there should be no Scroll bar you can give it a background location you can give it colors etc etc I’m just going to go through icon and display items so we’ll do icon first so I want the icon of mine to be using our example item here so all I’m going to do is say item init Dot example item and you’ll see that doesn’t work so let’s see what it’s asking for it is asking for a supplier of an item stack whereas we have given it a registry object of an item so if you do recall from our item tutorial so registry objects are just Suppliers so that that part matches technically however we’ve given it an item instead of an item stack and that’s because if we come in here you’ll see this registry object of an item so how do we get an item stack so there’s a few ways we can do that and The first maybe most obvious is just to literally create a normal supplier and do a new item stack and then just pass in our item item dot example item and we need to do dot get because that requires the actual item objects and that does work um To get rid of this error let’s just get rid of this error so we can much easier see what’s going wrong here and what’s fine we can just do dot build and that will build the Builder into the registry object so you see we have no errors now Well I do have this one and that will fix later when we create the translation key but you see that does work so the item stack asks for an item like which is just something that the item class inherits from but I don’t like to do it this way Because there is I would say a better way to define an item stack especially if it only has a singular item in it so what I like to do is for example item in it dot example item dot get and then colon colon get default instance So what does this do so what this does is this is still a supplier so this is actually something known as a method reference now this is a Java thing so I’m not going to go and explain what a method reference is I’ll leave a resource in the description to what a Method reference is if you are a bit confused because they are a little bit advanced effectively what this is doing is saying it’s saying A supplier like this or item in it got example item dot get dot get default instance it’s effectively doing this but instead of having this Lambda here We’re just putting these double colons which tells it that basically when it has this object um it will call this get default instance method when it’s ready is effectively what’s going on it’s it’s quite hard to explain but once you’ve used it a couple times you’ll understand exactly what it’s doing But yeah that’s how I like to do it this kit default instance method just creates the new item stack by the way it’s something that can be overridden in your item class if you need to do that so that’s why I like to use this one just in case you wanted some special Functionality on the default instance maybe you wanted to for example add some NBT to a default instance you would do that in here so that’s why I like to use that method instead of creating the item stack myself the next thing we need to do is actually add stuff to our Creative tab right so there’s a method for this called display items now you see here that this is a by consumer and it has these two parameters here that we don’t know what they are because they are unnamed so if we come into here you can see that this is the item Display parameters and the output so let’s name them we’ll go display params you can see that IntelliJ does actually give us names that it thinks might be relevant I’m just going to put display params and I’m just going to call this one output okay so effectively what we can do here is We can use these two different things to say what it should um how they should be displayed inside of our creative tab so we can do for example um like we can get stuff from the display params we can see if they have permission we can get the enabled Feature flags and we can see if it contains feature flag dot whatever it’s actually feature Flags isn’t it there you go we can see if it contains these different things and all of that but generally what you want to do here is use the output and all we do is we say output But accept and then we say the item that we want to add so for example we want to add our example item so we just do item in it dot example item and we need to dot get because it wants an item like instead of the actual registry object And boom you can do that for all of your different items right so output.accept item in it dot example block item dot get and that works fine however to do this for every single one of your items might be a little bit tedious and you might forget sometimes so I generally like to Do this a little bit different and I like to just create a list of items that I want to add to this and then just Loop through them and add them like that so I’m just going to quickly make a mock-up of how to do that and I’ll briefly explain the code afterwards Okay so I’ve gone ahead and added my method for doing this let’s go through and explain what I’ve done here so first of all you can see I’ve added this list of items here so this is the list of example tab items so what this is is Just a list of suppliers of something that extends item like so if you recall I mentioned item like is items also blocks are item likes so you can add a block to a tab as well which is a bit weird bearing mind blocks on items but it happens it happens So this is what this list is and you’ll see here I’ve added this method that says it’s public it’s static so we can call it from any class and we say that t is something that extends item and this returns a registry object of said item and we are calling this add to Tab this takes in a registry object of that t that we defined here and this is the item like we’re adding this to our list up here and then we’re just returning it and you’ll see in here in display items what I’ve done is I’m looping through This list and for each of those item likes in this list I’m saying that the output should accept that item like but we have to call Dot get because these are suppliers and then in my item in it I’m saying on each of these items I’ve surrounded this Items dot register call with a creative tab init dot add to tab which is this method right here and I’ve done that for the block item as well and effectively what this does is it adds those items to the tabs automatically now it’s going to sound like a lot and I’m fully aware that is going to sound quite complicated possibly so if that if you think that sounds too complicated then just don’t worry about it and just add them normally inside of this display items that’s perfectly fine and obviously there’s nothing stopping you from doing that However personally I find this a little bit cleaner I’m not personally a fan though of this whole method here so something I might want to do is just statically import this add to tab method so that that looks a bit cleaner there and if this was actually my own mod Right so if I was creating this as a proper mod I would probably just create a method that does this whole add to Tab and it does the items.register thing by itself right so that I don’t have to do this whole part every single time there’s just a method that does this part That would be great and maybe on the GitHub I’ll have a method that shows you this that kind of thing but for now I think this is fine obviously if you don’t want to do it like that you don’t have to you can do it like before as I Said that is completely up to you okay the next thing is how can we add to a vanilla tab so this is fairly simple really so we can do at mod Dodge event by subscriber we’re gonna say here inside of these brackets that the mod ID is tutorial Mod Dot mod ID oh by the way this needs to be at the top of your class I don’t think I said that as it needs to be above your class definition and we also need to say a bus is equal bus dot mod like that so what does this Do well in the items tutorial I briefly explained the whole uh deferred registry being added to the event bus if you can recall now effectively what this does is this tells uh Forge that that is this class is subscribing to that bus so when the bus has its events that fire right when It gets to a stop it’s saying that at this stop um this class has events that need to be put on that bus right so these events need to listen for that bus and we’re saying the bus that we want to listen to is the mod bus Now which pass you choose to listen to depends on what event you want to use the specific event that I’m going to be using in this tutorial is a mod event that’s just it is something it is so but you may also have Forge events for certain things as well And that is also the option here to add a value which would be like a dist um which I always forget what dist stands for but it stands for something and that’s basically the different side or the networking side that you’re on so if it’s client or dedicated server the Event that I’m going to be covering is just common so it’s on both sides so we don’t need to worry about that but how do we actually subscribe to this event the subscriber well it’s fairly simple and actually there’s several ways you can do this but I’m just going to be Showing you the easiest and I think the easiest to understand way and that is to use at a subscribe event and this will be public static void it’s very important that this is public it’s very important that this is static and it’s very important that this is void so Make sure you do have that exact um signature and what you call this method doesn’t really matter but I’m going to call this build contents and this needs to take in one parameter and that is the specific event that you want to listen to now the event that I Want to listen to is the build creative mode tab content event which is quite handful to say effectively what this does is we’re saying that this bus what happens here is Forge will look for classes that are annotated with this annotation it will look what Buffs this is Annotated with and it will tell that bus to look through this class and find methods that have the at subscribe event and it will take those methods it’ll first see if it can access them right so if they’re public static in their void and then it will check that it only Takes in this singular parameter which needs to be something that is an event the specific event here is the build creative mode tab event now you can actually see this influence something called imod event bus Which tells us that it is a mod event and not a forge Event you can also see that in the Java dock here you can see this event is fired on The Mod specific event bus and actually it’s only on The Logical client that’s something that I wasn’t aware of so that’s actually super interesting that it’s on The Logical client so we can Actually also specify a side here is Eagle disk dot client now you don’t need to do this by the way you don’t need to specify that it’s on the client that’s just something I like to do to say that if I come back to this in the Future I know not to you know put in server events in here because I know that this is for client stuff and not for Server stuff but anyways what do we need to do in this event to add to a vanilla tab so this is fairly simple really we just Say if event dot Tab Key get Tab Key is equal to creative mode tabs Dot and then whatever tab you want to check for for example building blocks so if the tab key is building blocks then we can say event dot accept and then we can add Whatever we want to that tab so we can add for example our example block to the building blocks so let’s do that let’s do item init dot example block item and boom that works now you see this does accept a supplier so we can just use the supplier version here instead of doing Dot get and that’s fine now what if we wanted to add a vanilla item to our tab now if we whatever reason we didn’t want to use this display items which I don’t know why you wouldn’t want to but let’s say we didn’t we can also do this for our Tab as well so we can say if event dots tab is equal example tab then we can add whatever we want to our Tab and we actually need to dot get here because if you recall this is a registry object which is a supplier So if the tab is our tab then we can say like event dot accept and we can maybe add a vanilla item to it right so we could say items Dot uh what do we want to add maybe we want to add the crossbow to our Tab and that would work You can use this this is kind of what we used to do in 1.19 point four and three I think and it works fine so you can do that instead of doing this display items like I could literally just take this part right here I could remove that display items and I Could just put it in here and obviously as long as I do event.accept and you see that does work right so those are interchangeable whichever one you do is up to you I’m going to leave it this way because this is the way that Ford recommends that you do it Um whether or not you listen to forge is completely up to you I wouldn’t say Forge are always the best in terms of their opinions especially when it comes from the higher ups but that’s completely something for a completely different time but yeah it’s up to you which way You decide to do it I’m just going to do it the way they recommend you do it so that I don’t get absolutely attacked for it that’s pretty much it and there is one thing which some of you may have noticed some of you may not have noticed But what you need to do is you need to register the Deferred register which is something we haven’t done yet and obviously if we didn’t do that then we just wouldn’t it wouldn’t work so we need to just do creative tab in it not tab dot register fairly simple now I Am just going to add this to our language file as well so let’s come in there and let’s just say that this is the example tab now you probably won’t have you know that thing come up so obviously you can just do it manually it’s just a great Thing about the Minecraft Dev plugin that you can have it done automatically for you but yeah that’s pretty much it well that is it so let’s run the game all right everyone so we’re in the game now let’s go first test if our item is added to the building blocks right if Our block is added in here so we’ll scroll down to the bottom and boom you’ll see our block is in the building blocks now there are also methods by the way to put it in a specific location I think you can say I don’t remember exactly how you do it let’s let’s mess Around with the code for a quick second here and see if we can find how you do that okay here you go so there is the method for get entries now you see this is a mutable hashed linked map which means that we can mutate it so we can Say event.get entries and you can say like put after I put before put first so say for example we could put after let’s say we wanted to put it after Acacia log right so we would do items dot Acacia log dot default instance so let’s just do that And we need to Doc uh get dot get default instance and then it wants a tab visibility do we need a tab visibility we do add visibility dot let’s just do a parent and search tabs and if we do that and if we re-ran the game in theory that Should put it after Acacia log and if we come into here we should see it’s after the AK Shield log and it is so that does actually um work like that as well and that should be in the search bar as well be in the exact same place so that’s a Pretty cool thing you can do now the keynote of you will notice that we do have this tab thing up here so we can select between the different tabs obviously I don’t know why this button is active but it is Forge moment and you’ll see our example tab here And it’s got our example item it’s got our example block and it’s got the crossbow and uh yeah that’s pretty much it so it’s obviously got our name it’s got our icon here and it’s scrollable we didn’t say to have a search bar but maybe we would want a search bar in Which case we would just say with search bar and you could specify a specific width of like 200 but um I assume there’s a default width that comes with this um yeah the default width is 89 which is probably this width here is that about 89 um yeah probably I would say that’s About 89. and yeah that’s that’s it um for Creative tabs so I hope you found it useful if you’re having any problems be sure to join my Discord server which is linked in the description of this video and um yeah obviously give it a like if you Found it useful and subscribe so you know when I post the next one I don’t actually know what the next tutorial is going to be on right now probably tools and armor Maybe uh we’ll we’ll see I haven’t decided yet so it may be something completely different And uh yeah I will see you then good bye Video Information
This video, titled ‘1.20 Minecraft Forge Modding Tutorial – Creative Tabs’, was uploaded by TurtyWurty on 2023-06-19 17:30:02. It has garnered 2038 views and 57 likes. The duration of the video is 00:30:10 or 1810 seconds.
In this video, I show you how to create a creative tab and add our items to it as well as how you can add your items to vanilla creative tabs too.
In the next video, we will create a full set of tools and armour. Remember, if you have any problems, please join the discord that is linked below!
Links: Patreon: https://www.patreon.com/turtywurty Discord: https://discord.gg/BAYB3A38wn Github: https://github.com/DaRealTurtyWurty/1.20-Tutorial-Mod
Method References: Oracle: https://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html bonding: https://www.baeldung.com/java-method-references JavaTPoint: https://www.javatpoint.com/java-8-method-reference GeeksForGeeks: https://www.geeksforgeeks.org/method-references-in-java-with-examples/
Chapters: 0:00 – Intro 1:00 – DeferredRegistry 3:25 – RegistryObject 4:15 – CreativeModeTab builder 12:45 – Adding items to your tab 15:00 – How I would simplify this 18:20 – Adding to an existing tab 26:05 – Registering the DeferredRegister 26:20 – Translation files 26:45 – Specific tab item placement 28:15 – Testing 29:30 – Outro