JasonConfig
This is a library mod — regular users just need to install it without reading further!
For Developers
Adding Dependency
It's recommended to use CurseMaven to add the dependency. Example of adding (note that this is just a template, the actual mod identifier differs):
implementation "curse.maven:cloth-config-348521:5987045"
Advantages and Disadvantages Compared to Forge's Configuration System
Advantages:
- Uses JSON instead of TOML, which increases reliability (for example, Forge configs struggle with empty lists)
- Supports reading and writing more Java/Minecraft classes (for example, Vec3, which doesn't work in Forge configs)
- Simpler code while maintaining similarity to creating Forge configuration classes
Disadvantages:
- Less user-readable due to JSON format
- Experimental status — undiscovered bugs may exist
- No side-specific config separation (client/server) like in Forge's "serverconfigs" system
Configuration Example
Complete example can be found in the "api" package after adding the dependency. All elements are well documented.
public class SimpleExampleConfigClass {
public static final Config EXAMPLE_CONFIG = new Config(MODID + "-example_config");
///The following configuration values are automatically added to the passed Config
public static final ConfigValue<Float> EXAMPLE_FLOAT = new ConfigValue<>(10f, "exampleFloat", EXAMPLE_CONFIG);
///Comments are placed in declaration order
public static final ConfigComment EXAMPLE_COMMENT = new ConfigComment("This is a list!", EXAMPLE_CONFIG);
public static final ConfigValue<List<String>> EXAMPLE_LIST = new ConfigValue<>(List.of("value1", "value2", "value3", "value4"), "exampleList", EXAMPLE_CONFIG);
public static final ConfigComment VEC3_COMMENT = new ConfigComment("This is a Vec3! Many Java classes that don't work in Forge configs work here!", EXAMPLE_CONFIG);
public static final ConfigValue<Vec3> EXAMPLE_VEC3 = new ConfigValue<>(new Vec3(123,123,123), "exampleVec3", EXAMPLE_CONFIG);
///This method must be called in your mod's main class
/// You need to call the {<code>register()</code>} method for the declared Config
public static void init()/ This method can be named anything: init(), register(), etc./ {
EXAMPLE_CONFIG.register();
///EXAMPLES OF GETTING VALUES
//EXPLICIT WAY (very similar to Forge configs)
SimpleExampleConfigClass.EXAMPLE_FLOAT.get();
}
}