Tip for testing datapacks: https://modrinth.com/mod/packtest
For setup instructions please see the fabric wiki page that relates to the IDE that you are using.
Download and install the propper Java development kit (JDK) version from AdoptOpenJDK. To see what version of Java you need, check the minecraft wiki. Currently, these are the latest java version requirements for minecraft:
- From Minecraft 1.17.1 and up: Java 16
- From Minecraft 1.18 and up: Java 17
- From Minecraft 1.20.5 and up: Java 21
Install an IDE of your choice. We recommend using IntelliJ IDEA Community Edition.
If you want to start a new project, you can use the FabricMC template mod generator. Make sure you:
- give your mod a name,
- enter a mod ID,
- choose a unique package name,
- select the propper minecraft version,
- check the
Data Generationcheckbox! - uncheck the
Split client and common sourcescheckbox! (Not confirmed yet, but it's recommended by Kaupenjoe (When creating server mods, I would expect this should be checked))
Add the downloaded files to a git repo and open the project in your IDE.
Alternatively, you can use an existing project.
If you open the project in IntelliJ IDEA, the project should be automatically configured. After the configuration is done, follow the following steps:
- Go to
File->Project Structure->Project->SDKand select the proper JDK version. - Go to
File->Settings->Build, Execution, Deployment->Build Tools->Gradleand make sure thatGradle JVMis set to theProject SDK. - In the project browser, click the options menu (three dots) and under
Tree Appearance, make sure thatFlatten PackagesandCompact Middle Packagesare unchecked. (This is a personal preference)
I'll refer to the project root folder as <ROOT>.
The server code is located in the src/main/java/net/<author>/<modid> folder. In this guide, I'll use the <BACKEND> placeholder to refer to this folder.
The resources are located in the src/main/resources folder. In this guide, I'll use the <RESOURCES> placeholder to refer to this folder.
- In the
<BACKEND>folder, you'll find a class implementing theModInitializerclass. This is the main class of your mod.- Refactor the
MOD_IDto your mod ID in snake case (all lowercase or numbers, words separated by underscores). - Refactor the class
ExampleModto your mod name in camel case (first letter of each word is capitalized, no underscores).
- Refactor the
- If you've got an
ExampleModDataGeneratorclass, refactor it to your mod name in camel case, suffixed withDataGenerator. - In the
<RESOURCES>/assets/modidfolder, you'll find an icon for your mod. Replace this icon with your own icon or remove it. - Open the
<RESOURCES>/fabric.mod.jsonfile.- Make sure that the
idfield is set to your mod ID. - Set the
namefield to your mod name. - Set the
descriptionfield to a short description of your mod. - Add your mod's authors to the
authorsfield. - Change your mod's license in the
licensefield. - Set the
iconfield to the path of your mod's icon. - In the
entrypointsfield, make sure that the entrypoints are updated correctly to your previously refactored classes. - For the
dependsandsuggestfields, refer to the manage dependencies section.
- Make sure that the
Your mod version can be changed in the <ROOT>/gradle.properties file using the mod_version property.
The version should specify your own version number, following the Semantic Versioning standard.
It's also recommended to specify the Minecraft version in the version number.
Use the following format to specify your mod version: <major>.<minor>.<patch>-<minecraft_version>.
<major>: The major version of your mod.<minor>: The minor version of your mod.<patch>: The patch version of your mod.<minecraft_version>: The Minecraft version that your mod is compatible with.
For example, if your mod is compatible with Minecraft 1.20.1, you could use the version 1.0.0-1.20.1.
When changing the Java, Minecraft, or Fabric versions, you must update the versions in two separate files:
- The
<ROOT>/gradle.propertiesfile specifies the versions that will be used to compile your mod. - The
<RESOURCES>/fabric.mod.jsonfile specifies the versions that your mod is compatible with.
In the <ROOT>/gradle.properties file, defines some variables that will be used in the <ROOT>/build.gradle file.
- The
minecraft_versionproperty specifies the Minecraft version what will be used when compiling the mod. - The
loader_versionproperty specifies the Fabric loader version what will be used when compiling the mod. - The
yarn_mappingsproperty specifies the Yarn mappings version what will be used when compiling the mod.- These mappings are used to map the obfuscated Minecraft code to human-readable names.
- The
fabric_versionproperty specifies the Fabric API version what will be used when compiling the mod.
The recommended versions can be found using a fabric tool found here.
You can add additional libraries or mods into the build.gradle and refer to a custom variable defined in the gradle.properties file.
In the <RESOURCES>/fabric.mod.json file, you'll find a depends object.
This object defines what versions of which dependencies are required for your mod to run.
In other words, this object defines what versions could be used.
- The
fabricloaderdependency defines the version of the Fabric loader that is required to run your mod. A changelog of the Fabric loader can be found here. - The
minecraftdependency defines the version of Minecraft that your mod is compatible with. A changelog of the Minecraft versions can be found here. - The
javadependency defines the version of Java that your mod is compatible with. A changelog of the Java versions can be found here. Make sure that the Java version is compatible with the Minecraft version. - The
fabric-apidependency defines the version of the Fabric API that your mod is compatible with. Check for compatibility on the CurseForge or Modrinth page of the Fabric API. - You can also add other dependencies that your mod requires to run.
When updating the dependencies, make sure to update your compilation targets as well.
Versions are usually defined according to the Semantic Versioning standard. You can use several operators to define the version:
*matches any version.=1.2.3matches exactly version 1.2.3.>=1.2.3matches any version equal or greater than 1.2.3.>1.2.3matches any version greater than 1.2.3.<=1.2.3matches any version equal or less than 1.2.3.<1.2.3matches any version less than 1.2.3.^1.2.3matches any version equal or greater than 1.2.3 but less than 2.0.0 (major version is fixed).~1.2.3matches any version equal or greater than 1.2.3 but less than 1.3.0 (minor version is fixed).
Dependencies can be added to one of the following blocks:
dependenciesblock: A failure to match causes a hard failure.recommendsblock: A failure to match causes a warning.suggestsblock: These dependencies are not matched and are primarily used as metadata.conflictsblock: A successful match causes a warning.breaksblock: A successful match causes a hard failure.
All this and more information can be found in the Fabric documentation.
Before you can browse the source files of a dependency, you need to make sure you configure the source files in the build.gradle file.
After configuring, you can reload the project and generate the source files.
./gradlew --refresh-dependencies
./gradlew genSourcesAfter generating the source files, you'll need to tell your IDE what source files to use. In this example, we'll configure this in IntelliJ IDEA for the Minecraft source files.
- In your project browser, go to
<BACKEND>/mixin/ExampleMixinandCtrl+Clickon theMinecraftServerclass. - You'll see a blue popup with a message telling you the sources could not be found.
- Click on the
Choose Sources...button and choose the jar file ending with-sources.jar
In some source files, you'll see some errors. You can ignore those but you now have a much more representative view of the Minecraft source files.
All gradle commands can be found in the gradle tab, on the right side of your IDE. Use the following gradle commando's to:
- run a server with your mod: Tasks -> fabric -> runServer
- run a client with your mod: Tasks -> fabric -> runClient
- build your mod: Tasks -> build -> build
This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects.