Making a mod in Java is challenging for a hobby programer in Python and JavaScript world. Starting a mod from scratch is even more challenging, and as I am just playing with minecraft mods, I chose to start with a existing mod, Draylar/identity.
Get Java Ready #
JDK, JRE #
JRE (Java Runtime Environment): essential for Java application to run
JDK (Java Development Kit): Includes JRE, with tools to compile Java source Code
Not Enough? #
As a (fresh) Minecraft player, I have already installed jre8. And I also have openjdk8 installed with Android Studio. However thats not enough.
openjdk does not include JavaFX, which is required for HMCL. And jre8 does not include tools to compile. So let's get official Java SE Development Kit 8 .(Most mods use this version.)
Setup Env and Config #
For example:
JAVA_HOME=/path/to/jdk
JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8
PATH=.....%JAVA_HOME%\binBuild Fresh Mod! #
Clone mod repo and run (varies between OS):
gradlew buildThis will download correct gradle wrapper version, Minecraft client & server jar, and other dependencies.
It may take some time to finish.
If network connection is poor, you can:
- manually extract downloaded gradle release (e.g.
gradle-6.5-bin.zip) to$HOME\.gradle\wrapper\dists\gradle-6.5-bin\<hash>\and touchgradle-6.5-bin.zip.ok - manually put
minecraft-1.16.1-<server/client>.jarto$HOME\.gradle\caches\fabric-loom\ - then restart building process
Get docs #
You will get confused with the code quickly if you just read fabric wiki. Where are docs for all these APIs?
Just go to fabric's own maven repo, navigate to net/fabricmc/yarn/<build-folder>, download and extract javadoc.jar, and you will get docs for net.minecraft.blahblah
And net/fabricmc/sponge-mixin for mixins.
But docs are no very useful, you often need the source code.
Quick Tip: What Commands are Supported? #
gradlew tasksto see all the tasks.
Generate Minecraft Source #
You will still get confused with mixin injections without Minecraft source: inject to what?
Generate Minecraft source by:
gradlew genSourcesThis will decompile Minecraft and download game assets. Open the project in VSCode, maybe wait a while for project to be imported. You can now right click class or method name and select "go to implementations" to see the source.
Debug the Mod #
Nobody would like to build the mod, drag the jar to mods directory, restart minecraft game, to see the effect. To debug right inside VSCode, generate launch.json:
gradlew vscodeNow Minecraft Client and Minecraft Server option is available in the debug panel!