Skip to content

Registering Preferences

Preferences are persistent key-value settings for the Packed Packs screen.

The PackedPacksApi instance injected on the entrypoint provides the PreferenceRegistry instance which allows the reigstration of preferences.

Method Description
register(id, type, defaultValue) Register objects using the default serialization strategy.
register(id, defaultValue) Helper for primitive types and String.
register(id, type, default, deser, ser) Register complex objects with custom serialization.
java
@Override
public void onInitialize(PackedPacksApi api) {
    PreferenceRegistry preferences = api.preferences();
    Preference<Boolean> enableOverlay = preferences.register(
        Identifier.fromNamespaceAndPath("mymod", "enable_overlay"), 
        true
    );
}

Accessing and Updating Values

Preference<T> handles the state of your setting.

  • get(): Retrieves the current value.
  • set(value): Updates the value in memory.
  • reset(): Reverts to the default value.

NOTE

Changes made via set are kept in memory and are only saved to disk when the user closes the Packed Packs screen.