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 {
}object ExampleConfig : KtConfig() // This is an object so we can easily access a singleton instance of the config. Refer to later section for more infoWhy 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
);
}
}object ExampleConfig : KtConfig(
id = "example_config.json", // Your mod's config file's name and extension
icon = "/assets/examplemod/example_mod.png", // A path to a PNG or SVG file, used as your mod's icon in OneConfig's UI
title = "Example Mod", // Your mod's name was it is shown in OneConfig's UI
category = Config.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.
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.
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.
Last updated