Tutorial 2: Game Setup
In this tutorial we will be setting up the very basics of our mod - actually doing some programming this time. Let's begin!
Rename the example mod project in Eclipse to the name of your mod. This can be whatever, but please, please do not make a gem mod.
To open the actual code, open the project with the arrow next to it on the left, and navigate through
src/main/java/
and
src/main/resources
. These locations will be where we store our code and assets respectively.
In
src/main/java/
there will be an example mod package. We can delete this, as we will be making a mod without it.
Now we can make our own package. Do this by right clicking on the
java
folder and hovering over new, then clicking
Package
.
There are certain package naming conventions in Java, where they will usually be
com.website.project
or com.username.project
. For example, these could be club.mcmodding.tutorial_mod
, or com.mrpineapple.tutorial_mod
respectively.
Now let's make a main class in this package. For the sake of simplicity, I will be calling it
Main
.
By convention, class names in java start with a capital letter, and for every new word it becomes a capital letter again. For example,
ThisIsAProperClassNameInJava
.
Now we will make a
Reference
class. This is where we will store information about the mod for us to use throughout it's
developement, such as the name and version. I have created a util
(short for utilites) package in my mod to make it easier
to navigate in the future when we have much more code.
Now we need to add some variables to this class. We need to include the mod's ID, name, version and path to our proxy classes. It should look a little like this:
public static final String MOD_ID = "tutorial_mod";
public static final String MOD_NAME = "Tutorial Mod";
public static final String VERSION = "Alpha 1.0";
public static final String CLIENT_PROXY = "club.mcmodding.tutorial_mod.proxy.ClientProxy";
public static final String COMMON_PROXY = "club.mcmodding.tutorial_mod.proxy.CommonProxy";
Your mod ID should be unique to your mod, so be creative. If it clashes with another installed mod there will be issues, so I advise using the
full mod name in there as well as your username if you're unsure whether your mod name is taken.
Now open your main class, and add the
@Mod
above the class name, which will accept the variables we entered into Reference
.
It should look like so:
@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)
public class Main {
}
You can import all classes needing importing at once in Eclipse by using the shortcut
Ctrl + Shift + O
.
Now we need to create an instance of our main class like so:
@Mod(modid = Reference.MOD_ID, name = Reference.NAME, version = Reference.VERSION)
public class Main {
@Instance
public static Main instance;
}
Then we will make a sided proxy like this (ignore the errors, we have not made the proxy classes yet):
@SidedProxy(clientSide = Reference.CLIENT_PROXY, serverSide = Reference.COMMON_PROXY)
public static CommonProxy proxy;
Next create a proxy package in your project. This must be the same name as what you put in your Reference file:
In this case the package would just be
In this case the package would just be
club.mcmodding.tutorial_mod.proxy
Now, in that package, we must create the two classes
ClientProxy
and CommonProxy
. ClientProxy
needs to extend CommonProxy
. Other than that, both can be left alone for now.
Finally (phew), we will create three initialization events like so in our main class:
@EventHandler
public static void preInit(FMLPreInitializationEvent event) {
}
@EventHandler
public static void init(FMLInitializationEvent event) {
}
@EventHandler
public static void postInit(FMLPostInitializationEvent event) {
}
Finally finished. Trust me, it gets better and easier from here. ;-)