Set what is saved by default

Decide whether profiles save your mod's settings without being asked, and which keys stay per instance, with savedByDefault and excludedByDefault.

Last updated

Steps

Two builder calls set the starting point for every profile: whether your mod is saved at all, and which keys are left out. The player can change both per profile, and the player's choice always wins.

Prerequisites#

Saved by default, or not#

By default a registered mod is off: nothing of it is saved or loaded until the player turns it on for a profile.

ModSettings.builder("mymod", "My Mod", "2.1.0")
        .file("config/mymod.properties", SettingsFileFormats.PROPERTIES)
        .savedByDefault(true)
        .build();

With .savedByDefault(true), every profile saves your mod's settings unless the player turned that off.

Your settings are… Use
the player's own: controls, accessibility, HUD layout .savedByDefault(true)
usually part of a modpack's setup: gameplay tweaks, server lists a pack ships leave it off
a mix leave it off, or turn it on and exclude the pack-specific keys

How the player's choice is stored: a line enabled.mymod=true or enabled.mymod=false in the profile's profile.properties. Without that line, your default applies.

savedByDefault Player's line Saved?
not called, or false none no
not called, or false enabled.mymod=true yes
true none yes
true enabled.mymod=false no

Exclude keys by default#

Some values belong to one machine or one instance: window positions, absolute paths, the last world or server joined, caches. Excluded keys are neither saved into the profile nor loaded from it, so each instance keeps its own value.

ModSettings.builder("mymod", "My Mod", "2.1.0")
        .file("config/mymod.properties", SettingsFileFormats.PROPERTIES)
        .excludedByDefault("lastServer", "window.*")
        .build();

Pattern rules:

Pattern Matches
lastServer the key lastServer, exactly
window.* every key that starts with window., such as window.x and window.y
key_* every key that starts with key_

Defaults stop applying once the player edits the list#

A profile follows your list until the player edits your mod's exclusions in that profile. From then on the profile keeps the player's list, stored as exclude.mymod= in profile.properties. Changes to your defaults in later versions of your mod don't reach that profile. The player can reset the list to your defaults in the Excluded settings screen.

So choose the defaults carefully in your first release, and don't rely on a later version adding one.

Example: on by default, machine-specific keys excluded#

MyModSettingsSaver.java
@Override
public void register(SettingsSaverRegistrar registrar) {
    registrar.register(ModSettings.builder("mymod", "My Mod", "2.1.0")
            .file("config/mymod.properties", SettingsFileFormats.PROPERTIES)
            .savedByDefault(true)                         // HUD layout and controls follow the player
            .excludedByDefault("window.*", "lastServer")  // these stay with the instance
            .excludedByDefault("cacheDir")
            .build());
}

Next steps#