There is an example mod that does nothing in src/main/java, in the package com.example.examplemod. We will make a new one based on this.
Start by making a new package in the same folder, where we will put our own code. Click on src/main/java, then from the menu select File – New – Package, and pick a package name:
Now create a class in it: File – New – Class and give it a name. There is no need to select the “public static void main” option; we will be replacing all the code.
From in ExampleMod.java, copy all of the code, then delete all of the code in your own class and paste in the code from ExampleMod. Now make some changes:
- On the top line, change the package statement: it has to correspond to the package you created your class in. Eclipse will flag the error with a red line and its quick fix will allow you to change the package.
- On the line public class ExampleMod, change ExampleMod to the name of your class. In Java, the file name and class name have to be identical.
- Check that the @Mod statement refers to your class, not ExampleMod. Note: statements beginning with @ in Java are called annotations.
- In the body of your class, change the values of the variables MODID and VERSION.
- If you like, change the System.out.println line to print a new message to the console window, e.g. “Craft1 mod initialised.” Lots of messages are displayed in the console window when Minecraft runs; you should see your message near the end.
Now run Minecraft and see if your mod exists. The name should be there and your hello message on the console, but it doesn’t do anything because we haven’t added code for anything useful.