Foreign ladies and gentle ladies and welcome back to the second episode of the Ford 1.20 tutorial for Minecraft modding in this tutorial we’re going to be adding items so let’s get started so the first thing I’m going to do is come into our project coming to the main Package and create a new package and I like to call this init and well yes I am British it does not mean the same thing that British in it means it just means uh it’s short for initialization is what I like to call it you can also call it something like Registry if you want or you know Registries or you could even go you know all the way into say English just going to test my planning initialization that’s wrong um but that’s why I call it in it because it’s so much simpler and this is basically where we’re going to initialize or Register all of our items blocks block entities you know menus etc etc that’s all going to happen inside of that package so since we’re adding items you can take a guess at what the item class is going to be called or the init class is going to be called It’s going to be called item in it amazing some other tutorials you might find we’ll call this mod items for example or also like item registry or you might see something like the mod name and then items so for example it might be like tutorial items or like if It was my mod it would be industria items you might see that too generally I just prefer item in it it’s simple it’s easy to say it’s quick um it’s obvious of what it is that’s just what I like to call it but whatever you call it is completely up to you you Don’t have to call it the same thing as me of course and in here we just want a public static final deferred register and this is generic so this will take a type of item since we’re going to be registering items and I’ll just call that items Is equal to deferred register dot create then we pass in Forge Registries dot items and then we pass in our mod ID so we made this a constant in our main class in the previous tutorial as you can see here so we can just do tutorial mode dot mod ID Now if you can’t do that then that is probably because you accidentally made this private or protected you need to make sure this is public so that we can access it anywhere inside of our code so with that done um let’s explain what a deferred Register is or at least I’ll try to give you a basic explanation so basically it’s just a map of string to A supplier of an item or supplier of whatever this object here is so since we’re registering items this will only allow us to register something that is of type item We create it with the forge registry this means it will automatically populate our registered items into that registry and it populates them in there with our mod ID so it doesn’t do the wrong mod for example and that means that every time we register an item we don’t have to say What the minor ID is because the mod ID is specified already in the Deferred register so it’s basically a registry we’re going to be registering items to the registry and then you can also get items from the registry Etc so to create an object that can be Registered we want to once again to go to public static final and by the way I’m just doing psf to do that that’s just a IntelliJ shortcut it’s quite handy and so public static final and this will be since it’s an object that we want to register we simply call it registry Object nice and simple right and this is of type you guessed it item because we’re registering items now this will be called whatever the name of your item is let’s say we’re registering a apple we would just call this apple if we’re registering a ruby we’ll just call it Ruby different registering a Diamond sword we’ll just call it diamond sword Etc I think you get the point I’m just going to be calling this an example item I’ll obviously underscores instead of spaces just general kind of java stuff there um by the way I probably should have prefaced the first tutorial with this And I might added I might value the clip during the editing but it is very important that you do have at least a very least a basic understanding of java not JavaScript Java because so many people seem to think they’re the same thing and that that pains me every single time but Java It’s very important that you have at least basic understanding of java I will have links in the description to some places where you can learn Java just don’t expect it to be quick okay learning a language is not a quick process but you have to do it if you Want to make a decent mod that is as simple as that but anyways that’s enough rambling about learning Java I’m sure so many people have already heard it a billion times so all we do here is we set this equal to and then we need to register it so as You can see we have our deferred register here we called it items so what we do is we do items dot register and then we put the name which is a string of course so this needs to be all lowercase no spaces no special characters all you can have in terms of Characters are slashes I think you can have dots you can have numbers obviously letters a to z and you can have underscores instead of spaces so for example once again we’ll go back to the previous examples you would do apple or lowercase instead of apple right this would be wrong this would Give you an error and the game would not load so you need to make sure it’s lowercase and also no spaces so for example if you accidentally put in a space there that wouldn’t work the game just wouldn’t load so it’s important that you make sure there’s no spaces no special characters Etc Now for us we have an example item so you might think obviously example space item um but obviously not because as we just said you can’t have spaces so you just replace a space with an underscore now this is only the registering name this is not the name that shows up in the Game this is the name for example you would see when you do slash give at s um Minecraft colon apple right that’s the name that shows up there it doesn’t show up as the actual name in the inventory and we’ll do we’ll do that part later Um and likewise you don’t need to put your mod ID here so for example we have Minecraft colon Apple we don’t need to do that because Forge already does that here we passed in our mod ID up here which is fantastic so then we actually need to say what This item is going to be is it just going to be a plain old item is it going to be a block item so it’s going to place a block um is it going to be a sword item so will it function as a sword and we can specify these different classes to Denote what it’s going to be so for us we’re just going to make a normal plain old item so it can’t do anything special for example um what’s a plain old item in Minecraft um a nautilus shell right it isn’t it doesn’t do anything it’s just an item uh It has recipes of course but that’s completely unrelated to the class that’s just a data pack thing so what we do here is we do double brackets so as we’re starting a Lambda and this will be a supplier of the item class right so we’re going To make a new instance of this so we’re going to just do a new item and you’ll see um IntelliJ already shows us all of the classes we could use here and you can also make your own which we’ll cover in the future but as you can See the top one is just item which is what we want we just want a plain old item now if we tried to do that that won’t work that’ll give us an error and it says the expected one argument but found zero and that’s because we need to say What properties this item will have for example does it have durability does it have um is it a food for example does it um what other properties are there there’s tons of other properties and we’ll go through them in a second so inside of these double brackets here Obviously make sure you’re in the side of the right brackets you want to do a new item dot properties and that will work but that’s all we need so I like to just put this Lambda on a new line as well by the way and you can change stuff onto this right This uses the Builder pattern so we can do item dot properties and then after these double brackets you can do Dot and then pass in any different property that you want to add to it you see there’s only a few so it’s not that complicated And we can set for example a stack size let’s do that so let’s say a stack size we’re going to put 16. we’ll come out of those brackets we can do Dot and then add another thing onto it so we can make it a food for example so we’ll do dot Food and we can do a new food properties right um food food properties dot Builder there you go and we can say that it has a nutrition of five um half jump sticks right we can say it has a saturation or 0.2 and then we can build our Food properties dot Builder boom it’s now a food and I’ll see you can new line this to make it more understandable and then we can do something else so we can go onto it again dot we can say that it has a rarity of rarity.epic and you can continue and Continue and continue of course you can set like feature flags for example right so that’s what Minecraft did for 1.19.4 when they were adding features locked behind these settings um that would be a feature flag thing um but we’re obviously not going to use it’s not really a modded thing but you Can use it if you want and just note that it is there and obviously add any properties you want and you don’t have to use these ones these are just what I’m going to be doing as an example so you see I’ve also made this a food just thought I might as Well do two tutorials in one because food isn’t any different really you can also add effects on here I guess since I’m doing food I might as well talk about effects so first of all let’s put these on a new line as well so we kind of have some consistency there So you could do for example effect and then just a supplier of a new mob effect instance and this will ask you for a bunch of stuff so I’ll ask you first for the mob effect which I think is um mob effects Notch and then whatever effect so say For example absorption and then you can give it like a time I think so duration 200 this will be in text probably not seconds and we can check actually um can we check let’s see so duration we can’t see but it is probably text if I I imagine because otherwise that’d be A bit silly wouldn’t it and then we can say the amplifier so you might say you know level two absorption and you could say you know give it a Boolean as well um not Boolean it is Boolean but you have to specify two billions you see there’s also like Um whether it’s ambient whether it’s visible show icon hidden effect Factor data Etc you can do those as well if you want um I’m just going to leave it like that and then you can also pass in the probability which I think actually you have to do you have to pass in a Probability so if you want it to have a hundred percent of the time it will give you absorption you just put one and if you want it to only happen half of the time you’re up at 0.5 if you want to only happen you know um 1 12 of the time you would just put Point 12 or 12 of the time um Etc I think you get the point I’m going to just do uh one so that it happens every single time so I can show that effect off but that’s all I wanted to cover about items Um however you’ll see that this class is grayed out right class item in it is never used and that’s true because we’re not using this class just by making a register and registering something we’re not actually registering it we need to tell Forge that this registry exists So we use our main class for that as I stated in the previous tutorial this is your entry point everything kind of needs to go through here so we make the Constructor we do public tutorial mod and in here we can make a variable and this will be something known as the Event bus or Forge actually equal to ni event bus because they still use outdated uh c-sharp naming conventions um good on your thoughts good on you um I’m joking of course that’s a terrible thing that they’ve done and it should be sacrilege but regardless um we’re just going to call This the bus to keep it simple and that will be equal to FML Forge Mode loader Java mod loading context dot get dot get mod event bus now what this is is basically what it says it is um it’s a bus right so think of a bus Just picture a bus in your head it goes down a street it has a bunch of different stops and this bus is exactly the same right so it will stop at each of those stops it will collect its passengers right in this case passengers are events right so it’s something that fires And then it takes that passenger to its destination where it performs you know whatever its action needs to be so we kind of want to add something to this bus we want to tell it oh you should stop here and you should do this so we can do bus Uh no we don’t I don’t know why I’m doing bask we don’t do that we do item in it dot items which is our deferred register and we tell it to register itself onto this bus and you’ll see that effectively um it just adds a listener to that bus So the bus will now listen to this passenger for when it wants to do its stuff I think you get the point but one it basically needs to do this with all of our Registries that we add in the future it’s very important that you do that otherwise it just won’t register Anything so blocks are going to be exactly the same you just do blocking it dot blocks don’t register bus obviously we don’t have that and that’ll be in the next tutorial but just so you know in the future okay let’s close that because that’s all we need for the code And let’s come into the resources so we’re going to want to create a new directory in here and this will be assets and inside of there we’re going to want another directory which will be called whenever our mod ID was so very very important you call it exactly the same Thing as your mod ID so it is just tutorial mode for us and inside of here we can create another directory and I’ll call this Lang which will be for your language files and then since IntelliJ has done its thing and we need to do that again so assets tutorial mode And we’re going to create this time models and inside of models we’re going to want another directory for item and we’re also going to want another directory instead of our assets tutorial mod called textures and once again inside of there we’re going to create another directory called item And whilst we’re here we’ll also do the same four blocks so we’ll do model towards slash block and we’ll do a new directory textures forward slash block and we’ll also create a directory called block state which will be something we do in the block tutorial as well So inside of the models inside of item we’re going to write a new file and this will be our items model so we need to say what model is it going to use is it going to be handheld such as a sword right you hold in your hand it’s held Differently from say an Apple so is it going to be like that or is it just going to be like an apple right or just normal item is it going to be held like a block right there’s all these different perspectives and models that you can have say the Trident for example Has a different model to an Apple it’s a bit different so first of all let’s create the file and then we’ll talk about the different models that you can use different perspectives Etc so this file just needs to be exactly what your item was named So if we come into our code again and into item in it you’ll see we called it example underscore item so let’s just copy that ensures that we have exactly the same name we come into models we come into item we create a new file we paste it in There and then we just add dot j s o n Json and inside of it this is just a normal kind of Json really so we create our object and we need to say what the parent is so this is basically the base model that it will use Now since we’re just going to have a normal item here right like an apple we’re just going to say item forward slash generated now what vanilla has started doing is they have started prefixing this with Minecraft colon now you don’t need to do that however it’s kind of started to Become a trend of everyone doing that um so just I guess do that or don’t if you don’t want to obviously I can’t force you to but that’s just what people have started doing so I’m going to do it as well and then we need to specify the textures And if we come into this generated model which actually I can’t be bothered to open that right now um basically this will specify what the model looks like and the generated model specifically will have several different textures that you can set so the kind of default texture that you Would need to put is layer zero and then colon and this will be your texture path so for us we first need to put our mod ID so tutorial mod then colon then item forward slash and then whatever the name of your texture is now generally you Should have the name of your texture the exact same name as the name of your model and the name of your item now just make sure you don’t have any kind of texture errors there if you keep everything the same name you won’t have issues um now it is very important you have Everything here correct right if you had for example layer underscore zero that instantly would not work if you had for example um instead of tutorial mod it was accidentally TT or real mod that wouldn’t work so it’s very important that you have these exactly as they are So once again for example if you had items instead of item that wouldn’t work it is very important and once again this is case sensitive so if you put for example capital E for example my item that wouldn’t work so I think you get the point but you just need to double Check if you if you do get texture errors just double check all of these jsons that we’re going to be doing all of the texture files all of these folder names check that they are correct and exactly how they should be once again for example if you put like a Space in here that wouldn’t work it is very very sensitive to that kind of thing but yeah that’s the item model anyways if you did want it to be handheld right you would literally just put handheld instead of generated and if you wanted it to parent off of a block model You would say Minecraft colon block forward slash and then for example like ice and that would work but we’re not going to do that we just want a normal generated item model so let’s close that enough rambling and then you just need a texture as well So I actually don’t have a texture right now I’ll create one in a second but let’s do the Lang first actually since we’re here so we need a new file in here just en underscore us dot Json once again I mean I’m not going to say This too many more times but just make sure it’s named exactly the same thing um and you just want to put your name in here really so you do item Dot and then your mod ID so ours is tutorial mod Dot and then the name of your item which Hours is example underscore item or we can just copy paste that in so that we make sure it’s exactly the same and then this is whatever your item should actually be called right so ours is example space item you can put Capitals in here this is what it will Show up as is in the game if you’re a data pack or resource pack creator I’m sure all of this is very familiar to you and seems blatantly obvious but you would not understand how many people get you know simple strings like this they’ll have simple mistakes with spaces And all of that kind of stuff and I’m sure you guys will right I’m not going to hate on you for having that happen because it happens to everyone at some point it’s just very important that if you have it happen once you understand it and you don’t do it again that’s kind Of the whole preface behind why I keep overstating uh that you keep checking everything is correct but that’s all you need from that by the way Ian underscore us that’s just English us you could also do en underscore GB I think it is and you could do the same thing and then That would um also work um it just depends on what language is set in your game for example if your mod is only in French right you would just do Ian underscore f r and change it to you know French um I’m going to test my French knowledge it Exempt Exemplar I don’t know Exemplar item whatever that is in French and I don’t know enough French for that unfortunately and I’m sure someone will tell me in the comments that I’m an idiot but that’s okay just put whatever your language is really in underscore us is just the default Isn’t it really so example item boom okay let’s create a texture I’m going to create a texture and I’ll be back once I’ve done that okay so I’ve created my tank shot or really I just copied it from my 1.19.3 tutorial mod um and I put it in here and obviously Make sure it’s the exact same name example underscore item and it needs to be a DOT PNG that’s also very important it can’t be like a JPEG it can’t be a gif it can’t be um you know avif or whatever the other file types are it has to be a DOT PNG And make sure it’s also like power of two 16 by 16. that’s quite important and with that complete we can pretty much go ahead and run the game so we’ll once again run client like we did before if you don’t have that up there once again Gradle tab tasks Forge Gradle Runs run Client and we’ll let it go through and it should start in the game hopefully this should be fairly quick so I don’t intend to make a cut here it please Forge I would appreciate if you load nice and quickly there you go look at that look How fast that is nowadays with um dfu or data fix wrapper super fast super fast so we go single player we go new world and after loading in here let’s kill these guys because they’re going to really annoy me and you’ll see it’s not in our creative tab though is it right Example item where is it so if you recall we never stated anything about creative tab we never added it to one um so it won’t be in one um so we actually just need to slash give at s um tutorial mod and there you go you see our item is there And it’s purple because we gave it a rarity um of being purple and you can see we can eat it because we once again gave it a food and we get absorption look at that for 10 seconds Distortion free nice and um you should also just see that it only snacks to 16. Which is correct because that’s what we set it to do amazing so obviously in the next tutorial I will cover blocks and then the floral after I will add these to a creative tab as well so we can get that working and that’s all nice and simple Really so yeah that all works fine if we go in survival obviously game mode survival um we should be able to see this does actually function as food right so and if we eat it boom you see it refills hunger it gives us absorption nice nice nice And that’s pretty much it and what that is it um which I hope you guys enjoyed obviously leave a like And subscribe if you want to know when the next tutorial releases and uh I’ll see you then good bye Video Information
This video, titled ‘1.20 Minecraft Forge Modding Tutorial – Items and Food’, was uploaded by TurtyWurty on 2023-06-12 17:30:04. It has garnered 2257 views and 77 likes. The duration of the video is 00:28:59 or 1739 seconds.
In this video, I show you how to register an item and set up all of its properties including how you can make it function as a food item.
In the next video we will create our first block and create its loot table! 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
Learn Java Links: https://java-programming.mooc.fi/ https://www.codecademy.com/learn/learn-java https://docs.oracle.com/javase/tutorial/
Java Support Server: https://discord.gg/GzvQjhv
Chapters: 0:00 – Intro 0:20 – Registry class 2:10 – DeferredRegister 4:10 – RegistryObject 9:30 – Item Properties + Food Properties 14:35 – Registering our registry 17:15 – Resources directory 18:30 – Item Models 23:20 – Translation Files 26:00 – Texture 26:35 – Running the game 27:20 – Testing 28:40 – Outro