Hello cyberspace my name is Ken Mills and welcome to episode three in my minecraft 117 modding tutorial in this tutorial we’re going to take a look at setting up our first mod item and importing it into the game if you haven’t I recommend you start the beginning of this series so that you Make sure you have all your files and stuff set up correctly you can do that by clicking the I in the top right hand corner in this video but as long as you’ve done that without further ado let’s get started so I’ve got a clip start it up into the Eclipse Folder of our mod installation so before we get started actually working on this tutorial where we get our mod setup that I’ve got a bit of correction from our last tutorial so in our main mod file above the so this is in source main Java whatever dot tutorial mod main Java Above the preeminent in it and post in it functions we need to have that so we need the event handler annotation from forge mod loader this tells forge mod loader that these three functions should be called when the mod is loaded so that’s important otherwise the blocks and things and Items that we add won’t get loaded in because these functions don’t get called so creating our items it’s important to kind of have them centrally located so that it’s easy to find them if we need to modify them so we’re gonna create a new package to hold our items so I’m Going to new package and we’re gonna just I’m just going to name it items so there we go we’ve got a new items package and in that items package we’re going to need a class that we’re going to register our items in so I’m just gonna call it two mod items and there’s Our class so in this class we need a function that we can call to register all the items so we’re going to just name it in it so we have a public static final void function and NIT so this function is where we’re going to register all of our Items now in order to make sure that this function actually gets called and our items actually get registered we need to call it in one of the proxies and because items should be registered on both the client side and the server side we want to call it in the common Proxy so in our pre init stage of the common proxy we need to call to mod items got in it and there we go so now any items that we register in this init function will get loaded into our mod as it starts so we’re gonna get started Actually creating our first item now so minecraft hopefully provides an item class that’s pre-made so we don’t need to define an brand new class for this at least not yet since we’re just adding normal items so first thing that we’re gonna do is define a variable so this is Going to be a public static item of name tutorial item and so then we can import the item class we want net minecraft item so we afford that now in our init function we want to define this item and tell Minecraft what it is so a tutorial Item is a new item so it’s going to create a new item now we need to set the name so we’re going to set the unload i’s name to whatever we want to call so you need to use double quotes here tutorial item so that’s going to that’s Going to define our item as a new item class and is going to set the unlock wise name to tutorial item and the unlock wise name is basically just how minecraft and forge refer to this item it’s like its identifier and now there are a couple things that we can do here But just for sake of simplicity we’re going to put it into a creative tab so that we can find it and to do that we’re just going to borrow one of the existing creative tabs and minecraft instead of creating our own yet so we’re going to do set creative tab and then the Creative tabs in Minecraft are under a class called creative tabs and now we can look through here so we’ve got the blocked a brewing combat decorations food whatever so let’s just put it in hello let’s just put it in redstone for no other reason that I want To so now we’ve got our item defined but it’s not actually registered into the game so the way Forge works is you can define all the items you want but until you register them through the game registry which is what actually injects them into the game they won’t show up so We need to register this item into the game so we can use that we can do that using the game registry class so game registry dot register item and then we need to pass it the item so tutorial item and then the name so for this name We want to use the unlock lized name that we’ve just set so tutorial item get unloads now so the reason we want to use get the get unlock alized name function instead of just typing tutorial item again in there is if we ever have to change the on localize name for whatever Reason say it’s used by another mod or something and we need to change it it’s way better to do it this way because I can just change this one string right here and it updates it throughout all the rest of the code instead of having To dig through my code for all the times I’ve typed in tutorial item for the name and changed them all individually so now that we have our item defined and we gave it a name and a creative tab and we’ve registered it through the game registry we should be able to start up Our game and see our item in the game so we can do this by just hitting this play button up here and we’ll see the scrolling text which means that Forge is loading mods we’ll just wait a sec alright so I just created a creative super flat world to Just sort of test in let’s do that so in our code we’ve told it to put this item in the redstone tab so if we go to our Reds from tab looky there so we have no texture because we didn’t set a texture and it’s named item dot tutorial item Name because it doesn’t know what to call it yet so that’s something that we will get to in just a minute but the good news is we have our items so it looks a little funny but it behaves just like a normal item in Minecraft so we Can pick them up and they stack and we can throw them in a crafting table and they show up in a crafting table so they just need a texture in a name so now that we’ve got our item defined and we’ve verified that it is in the game we Can set it up so that it has both a texture and a name so the way Forge and the Minecraft loader handled names is they use a thing called a Lang file and basically you create a file for your mod called en underscore us dot Lang and that English United States Lang file Defines aliases for things so for example we saw our item was called item dot tutorial item dot name so what we would do is we would tell the Lang file that anywhere that it sees this used in display we want it to show something Else we wanted to show the name so to do this we need to create our laying file so I’m going to open up a file explorer and navigate to wherever we put our tutorial mod so this is the Eclipse folder not the Eclipse folder this is the root Folder so then we’re going to go to source main resources and then we’re gonna create a new folder this is going to be called assets then in this assets folder we have a new folder and this folder is our mod ID so the mod ID for The mod we’re working on right now is two mod so we’re gonna have a two mod folder and then we’re gonna have a Lang colder LAN G then in this Lang folder we need to create a new document and we’re gonna name it ii-in underscore capital u capital S dot Lang so that’s our lang file that’s where we will define the names of all of our items and blocks and such now while we’re in here we can go up one directory so asset slash to mod where our Lang file is we’re gonna have a new folder We’re going to call this textures then in this textures folder we’re gonna create two folders so we’re going to create an items folder and we’re going to create a blocks folder so this will be where we put our textures once we get to that point so now that we’ve got all This done if we go over here to our package Explorer and we see source main resources over here we can expand this assets to mod Lang and there is our Lang file so we can open this up in here so in this Lang file we need to tell Minecraft what it should call our item any time it sees the item dot tutorial item name string so first of all we need to tell it what string it’s looking for so item dot tutorial item dot name so we’re telling the Leng file that anytime You see this string we want to call it something different so no spaces immediately put an equal sign and then no spaces immediately start typing the name so we’re going to call it tutorial item so there we go now we can start at minecraft and when we get into our game anytime we’re Used to use item to toriel item name it’s now going to call it tutorial item so the Lang system of naming is very dynamic in the sense that you can alias anything that has a name anything that uses a string like that so item dot tutorial item name so minecraft itself Does this so like this single player button where it says single player it doesn’t it’s not actually called single player somewhere there is a string called something like I don’t know GUI button dot single player dot name and so somewhere in the Minecraft source code there’s a laying file that tells the GUI Renderer to call this button single player and so it’s consistent throughout all of Minecraft so now if we go look there we go we have it officially has a name tutorial item so there we go the next thing we want to do is create our texture so textures for items in Minecraft are a little picky so we want to create a PNG file that is 16 pixels by 16 pixels that is all the more space we have to work with so you want to use some sort of image editor that is not Microsoft Paint basically I’m going to Be using Pinta on Ubuntu if you’re using windows I recommend paint.net it’s very similar to Pinta and it supports the full like transparent background and everything so we’re gonna create a new image that is 16 pixels by 16 pixels and we wanted to have a transparent Background so now let’s just zoom in a ways there we go so now on here there we go oh one two three four five six seven eight there now every one of those little tiles is one pixel so now we will just create some dummy texture so I don’t know why Don’t we may it lets make it a plus sign I don’t know why it’ll just be easy to demonstrate so we’ve got our plus sign they’re real ooh better yet I have an idea why don’t we make it like the flag of England or something let’s do that And then we’ll fill these parts white there we go flag of England so now we’re going to save it so when you save it you need to save it to that textures folder so we find the folder for our mod let me go to source main resources assets then Our mod ID then textures and since this is an item it’s going to go in the items now when you name it it needs to be named whatever the unlock lies name is so we set that to the tutorial item and then we need to save it as a PNG file so We hit save now we can close this so now if we look in our textures file under items we have tutorial item so now that we’ve got our texture created and saved in the proper directory we need to tell Forge to look for that texture so that Minecraft can load it into the game so if you look here I’ve added this extra line so tutorial item dot SEC texture name and then here we’ve got a bit of kind of complicated looking code but it’s really not it just takes the mod id adds a colon after it and then the Unloads name after that so it’s gonna look something like this so toot mod is the mod ID and then colon and then you’ve got the unlock alized name now here is a misconception or not a misconception but just sort of a mistake that a lot of people make you Might assume because we’ve set the on localize name to tutorial item here this is going to be tutorial item there when we get the in localize name however this is incorrect because if you read the tooltip for this we look it says it sets the unlock last name of this item to the Past is the parameter prefixed by item dot which means this is actually item dot tutorial item which means that in our items directory or tutorial item file we need to rename it item dot otherwise it’s not going to be able to find the texture so once we rename that We should be able to load up the game because we’ve told minecraftforge that the items texture name is to mod so mod bars mod ID toutes mod : and then the unlock applies name so now minecraft knows to go look in assets toot mod under textures items and find Item dot tutorial item so now we can load up our game and what it’s going to do is once it reaches that line it’s going to go and find the item tutorial item PNG file and minecraft is going to apply that texture to our item so once It loads up we should see our English flag texture on our tutorial item and there we go so now we have an English flag so it behaves like a normal item drop it on the ground we can craft with it and whatnot so there we go so that’s About all we’re going to cover in this episode in the next episode we’ll take a look at creating our first block with textures and getting that set up but for this tutorial we’ve successfully scaffolded the framework to add many items to our mod and we’ve created our First one and walk through setting up the texture and the name of it and getting it properly injected into the game alright guys thanks for watching episode 3 in my minecraft 117 modding tutorial as usual I will be down in comments if you mean help if something didn’t work Is something that’s kind of weird you don’t know why I’ll be down there I’ll help you out as best I can if you just want to show off something you built so maybe you built some really cool mod I’d love to see that also or if You just want to connect with me so you can do that on Twitter on Google+ on email by my blog links to do all that stuff are the description down below be sure to get subscribed they do you don’t miss the next episode in this series where we’re gonna take a look at Creating our first textured block and getting that set up into the game and as always thanks for watching this video and I will see you in the next one Video Information
This video, titled ‘Creating an Item // Minecraft Modding Tutorial (1.7.10) // Episode 3’, was uploaded by Garrett Mills on 2017-01-18 13:00:14. It has garnered 680 views and 12 likes. The duration of the video is 00:18:59 or 1139 seconds.
In which we create our first custom item, set up the texture for it, and create the name in the lang file.
View the code as it stands at the end of this episode: https://github.com/glmdev/mc-1.7.10-tutorial/tree/Ep.3 (This is src/main/ folder.)
========= LINKS =========
Paint.NET: http://getpaint.net/
—
Hi! My name is Garrett, and I write code!
Connect with me:
Twitter: https://twitter.com/glmdev Blog: https://glmdev.github.io/blog/ E-Mail: [email protected]
https://youtube.com/garrettmills1999
—
Creating an Item // Minecraft Modding Tutorial (1.7.10) // Episode 3