-
Notifications
You must be signed in to change notification settings - Fork 1
Creating Configs
Creating a configuration file is extremely easy. First, create a ConfigManager
instance somewhere. Ideally, this will be in your mod constructor:
public YourMod(IEventBus modEventBus) {
// Creates a config named "modid.json"
new ConfigBuilder("modid", ConfigEntries.class).build();
}
Then, define a class that contains your configuration entries:
public static class ConfigEntries {
@ConfigEntry
public static int testIntOption = 50; // Creates a JSON key named "testIntOption" with a default value of 50
}
That's the bare minimum required to start using Cobalt Config. You can access the values directly via static references. This type of configuration will automatically sync from servers to clients during the login process or after running /reload
in-game.
You can add a suffix to the filename (like modid-suffix.json
). This is useful if you use separate common
and client
configurations.
public YourMod(IEventBus modEventBus) {
// Creates a config named "modid-suffix.json"
new ConfigBuilder("modid", "suffix", ConfigEntries.class).build();
}
Config names are used to provide a friendly name when using the configuration menu. By default, the classname of the config class is used.
public YourMod(IEventBus modEventBus) {
new ConfigBuilder("modid", ConfigEntries.class)
.setConfigName("Friendly Configuration Name")
.build();
}
You can also pass a translation string if you would like.
Client-only configurations do not generate on dedicated server environments and are not synced anywhere.
public YourMod(IEventBus modEventBus) {
new ConfigBuilder("modid", ConfigEntries.class)
.setClientOnly(true)
.build();
}
You can place comments inside annotations which will be displayed underneath entries in the configuration menu. Comments have no effect on the configuration file itself.
@ConfigEntry(comment = "This is an int config option")
public static int testIntOption = 50;
Translation strings are supported.
For number-type values, min/max bounds can be declared. When loading a configuration that has out-of-bounds values, the values will be clamped to within the delcared range.
When both min/max bounds are specified, the configuration menu will use a slider widget to represent the entry.
@ConfigEntry(min = 0, max = 100)
public static int testIntOption = 50;
You can define groups for entries, and entries with the same group will be placed together in the configuration menu. Groups have no effect on the configuration file itself.
@ConfigEntry(group = "Test Group")
public static int testIntOption = 50;
Translation strings are supported.
If an entry requires a restart for changes to take effect, you can mark it as such. This will not prevent the value from being updated or synced, but it indicates to the user that it will not be utilized until a restart.
@ConfigEntry(restartRequired = true)
public static int testIntOption = 50;