In this tutorial I will show you how to do several things. First of all I will show you how to update your code to a new version of Forge. After that we will have to fix an error in the Texture tutorial code and to do that I will use a cool Java trick that will make adding items easier.
The first thing is to update Forge. Step 1 for this is to install forge. If you don’t know how to do that you have to watch this.
Step 2 is to go to your old forge folder and go to mcp/src/minecraft there you have to copy the folder you have created. Then go to the same folder in your new mcp and paste it in there.
You will also have to put the textures in the new minecraft.jar found in MCP.
Next up is to open up Eclipse in the new forge.
The last version of Forge I used to make the tutorials was 605. The newest version at the moment of writing this is 655. There are some important changes between these versions. Of course there are bug fixes, but there are also some new things added, old things depricated, some method names changed and most importantly in some of the newer Forge versions the speed of playing Minecraft has increased by a lot.
When you copy over your code to the new Eclipse workspace you will get an error in your Item file under iconIndex. To fix that you will have to change it into itemIcon.
There is one other important change that you can’t really see as an error at the moment. With the code currently in the Item file the Icon will not load. That is because updateIcons has changed it’s name into registerIcons just like with Blocks. Now your Item file should look like this.
If you start Minecraft now it will work just fine.
However, there is one problem I wasn’t aware of when I made the custom texture tutorials. This is that getUnlocalizedName2() doesn’t exist on the server for blocks, which means that the current code would crash a server.
To fix this problem, and improve the overal code we are going to add a general Item and Block class. Those files should look like this.
As you can see these files are exactly the same as the basic Block and Item file. The way you should use these is the change the extends from the basic Item and Block file into the General files.
This makes the Block and Item files look like this.
Right now you might be thinking: Why would I make a General file that is exactly the same as the basic Item and Block file? The thing is that when Java reads the ItemTutorial file and it is looking for the registerIcons method, it will try to find it in there. If it can’t it will go to the extended file, which is ItemGeneralTutorial, there it can find the registerIcons method which it will then use for the ItemTutorial.
So now whenever you have an Item that extends ItemGeneralTutorial it will use the registerIcons method and load the texture correctly. And all of that without having to add a method to the file for the new Item.
This way you can generalize a lot of things. Simply add it in the general file and it will be used in everything extending it. If you want to change something in that method you can simply add it to the Item file (not the General) and it will override it from there.
The ItemTutorial file should now look like this.
And this is the BlockTutorialBlock file.
As you can see this makes reading the Item files a lot easier. It also enables you to add items and blocks much quicker. Just make it extend the general file and there will already be some things set for it.
Now we have General files, but we haven’t fixed the getUnlocalizedName2() crash just yet. To fix this you will have to make the General file look like this.
The difference here is that it’s now using getUnlocalizedName() with a substring. Substring is a cool little method in Java for strings. It lets you cut out the first couple of letters of a String. The amount of letters is set with the parameter. This thing will remove the first 5 letters being tile. every time, leaving just the unlocalized name.
As you remember you had to save the Images for Items as item.unlocalizedname. We can now remove that item. with the same little trick. This will make the General Item file look like this.
So you know have:
– An updated Forge
– No more crash on the server
– Better file names for your Item images
– General Item and Block files making adding more/new items very easy