Minecraft Blogs / Tutorial

Java Forge MDK Programming!

  • 4,996 views, 1 today
  • 20
  • 18
  • 8
Wannabe TommyInnit's Avatar Wannabe TommyInnit
Level 41 : Master Magical Boy
281
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:

@EventHandler
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:
https://cubicoder.github.io/

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
Tags

Create an account or sign in to comment.

urlocalnerd
• 02/08/2021 4:57 pm
• Level 10 : Journeyman Birb
urlocalnerd's Avatar
can i do this with intellij
2
Wannabe TommyInnit
• 02/08/2021 5:03 pm
• Level 41 : Master Magical Boy
Wannabe TommyInnit's Avatar
Yep! You just may have to set it up differently. I recommend Eclipse, though.
1
urlocalnerd
• 02/08/2021 5:32 pm
• Level 10 : Journeyman Birb
urlocalnerd's Avatar
k
2
Dunk__
• 01/28/2021 1:41 am
• Level 38 : Artisan Pixel Painter
Dunk__'s Avatar
can you make make it into a full tutorial like Bertiecrafter did?
2
Wannabe TommyInnit
• 01/31/2021 12:24 pm
• Level 41 : Master Magical Boy
Wannabe TommyInnit's 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.
1
Dunk__
• 02/03/2021 9:13 am
• Level 38 : Artisan Pixel Painter
Dunk__'s Avatar
can you convert .zip into .jar?
because I know .json and if you could it would be easy.
1
Wannabe TommyInnit
• 02/03/2021 9:59 am
• Level 41 : Master Magical Boy
Wannabe TommyInnit's Avatar
You can't convert .json to .jar or .zip to .jar unless it is coded in Java.
1
Dunk__
• 02/03/2021 1:31 pm
• Level 38 : Artisan Pixel Painter
Dunk__'s Avatar
oh, ok, nvm. I am learning now java
2
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome