Modding: 1.4.7 Basic File

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 common folder in eclipse. Do this by right clicking on the common 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:
tutorial
The first word should be the name of your mod. The second one has to be common.
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.


package tutorial;

public class Tutorial {

}


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 = “YourName_ModName”, 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 from any other mod or it will crash Minecraft. I suggest giving it your user name_ your mod name.
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.


import cpw.mods.fml.common.Mod;


If it does not import it you will have to typ it yourself.
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.


import cpw.mods.fml.common.network.NetworkMod;


Now the whole file should look like this.


package tutorial;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid = “YourName_ModName”, name = “Mod Name”, version = “1.0”)

@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{

}


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.


@Init
public void load(FMLInitializationEvent event) 
{

}


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 @Init 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 @Init and inside of the load brackets. Fix it by pressing Crtl, Shift, O or by adding these 2 lines.


import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;


The whole file should now look like this. All the new code is in blue.


package tutorial;

import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;

@Mod(modid = “YourName_ModName”, name = “Mod Name”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
@Init
public void load(FMLInitializationEvent event) 
{

}
}


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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">