Your first integration
Write a plugin class and a service file so Settings Saver saves and syncs your mod's config file, then check that the file reaches a profile.
Steps
By the end of this page Settings Saver knows your mod's config file, saves it into a profile and gives it to new instances.
Prerequisites#
- Installation done: the API is a
compileOnlydependency. - A mod with a settings file inside the game directory. The examples use
config/mymod.properties:
renderDistance=12
showHud=true
windowX=120
Steps#
1. Create the plugin class#
Make a class of its own that implements
SettingsSaverPlugin. Settings Saver calls
its register method once, early in the launch.
package com.example.mymod.compat;
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", "My Mod", "2.1.0")
.file("config/mymod.properties", SettingsFileFormats.PROPERTIES)
.build());
}
}
The class must be public, have a public no-argument constructor (the default one is fine) and be a top-level class or a static nested class.
2. Describe your settings#
Everything Settings Saver needs is in the ModSettings you build:
| Part | In the example | Meaning |
|---|---|---|
| mod id | "mymod" |
Your mod id as your loader knows it. It names your folder in every profile, so never change it. |
| display name | "My Mod" |
The name players see in Settings Saver. |
| mod version | "2.1.0" |
The running version of your mod. Recorded with every save. |
| file | "config/mymod.properties" |
A path relative to the game directory. |
| format | SettingsFileFormats.PROPERTIES |
How the file is read: here key=value lines, so settings sync one by one. |
At least one file or directory is required. Everything else is optional and covered in the guides.
3. List the class in a service file#
Create a text file named after the plugin interface, containing the full name of your class:
com.example.mymod.compat.MyModSettingsSaver
The file must end up at META-INF/services/dev.xichil.settingssaver.api.v1.SettingsSaverPlugin inside
your mod's jar. Settings Saver finds it with java.util.ServiceLoader. When Settings Saver isn't
installed, nothing reads the file, so your plugin class is never loaded.
4. Keep the plugin class isolated#
The plugin class is the one place in your mod that references the API.
- Don't reference
MyModSettingsSaverfrom your other classes. - Inside it, don't touch Minecraft classes, don't load your config and don't do slow work. It runs during
startup, possibly before the game or your mod is set up. Build a
ModSettingsand hand it over.
5. Decide whether it is on by default#
As written above, your mod is listed in Settings Saver but nothing is saved until the player turns
your mod on for a profile. To have it saved without that step, add .savedByDefault(true):
registrar.register(ModSettings.builder("mymod", "My Mod", "2.1.0")
.file("config/mymod.properties", SettingsFileFormats.PROPERTIES)
.savedByDefault(true) // leave this out to stay off until the player turns it on
.excludedByDefault("windowX") // this key stays per instance
.build());
Only do that when the settings clearly belong to the player and not to a modpack. See Set what is saved by default.
Check it worked#
- Build your mod and put the jar into an instance that has Settings Saver installed.
- Start the game and search the log for
[Settings Saver] Registered. You should see:
[Settings Saver] Registered My Mod (mymod 2.1.0): [config/mymod.properties], not saved unless turned on in a profile
With .savedByDefault(true) the line ends in saved by default.
- If your mod is not saved by default, close the game and turn it on for the profile: add
enabled.mymod=truetoprofiles/default/profile.propertiesin the Settings Saver store (the wiki shows players how). Start the game again. - Open Options, Settings Saver... and press Save settings to profile.
- Look in the store. Your file is there, next to a
module.txtthat records the versions it was saved in:
profiles/default/mymod/config/mymod.properties
profiles/default/mymod/module.txt
- Create a new instance with both mods and start it. Its
config/mymod.propertiesnow holds the saved settings.
No Registered line? See Fix an integration that doesn't sync.
Next steps#
- Register files and directories: more files, whole folders.
- Choose a file format: what "key by key" changes.
- Read your config after the restore: where to load your config so a new instance sees the saved file on every loader.
- A properties config: this integration as a complete example.