Creating your config

Getting Started

Building your base

To create your config, you'll first need to create a new class that extends OneConfig's Config class, like so:

public class ExampleConfig extends Config {
}

Why do we use KtConfig for the Kotlin example?

KtConfig provides additional functionality which makes it easier to create type-safe options in Kotlin with a much more readable and serviceable syntax.

Easy, right? Now, you'll need to provide it with some info via it's constructor, which takes your config's name, category, file name and some other relating data.

The filename you pass to OneConfig is what the file will be named inside of the user's OneConfig settings profile, f.ex .minecraft/config/OneConfig/profiles/example_config.json.

public class ExampleConfig extends Config {
    public ExampleConfig() {
         super(
              "example_config.json",                // Your mod's config file's name and extension
              "/assets/examplemod/example_mod.png", // A path to a PNG or SVG file, used as your mod's icon in OneConfig's UI
              "Example Mod",                        // Your mod's name was it is shown in OneConfig's UI
              Category.QOL                          // The category your mod will be sorted in within OneConfig's UI
         );
    }
}

Simple as that!

Initializing your config when the game launches

There are various different ways to initialize your config, but here are the way we recommend:

If you are on Java, add an INSTANCE field to your config. This is where you will access your dedicated object of your config for non-static methods, such as save.

public class ExampleConfig extends Config {

    // Your actual config options here...
    
    public static final ExampleConfig INSTANCE = new ExampleConfig();
    
    // Your constructor here...
}

If you are on Kotlin and you have not already, make your config class an object. This makes your class a singleton, which essentially will create the INSTANCE field in Java for you, and make accessing it via Kotlin syntax easier.

object ExampleConfig : KtConfig(
     // Your constructor stuff here...
)

Now, all you need to do is initialize your config when the game first launches with your mod, via the preload method. This can be done using your mod loader's standard means of initializing your mod at game launch, or alternatively, by using OneConfig's events system, using the InitializationEvent.

@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION, name = ExampleMod.NAME)
public class ExampleMod {
    public static final String MODID = "examplemod";
    public static final String VERSION = "1.0.0";
    public static final String NAME = "Example Mod";
    
    @Mod.EventHandler
    public void onInitialize(FMLInitializationEvent event) {
        ExampleConfig.INSTANCE.preload();  // Ensures that everything is set up as it should be!
    }
}

Last updated