Build one integration for every loader
Ship one Settings Saver plugin class and one service file in every jar of a mod that supports Fabric, Quilt, Forge and NeoForge from 1.7.10 to 26.3.
Steps
- Prerequisites
- The idea
- Steps
- 1. Put the plugin class in the shared source set
- 2. Put the service file in the shared resources
- 3. Add the API to the shared source set only
- 4. Build one jar per loader family
- 5. Read your config at a safe point
- 6. Describe version differences with fixes
- 7. Use one mod id and one version everywhere
- Why one service file works on every loader
- Check each jar
- Checklist
- Next steps
The Settings Saver API has no Minecraft or loader classes, so a mod that ships for many loaders and Minecraft versions writes its integration once. This guide shows where the plugin class and the service file go in a multi-loader project, and what to check in each jar.
Prerequisites#
- Your first integration
- A mod that builds more than one jar, or will. If you are setting that up now, Build one mod for every loader in the Xi's Multiversion UI Lib docs describes the project layout used here in full.
The idea#
A multi-loader mod has shared code and a thin layer per loader family:
| Layer | Contains | Settings Saver integration |
|---|---|---|
Shared (src/main) |
config, logic, everything without Minecraft classes | the plugin class, formats, fixes, merger, and the service file |
| Entry (one source set per loader family) | the loader's entry class and mod metadata | nothing |
| Game (per Minecraft version range, if needed) | code that calls Minecraft | nothing |
Everything for Settings Saver lives in the shared layer. The entry classes don't mention it, and no metadata file declares it.
| What differs per loader | Who handles it |
|---|---|
| How the plugin is found | Settings Saver, through java.util.ServiceLoader on every loader |
| When the plugin runs | Settings Saver (When plugins run) |
| Where your mod reads its config | you, in each entry class (Read your config after the restore) |
| How a setting is stored on old and new Minecraft | you, with Minecraft fixes |
Steps#
1. Put the plugin class in the shared source set#
package com.example.mymod.compat;
import com.example.mymod.MyMod;
import dev.xichil.settingssaver.api.v1.ModSettings;
import dev.xichil.settingssaver.api.v1.SettingsFileFormats;
import dev.xichil.settingssaver.api.v1.SettingsSaverPlugin;
import dev.xichil.settingssaver.api.v1.SettingsSaverRegistrar;
/** Only Settings Saver loads this class. Nothing else in the mod may reference it. */
public final class MyModSettingsSaver implements SettingsSaverPlugin {
@Override
public void register(SettingsSaverRegistrar registrar) {
registrar.register(ModSettings.builder(MyMod.MOD_ID, "My Mod", MyMod.VERSION)
.file("config/mymod.properties", SettingsFileFormats.PROPERTIES)
.minecraftFix("1.13", new ZoomKeyFix())
.build());
}
}
MyMod.MOD_ID and MyMod.VERSION are public static final String constants with literal values. The
Java compiler copies such constants into the class that uses them, so the plugin doesn't load MyMod at
run time. Don't call methods of your other classes from the plugin.
2. Put the service file in the shared resources#
com.example.mymod.compat.MyModSettingsSaver
Because it is a shared resource, it is packed into every loader family's jar together with the shared classes.
3. Add the API to the shared source set only#
repositories {
maven("https://maven.xichil.dev")
}
// Java 8 bytecode runs on every Minecraft version from 1.7.10 to 26.3.
tasks.withType<JavaCompile>().configureEach {
options.release = 8
}
dependencies {
// Shared code compiles against the API. No jar ever contains it.
compileOnly("dev.xichil.settingssaver:settingssaver-api:1.0.0")
}
The entry source sets don't need the API: they never reference it.
4. Build one jar per loader family#
Each jar packs the shared classes and resources plus one family's entry classes and metadata:
val main: SourceSet = sourceSets["main"]
// sourceSet name -> jar classifier
val families = mapOf(
"fabric" to "fabric",
"modlauncher" to "modlauncher",
"forgeLegacy" to "forge-1.8-1.12.2",
"forgeCpw" to "forge-1.7.10",
)
families.forEach { (name, classifier) ->
val set = sourceSets.create(name) {
compileClasspath += main.output
}
val familyJar = tasks.register<Jar>("${name}Jar") {
archiveClassifier = classifier
from(main.output, set.output) // main.output includes META-INF/services
}
tasks.assemble { dependsOn(familyJar) }
}
// The shared classes alone load on no loader.
tasks.jar { enabled = false }
| Jar | Loaders and versions |
|---|---|
mymod-<version>-fabric.jar |
Fabric and Quilt 1.14 to 26.3, Legacy Fabric 1.7.10 to 1.13.2 |
mymod-<version>-modlauncher.jar |
Forge 1.13.2 to 26.3, NeoForge 1.20.1 to 26.3 |
mymod-<version>-forge-1.8-1.12.2.jar |
Forge 1.8 to 1.12.2 |
mymod-<version>-forge-1.7.10.jar |
Forge 1.7.10 |
Drop the families you don't support. The entry classes and metadata for each family are in A multi-loader mod.
5. Read your config at a safe point#
A fresh instance gets your saved file while the game starts, at a point that differs per loader. Two patterns are safe on all of them:
- call a shared
init()that reads the config from each loader's init or setup event, or - load the config lazily on first use, which needs no loader code at all.
Don't read it in a @Mod constructor or a static initializer. See
Read your config after the restore.
6. Describe version differences with fixes#
One profile serves the 1.7.10 instance and the 26.3 instance. Where your mod stores a setting differently on some Minecraft versions, register a Minecraft fix. Where your mod's own versions differ, register a mod version fix. Both are plain Java in the shared layer.
If every jar of one release writes the same file format, you need no fixes at all.
7. Use one mod id and one version everywhere#
Pass the same mod id and the same version string from every jar. The mod id names your folder in the profile, so a jar that used another id would get a separate, empty set of saved settings. The version decides which mod version fixes run.
Why one service file works on every loader#
java.util.ServiceLoader is part of the JDK, so no loader-specific code is needed:
| Loader | How the service file is found |
|---|---|
| Fabric, Quilt, Legacy Fabric | every mod jar is on the game's class loader, which serves META-INF/services |
| Forge 1.7.10 to 1.12.2 | mod jars join the class loader when Forge discovers mods; Settings Saver looks then |
| Forge 1.13.2 to 1.16.5 | through the game's class loader |
| Forge 1.17 and newer, NeoForge | the service file becomes a provides clause of your jar's automatic module, found through the module layer |
Check each jar#
For every jar you ship:
- List its contents and confirm the service file is there:
unzip -l build/libs/mymod-2.1.0-fabric.jar | grep META-INF/services
- Confirm no
dev/xichil/settingssaver/classes are inside: the API must not be bundled. - Start one instance per loader family with Settings Saver installed and look for the
[Settings Saver] Registered My Modline in the log. - Start the same instances without Settings Saver and confirm your mod starts normally.
Checklist#
- [ ] The plugin class, formats, fixes and merger are in the shared source set and use only the JDK and the API.
- [ ] The service file is in the shared resources and ends up in every jar.
- [ ] The API is
compileOnlyand in no jar. - [ ] Shared code compiles with
options.release = 8. - [ ] Every jar passes the same mod id and version.
- [ ] No entry class and no other class references the plugin class.
- [ ] Config is read in the init or setup event, or lazily on first use, never in a constructor or static initializer.
Next steps#
- A multi-loader mod: every file of a project with this layout.
- Settings across versions: fixes for a mod that spans Minecraft eras.