This is an old revision of the document!
Table of Contents
Setting up a mod development environment
Prerequisites
- A Java Development Kit (JDK) for Java 21 (recommended for 1.20.5) or newer. Visit https://adoptium.net/releases.html for installers.
- If you are professional, you can obtain a JDK from http://jdk.java.net/, which needs to be extracted and have system variables set up manually.
- Any Java IDE, for example Intellij IDEA and Eclipse. You may also use any other code editors, such as Visual Studio Code.
- If you are not familiar with any of these, we recommend to use Intellij IDEA as that is what most people choose for modding.
Mod Setup
Manual Steps
- Copy the starting files from fabric-example-mod (or from the template generator, if you wish to use Kotlin or other featues.) excluding the
LICENSE
andREADME.md
files - as those apply to the template itself, not necessarily to your mod. - Edit
gradle.properties
:- Make sure to set
archives_base_name
andmaven_group
to your preferred values. - Make sure to update the versions of Minecraft, the mappings, the loader and the loom - all of which can be queried through https://fabricmc.net/develop/ - to match the versions you wish to target.
- Add any other dependencies you plan to use in
build.gradle
.
- Import the build.gradle file to your IDE. You may refer to the next section for specific IDE's.
- Happy modding!
Fabric Mod ID Change
As of Minecraft 1.19.2, Fabric API's mod ID has changed from fabric
to fabric-api
. When backporting from 1.19.2 to earlier versions, you must alter the depends
section of your fabric.mod.json
to expect fabric
.
IntelliJ IDEA
If you are using IntelliJ IDEA by JetBrains, please follow these steps:
- In the IDEA main menu, select 'Import Project' (or File → Open… if you already have a project open).
- Select the project's build.gradle file to import the project.
- After Gradle is done setting up, close (File → Close Project) and re-open the project to fix run configurations not displaying correctly.
- (If the run configurations still don't show up, try reimporting the Gradle project from the Gradle tab in IDEA.)
Optional, but recommended: By default, IntelliJ delegates to Gradle to build the project. This is unnecessary for Fabric and causes longer build times and hotswapping related weirdness, among other problems. To make it use the builtin compiler:
- Open the 'Gradle Settings' dialog from the Gradle tab.
- Change the 'Build and run using' and 'Run tests using' fields to 'IntelliJ IDEA'.
Unfortunately, it is currently impossible to set an IDE-wide default for the 'Build and run using' and 'Run tests using' options, so these steps have to be repeated for every new project.
NOTE: Don't run the idea
gradle task. It is known to break development environment.
If you are using IntelliJ IDEA you can use the MinecraftDev plugin. This plugin adds support for automatically generating Fabric projects as well as some mixin related features like inspections, generating accessors/shadow fields, and copying Mixin Target References (JVM Descriptors). You can install it using IntelliJ's internal plugin browser by navigating to File → Settings → Plugins, then clicking the Marketplace tab and searching for Minecraft.
NOTE: The default template in the mcdev plugin blindly uses the latest unstable version of the loom. Use with caution.
Eclipse
If you are using Eclipse and you would like to have the IDE run configs you can run gradlew eclipse
. The project can then be imported as a normal (non-gradle) Eclipse project into your workspace using the 'File' - 'Import…' menu, then 'General' → 'Existing Projects into Workspace'.
Visual Studio Code
If you are using VSCode, please follow these instructions.
Generating Minecraft Sources
Reading the Minecraft source is an essential part of modding. Unfortunately, we can't publish the Minecraft source because it violates the Minecraft EULA. You need to generate the Minecraft source yourself.
To generate the Minecraft source. run the genSources
gradle task.
If your IDE doesn't have gradle integration, run the following command in the terminal: gradlew genSources
(or ./gradlew genSources
on Linux/macOS).
It can take a while depending on your computer power.
You may need to refresh gradle after running the task.
See Reading the Minecraft source for how to read the source.
Getting started
Try adding an item or a block. It's also a good idea to visit Applying changes without restarting Minecraft.
Advice
- While Fabric API is not strictly necessary for developing mods, its primary goal is to provide cross-compatibility and hooks where the game engine does not, and as such it is highly recommended! Even some of the tutorials on the wiki implicitly require Fabric API.
- Occasionally, with development of fabric-loom (our Gradle build plugin) issues may crop up which require resetting the cache files. This can be done by running
gradlew cleanloom
. Runninggradlew --stop
can also help with a few rare issues. - Keep up with the latest Loom version (which is defined in
build.gradle
) and the Fabric Loader and Fabric API version for your mod (which is defined inbuild.gradle
orgradle.properties
). Latest version can be found in https://fabricmc.net/develop/. Even the old version Minecraft is supported by latest Loom and latest Fabric Loader. - Keep up with the latest Gradle version, which can be defined in
gradle/wrapper/gradle-wrapper.properties
. Old version Minecraft is supported by latest Gradle.- Different Gradle versions require different Java versions.
- If you're developing mods for old version Minecraft, besides changing
gradle.properties
, you may also need to change the Java compatibility version inbuild.gradle
and the mixin config. - Don't hesitate to ask questions! We're here to help you and work with you to make your dream mod a reality.
Troubleshooting
"no usages" on every method
After running the genSources
gradle task in IntelliJ IDEA, check if the sources are attached properly. Open a Minecraft .class file and click on the “Choose Sources…” button on the top right of the screen. Select the jar with “-sources” at the end (e.g. .gradle\loom-cache\1.20.1\net.fabricmc.yarn.1_20_1.1.20.1+build.10-v2\minecraft-project-@-merged-named-sources.jar
)
Missing sounds
Sometimes, when importing the Gradle project into an IDE, the assets might not download correctly. In this case, run the downloadAssets
task manually - either using IDE's built-in menu or by simply running gradlew downloadAssets
.
Could not find or load class net.fabricmc.devlaunchinjector.Main: java.lang.ClassNotFoundException / "no JDK module specified" in the run config
It seems to be a bug of Intellij IDEA since a recent update 2023.2. To fix, just delete the `.idea` folder entirely and then restart Intellij IDEA. The module will be reconstructed. You may need to specify Java versions again. If after restarting there is no run config, you can run `gradle ideaSyncTask` then check it again.
java.lang.ClassNotFoundException: net.fabricmc.loader.impl.launch.knot.KnotClient / java.lang.TypeNotPresentException: Type net/minecraft/util/Identifier not present / java.lang.RuntimeException: Minecraft game provider couldn't locate the game! The game may be absent from the class path, lacks some expected files, suffers from jar corruption or is of an unsupported variety/version.
This may be because the project path contains non-ASCII characters that may cause incompatibility. Try move the project to paths without non-ASCII characters, or in the run config of “Minecraft Client” and “Minecraft Server”, set “Shorten Command Line” from “@argfile (Java 9+)” to “none”.
What's Next?
Create your first item.