Minecraft 1.12 modding with forge – 2 – main mod class

Hello everyone and welcome to part 2 of Minecraft 1.12 modding with forge, today we are going to setup the main mod class and make minecraft load our mod. So start eclipse and start modding!

First we are going to setup some folders to structure the mod.

  1. Right-mouse click on the root folder in eclipse, press new and select source folder. Then as folder name use: “src/main/java”.
  2. Do step 1 again but instead use “src/main/resources” as folder name.
  3. Create a package in the “src/main/java” source folder. I will call it com.suppergerrie2.tutorial”. But you should think of your own name, I will be referring to this package as the mod package. This package will contain all of the classes we are going to create.
  4. Create a class in the mod package and I will call it TutorialMod I will be referring to this class as the Main class. This class will be the entry point of the mod. Everything will start here.
  5. One last class before we can start coding, I will call it Reference. This class is going to contain all of the references to constant values. For example the mod version, modname, etc.

The basic files are now setup so lets start coding!
In the reference class add 4 static final String variables:

  • MODID, this will be the id of your mod, it can be whatever you want but don’t make it too fancy, it also has to be all lowercase.
  • MODNAME, this will be the name of your mod, this will be shown to the users of your mod. This can be as fancy as you want.
  • VERSION, the version of your mod. You could think of your own versioning system or use a standard one, I am just gonna use 1.0
  • ACCEPTED_MINECRAFT_VERSIONS, the versions of minecraft your mod is supposed to work with. This is in maven syntax I will use [1.12].

Your reference class should now look a little like this:

In the Main class add an @Mod annotation above the class declaration. This will tell forge that this is a mod file. In eclipse you can press ctrl-shift-o to import missing imports, press it to import net.minecraftforge.fml.common.Mod@Mod requires the modid as an attribute, so lets add it. I will also add the name, version and accepted minecraft. It should now look like this:

Now lets add some functions, these 3 functions will be called by forge in specific loading stages. We have preInit, init and postInit. They all need an @EventHandler annotation. They all need a specific argument. preInit has FMLPreInitializationEvent, init has FMLInitializationEvent, and postInit has FMLPostInitializationEvent. I will also add some println functions for debugging.
This is what it should look like:

This is enough for forge to load the mod, to run the game press the green run button. If this doesn’t work go to Run Configurations click on the client and run.

If everything is good the game will start and load the mod. If you added the println function calls you can look in the console and they should be in there. You can also click on Mods and see if your mod is in there. If you click on your mod it will show a red warning telling you to add a file, don’t worry. We will add that now!

Going back to eclipse, go to the src/main/resources source folder and create an empty text file. Add this to the file and replace the words in capslock:

After relaunching the game the issue should be fixed.

One last thing before I will finish this part of the tutorial,
In the Main class add these 2 lines:

Forge will assign the instance of your Main class it is using to this variable.

Next time we will add an custom item, I hope to see you next time!
I also made a github repository for this tutorial, by clicking here you will be send to the code of this part, it is my first time really using github so sorry for all of the errors I probably made!
And as always, if you have any question don’t hesitate to ask in the comments! Also if you saw any errors in the tutorial please let me know so I can fix it!

Till next time!


Posted in Forge tutorial, Forge Tutorial 1.12.


  1. Nice series of guides. I was making tons of mods a few months back. Just needed a quick refresher. Thanks!

  2. I havent got a text if i turn on my mod

    this code
    “modid”: “aqm”,
    “name”: “Adventure Quest Mod”,
    “description”: “this mod is for peoples who likes adventures and completing quests.don’t forget to compllete all challanges too!”,
    “version”: “0.1”,
    “mcversion”: “${1.12}”,
    “authorList”: [“Tweedy”],
    “credits”: “Suppergerrie2’s tutorial and the internet!”,

    what i can do with this?

  3. got this error when i added the last line
    public static randomstuff instance;

    it says : randomstuff cannot be resolved as a type

    • Without code I am not sure, but I guess your class is called RandomStuff and not randomstuff.

  4. Mine says, “mod cannot be reserved to a type” after I do

    @Mod(modid = Reference.MODID, name=Reference.MODNAME, version=Reference.VERSION, acceptedMinecraftVersions=Reference.ACCEPTED_MINECRAFT_VERSIONS)

  5. Using the latest Eclipse IDE you can create a new “Untitled Text File” or a “File”, so instructing to create a new “empty text file” is a bit confusing. Maybe update your instructions to say new “File” and include instruction to name it “mcmod.info”.

  6. I had this error:
    [main/ERROR] [FML]: Unable to construct net.minecraftforge.fml.common.Mod container
    java.lang.reflect.InvocationTargetException: null

    And I have found solution:
    Recent Forge versions reject mods that have uppercase letters in the mod ID. The mod ID needs to be lowercased.
    it’s from: https://github.com/Elecs-Mods/CraftingTable-IV/issues/44

    You have to just change all upper case letters to lower case, and that’s all.

Leave a Reply

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