Minecraft Blogs / Tutorial

Java Forge MDK Programming!

  • 170 views, 6 today
  • 13
  • 12
  • 8
WannabeTommyInnit avatar WannabeTommyInnit
Level 30 : Artisan Magical Boy
Hey! Welcome to another one of my tutorials!
Today, we'll learn modding in Java with Forge MDK!
This will be split into stages, each stage having multiple steps.

Sample text, sample text, tl;dr
Why use Java?
Java is preferable to messy, quick coding like MCreator because of it's speed. MCreator has unoptimized code that make the file size large, and increase your lag.

Stage 1: Preparation
Now this part is easy and only has one step. This will prepare your workspace for your mod and download the required files!
Step 1: Download files.
This requires you to download files to your computer. (I will be grabbing links from the adfocus paywalls so you don't have to get ads and viruses)

First, visit the forge installer website and the forge mdk website. These will automatically download.

Second, extract the MDK to a directory where you will setup the workspace. This can be anywhere from your desktop, to %appdata%.

Third, you must have Windows. Go to the command line and type "cd (my mdk path here)". Then type "gradlew setupDecompWorkspace" to set up the workspace for your project.

Fourth, launch the Forge installer. Follow the instructions to install Forge in Minecraft.

Fifth, download Eclipse IDE from Eclipse IDE link lel.

Stage 2: Setup workspace and build
Meh, this part is a l i t t l e harder. It will have multiple steps.

Step 1: Setup workspace.
Run eclipse and set up a Java project with the directory being the directory you extracted the Forge MDK to. Aight, done.

Step 2: Setup build.gradle.
Open the build.gradle file in the Forge MDK and change the "archivesBaseName" to the name of the file. Then, change the "group" to a name following these Apache Maven naming guides. Also change the "version" to your mod version (preferably using 1.0 for your first release). Then, replace all occurences of "examplemod" to your mod ID (follow stage 3)

Step 3: Edit mcmod.info.
Navigate to src/main/resources/mcmod.info to change the mod info, this will be displayed in game in the mods list. Change the "modid" to your mod id and the name and description to your own. No more having your private computer username displayed in a public mod! 😳.

Stage 3: Coding
For this you'll need some basic knowledge of Java.

Step 1: Create mod files.
This is where we will store our mod code! This is how our directories should be stored:
if your group is "heya", we will create a new folder in src/main/java/ named "heya", and have a new class in that with the name of your archiveBaseName.

Step 2: C O D E
This is the hardest part of the entire tutorial, we will be writing the Java code!
Let's start out with this:
At the top, after "package (package name)", write:

import org.apache.logging.log4j.Logger;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;

Your default code should have a package name and all that stuff. What we're after is the code with public class (package name) {
That's where we will write our code instead of dragging and dropping blocks.
Write in here:

public void init(FMLInitializationEvent event)
logger.info("Done loading " + NAME);
Worrying about the name part? We're defining this now.
Above the class part, write:

@Mod(modid = (package name).MODID, name = (package name).NAME, version = (package name).VERSION)
Load it, and it should display "Done loading (package name)"!
Some more things are here:

Stage 4: Test mod
Open the command window again and run the same CD command to access gradle, and run "gradlew build". Your build may fail. so there may be an error with Gradle or your code. To run Minecraft, use "gradlew runClient". To access your built mod, navigate to build/libs and find your newly created .jar file.

Alright lol bye kids, enjoy your modding.
You now know how to make a basic mod with Forge API.
CreditMedium, CubeCoder, Forge API Developers

02/08/2021 4:57 pm
Level 6 : Apprentice Bear
PopingBob avatar
can i do this with intellij
02/08/2021 5:03 pm
Level 30 : Artisan Magical Boy
WannabeTommyInnit avatar
Yep! You just may have to set it up differently. I recommend Eclipse, though.
02/08/2021 5:32 pm
Level 6 : Apprentice Bear
PopingBob avatar
01/28/2021 1:41 am
Level 23 : Expert Pixel Painter
TheBigPug avatar
can you make make it into a full tutorial like Bertiecrafter did?
01/31/2021 12:24 pm
Level 30 : Artisan Magical Boy
WannabeTommyInnit avatar
You can try looking at Forge docs or Java docs, but I do not feel like making it huge. I only want to make this tutorial simple.
02/03/2021 9:13 am
Level 23 : Expert Pixel Painter
TheBigPug avatar
can you convert .zip into .jar?
because I know .json and if you could it would be easy.
02/03/2021 9:59 am
Level 30 : Artisan Magical Boy
WannabeTommyInnit avatar
You can't convert .json to .jar or .zip to .jar unless it is coded in Java.
02/03/2021 1:31 pm
Level 23 : Expert Pixel Painter
TheBigPug avatar
oh, ok, nvm. I am learning now java
Planet Minecraft Logo


© 2010 - 2021