In this tutorial I will show you how to create your very first basic file that you will need before you can add anything to the game.
The first thing that you will have to do is create a new package inside of the src folder in eclipse. Do this by right clicking on the src folder and clicking new Package. When you click that a window will pop up that asks you for the package name. The name could be anything, but it is smart to give it a name like this one:
So just the name of your mod.
Now select the package and right click again. This time click new Class. Again a window will pop up telling you that you need to give it a name. The file you are going to create right now is the mod file. It will contain the most important information about your mod. It will contain recipes, blocks, items and much more. I suggest giving this file the name of your mod.
When you create the file it should look something like this.
The first thing you will have to add must be placed above the public class Tutorial line. It should be something like this.
@Mod(modid = Tutorial.modid, name = “Mod Name”, version = “1.0”)
The first thing inside of the quotation marks is the mod id of your mod. This has to be unique for every single mod or it will crash. Right now you will have an error under modid. That is because you are trying to acces a variable you haven’t made just yet. We will do that in just a second.
The second thing inside of the brackets is the mod name. This will show up inside of the Minecraft client.
The third and last thing is the version number. This one will as well show up inside of the Minecraft client.
You will probably get some errors right now under @Mod. To fix this press Ctrl, Shift, O. It should add this line to your file just below the line with the package.
If it does not import it you will have to typ it yourself.
Now you should make the variable, by adding this one line between the brackets just after Tutorial.
public static final String modid = “YourName_ModName”;
To get this in your mod you have to keep everything the same except for the thing between the quotation marks. In here you add your name and your mod name.
The second line that you need to add goes right between the @Mod line and the public class line. It should look exactly like this one.
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
This line will make sure that people using this mod can connect to servers that don’t have it and that they can’t connect to servers that have it when they don’t. You need to have it this way or it will crash your mod when you try to connect to a server.
Once again you will get an error under @NetworkMod. Again you have to press Ctrl, Shift, O. And if that still doesn’t work you have to add this line inside of your file.
Now the whole file should look like this.
One thing that you should notice is that I moved the bracket behind Tutorial to a line lower. This is because I don’t like the bracket there. That is completely my own style of coding and you don’t have to copy that exactly. There are a lot of coding styles that you can use and none of them is the best. Your style should simply be the way you can read code the easiest.
The next thing you have to add is this.
This has to be added inside of the brackets below the public class Tutorial line. The public void load() is the first method in your mod. A method is a piece of the code that can be called from outside. The @EventHandler above makes sure that forge will call it during the Init phase of start-up.
Inside of this method will be most of the code for your mod. It is a very important method and it will become very big.
You might get errors under @EventHandler and inside of the load brackets. Fix it by pressing Crtl, Shift, O or by adding these 2 lines.
The whole file should now look like this.
You can download the source code from this tutorial right here.
I don’t suggest copying the code directly from this download. It will not learn you as much nor will you remember the code. If you want to do that or if you just can’t figure out why your code isn’t working you can download this.
In the next tutorial I will show you how to add a basic block to Minecraft.