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.

Last updated

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#

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.

src/main/java/com/example/mymod/compat/MyModSettingsSaver.java
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:

src/main/resources/META-INF/services/dev.xichil.settingssaver.api.v1.SettingsSaverPlugin
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.

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#

  1. Build your mod and put the jar into an instance that has Settings Saver installed.
  2. 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.

  1. If your mod is not saved by default, close the game and turn it on for the profile: add enabled.mymod=true to profiles/default/profile.properties in the Settings Saver store (the wiki shows players how). Start the game again.
  2. Open Options, Settings Saver... and press Save settings to profile.
  3. Look in the store. Your file is there, next to a module.txt that records the versions it was saved in:
profiles/default/mymod/config/mymod.properties
profiles/default/mymod/module.txt
  1. Create a new instance with both mods and start it. Its config/mymod.properties now holds the saved settings.

No Registered line? See Fix an integration that doesn't sync.

Next steps#