LibJF/docs/libjf-config-v0.md

1.8 KiB

libjf-config-v0

LibJF config provides config screens and is partially based on TinyConfig and MidnightLib It depends on libjf-unsafe-v0 to ensure configs are loaded before you use them and libjf-base To add a config create a class using only static fields with default values like this:

import io.gitlab.jfronny.libjf.config.api.JfConfig;
import io.gitlab.jfronny.libjf.config.api.Entry;
import io.gitlab.jfronny.libjf.gson.GsonHidden;

public class TestConfig implements JfConfig {
    @Entry public static boolean disablePacks = false;
    @Entry public static Boolean disablePacks2 = false;
    @Entry public static int intTest = 20;
    @Entry(min = -6) public static float floatTest = -5;
    @Entry(max = 21) public static double doubleTest = 20;
    @Entry public static String dieStr = "lolz";
    @Entry @GsonHidden public static String guiOnlyStr = "lolz";
    public static String gsonOnlyStr = "lolz";
    @Entry public static Test enumTest = Test.Test;

    public enum Test {
        Test, ER
    }
}

You MUST annotate any field configurable through the UI as @Entry and the class MUST extend JfConfig. You MAY annotate fields as @GsonHidden to not serialize them (-> libjf-base). Numeric values MAY have a min and max value specified in their @Entry.

To register a config, add a libjf:config entrypoint pointing to its class to your fabric.mod.json. To manually register a config or save changes, use io.gitlab.jfronny.libjf.config.api.ConfigHolder For example, to save a config for a mod titled yourmod:

ConfigHolder.getInstance().getRegistered().get("yourmod").write();

LibJF config is only intended for simple config screens, it does not support nested classes, multiple pages or controls like sliders. Use something else for those