An easy-to-use template for creating multi-loader minecraft mods for fabric and neoforge (forge for mc <= 1.20.1). Works with Minecraft 1.17 to 1.21.8+
😎 Easy to use (see the Getting started section)
🚀 Blazingly fast thanks to gradle configuration cache*
Free of copyright restrictions as it is subject to the public domain by using Unlicense
*Importing and building the project for the first time might take quite a while, but once that's done building or running the project will be pretty fast!
-
Create your repo
Click the "Use this template" button in the top right to create a repository, then clone & import your new repository into IntelliJ IDEA (or your preferred IDE) -
Add mod info
Open thesettings.gradle.ktsfile and put your mod id as the project name (at the very top of the file). Then, check thegradle.propertiesfile and set your mod info like id, package, name and authors there. -
IDE integration
First, import your repo into IDEA and import the gradle project if it isn't importing already (this might take a while). Once done, you can run thegenSourcesgradle task in the fabric category to ensure that you have access to the Minecraft source code in all modules.For neoforge, IDEA might not automatically use the right sources, and will show a blue bar at the top when viewing minecraft / neoforge sources, with a button named "attach sources" that you need to click to make it use the generated sources.
-
Rename package
In thecommon,fabricandneoforgemodules, refactor the package name fromnet.yourpackage.yourmodto your actual package name. Also adjust the java file names and themodIDfield -
Done
You can now enjoy modding in a multi-loader setup! Working run configurations are automatically generated - just select the relevant one in the top right of your IDE window and run the game right from your IDE.
Project structure
A multi-loader project consists of a root gradle project and three subprojects: common, fabric and neoforge.
The root project should not contain any code. It's build.gradle.kts file is used for some common configuration for all the subprojects.
The common subproject contains all the common mod code, which will be included in all built jars. It has access to all of Minecraft,
and the ability to add Access wideners and mixins, but no access to any mod loader's API.
It's build.gradle.kts is the place to put most of your required dependencies.
The fabric and neoforge subprojects contain initialisation and loader-specific code, as well as loader-specific resources like fabric.mod.json and neoforge.mods.toml
Switching Minecraft versions
In order to change the target Minecraft version, just set the minecraft_version property in the gradle.properties
file and adapt the other properties
(mc_versions_fabric, mc_versions_neo, parchment_version, neoforge_version,
fabric_loader_version and fabric_api_version) appropriately.
Just check the links for the latest versions for your desired minecraft version
Note that this only works for versions later than 1.20.1, because the neoforge ModDevGradle plugin only works for these newer versions.
Therefore, there is a seperate 1.20.1 branch that you need to use for Minecraft versions from 1.17 to 1.20.1. For all newer versions,
just use the 1.21.x branch and change the versions as described above.
Access wideners/Access transformers
To use access wideners, create a .accesswidener file somewhere in your common resources directory and define the path in the common/build.gradle.kts file (~ line 30).
These access wideners will be loaded in common and fabric, but they won't work on neoforge. That means you will need to create an accesstransfomer.cfg file inside
your neoforge/resources/META-INF and add the same entries to that. The access transformer file will be loaded automatically if it has the default location & file name.
More information on access wideners / More information on access transformers
Mixins
To use mixins in your project, just create a mixin configuration file (mymod.mixins.json) in your common resources and add the path of it to your
fabric.mod.json and neoforge.mods.toml files. No additional configuration required.
More about mixins: Mixin introduction / Mixin examples
Automatic Release Publishing
This template uses mc-publish to allow you to automatically publish your mod to Modrinth, Curseforge and GitHub releases.
In order to set this up, add the project IDs of your modrinth and curseforge projects
in the release.yml action file.
Then, open your GitHub repository settings, select "Secrets and Variables" and then "Actions" in the left sidebar. Next up, generate a Modrinth personal access token and use the green "New Repository Secret" button in GitHub to add the token with the name "MODRINTH_TOKEN". Repeat the process by generating a curseforge API token and adding it as a secret named "CURSEFORGE_TOKEN".
Then, you can publish your mod to Modrinth and curseforge by creating a GitHub release with no attached files. Your mod will be built to a jar file automatically, which will then be uploaded to Modrinth and curseforge and also attached to the GitHub release.
Please feel free to contact me on Discord (@player.005) or open an issue on GitHub.