Tutorial 2. Base File

So, now we can make the fun begin!

Make sure you watched Tutorial 1

Code is on Github

WEBSITE IS DEPRICATED

VISIT THE NEW WEBSITE

 

Highly recommended to look on github for source

To start off, in tutorial 1, I made you think of a name. A name which we would use a lot.
That name is now gonna be referenced at as your mod-id.
So. In intelliJ, create a new package, inside the Java folder, with your mod-id as name.
Inside the package, create a new java class, with your mod-id as name.
This java file, will be the main class of our mod!

So, Lets get started!!


package mcmodtutorial;

public class Mcmodtutorial
{

}

This is the file I start with, when i create a new class.
Anything grey astrixes, is for learning purposes, or documentation. In this case, the info is for documentation.

So, in order for forge to load our mod, we need to tell it, that we have a new ModFile. We do that, by placing the @Mod notation in our file, before we declare the class.
The @Mod takes 3 params. Modid, Modname, and Modversion.
To keep things saved properly, I store all my global references in a class called References.
This class, will be located in the package lib. Therefor, i click on mcmodtutorial package, and select new package. I name it lib. In that package, i create a class called References.

fd4185ffb2a54b6aa3077287050ffce9

So, in References, i create 3 final variables. These vars will be the same for the entire mod.

public class References

{
 public static final String MODID = "mcmodtutorial";
 public static final String MODNAME = "MC Modding Tutorial";
 public static final String VERSION = "1.0.0";
}

Now we can use those references in our main mod file


package mcmodtutorial;

import cpw.mods.fml.common.Mod;
import mcmodtutorial.lib.References;

@Mod(modid = References.MODID, name = References.MODNAME, version = References.VERSION)

public class Mcmodtutorial
{

}

So, now atleast forge knows we have a mod.
But we cant load anything yet. In order to have anything loaded at all, we need to call 3 events. FMLPre- , -Post- and FMLInitializationEvent.
This requires the annotation EventHandler


@Mod(modid = References.MODID, name = References.MODNAME, version = References.VERSION)

public class Mcmodtutorial
{

@Mod.EventHandler
 public static void preInit(FMLPreInitializationEvent event)
 {

 }

 @Mod.EventHandler
 public static void init(FMLInitializationEvent event)
 {

 }

 @Mod.EventHandler
 public static void postInit(FMLPostInitializationEvent event)
 {

 }
}

The preInit loads things like blocks, items, loggers, and config handlers.
The init loads stuff like renderers, Gui’s, etc.
The post init loads add-ons.

One more thing we need to add. Its the hardest part to understand.
In Minecraft, you have 2 sides. Client and Server.
Client handles everything that you SEE on your screen. So textures, models etc etc.
Server handels all calculations. So rigstering blocks, events etc etc.
The proxies are there, to seperate client and server.
Everythign you do in the ClientProxy, will happen on the client.
Everything you do in the CommonProxy, will happen on the server.

Now, to add those 2 proxies, i make a new package called core, and inside that package another package called proxy.

f250a149a62a223c4f3f9bc603de6ca9

Add 2 files, CommonProxy and ClientProxy
Make ClientProxy extend CommonProxy
Now, one more thing we have to do to make minecraft run, is register the proxies.
We do that by telling forge, which files are proxy files.
Therefor, in References, I declare where they are.
The localtion is [modid]+.core.proxy.+[classname].
In my case my location is:


public static final String CLIENTPROXYLOCATION = MODID + ".core.proxy.ClientProxy";
 public static final String COMMONPROXYLOCATION = MODID + ".core.proxy.CommonProxy";

Now, in your main class, tell forge where our proxies are.
The way to do that is:


@SidedProxy(clientSide = References.CLIENTPROXYLOCATION, serverSide = References.COMMONPROXYLOCATION)
 public static CommonProxy proxy;

Now, when you run, you can see that your mod work!

Back to List
Next tutorial

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s