ModderDojo Java Modding 5: Creating Our First Mod – The Basic Code

Previous post: ModderDojo Java Modding 4: Creating Our First Mod – Getting Started
Next post: ModderDojo Java Modding 6: Creating Our First Mod – Adding A Crafting Recipe

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:

forgepackage

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.

forgeclass

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.

Previous post: ModderDojo Java Modding 4: Creating Our First Mod – Getting Started
Next post: ModderDojo Java Modding 6: Creating Our First Mod – Adding A Crafting Recipe

3 thoughts on “ModderDojo Java Modding 5: Creating Our First Mod – The Basic Code

  1. Pingback: ModderDojo Java Modding 1: Beginning Java Mods with Forge | CoderDojo Athenry

  2. Pingback: ModderDojo Java Modding 4: Creating Our First Mod – Getting Started | CoderDojo Athenry

  3. Pingback: ModderDojo Java Modding 6: Creating Our First Mod – Adding A Crafting Recipe | CoderDojo Athenry

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s