AllanChain / blog

Blogging in GitHub issues. Building with Astro.
https://allanchain.github.io/blog/
MIT License
13 stars 0 forks source link

Modding with Minecraft Fabric: start w/o Java knowledge #140

Open AllanChain opened 4 years ago

AllanChain commented 4 years ago

View Post on Blog

Thats challenging but possible


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%\bin

Build Fresh Mod!

Clone mod repo and run (varies between OS):

gradlew build

This 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:

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 tasks

to 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 genSources

This 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 vscode

Now Minecraft Client and Minecraft Server option is available in the debug panel!