SuperMartijn642's Config Lib - Simplified Configuration Management
This library provides mod developers with an intuitive way to create configuration files. You define parameters only once, and the system automatically handles updating them when switching worlds, synchronization between client and server, and generating separate values for client or server components.
Creating Configuration
Work begins by creating a ModConfigBuilder object through the constructor:
ModConfigBuilder builder = new ModConfigBuilder();
Adding parameters is done using the define() method, which takes a name and default value. For numeric types, minimum and maximum values must be specified. The method returns a Supplier for retrieving the current parameter value.
Supplier<Boolean> booleanValue = builder.define("booleanValue", true);
Supplier<Integer> integerValue = builder.define("integerValue", 5, 0, 10);
Supplier<Double> doubleValue = builder.define("doubleValue", 0.5, 0, 1);
Supplier<ExampleEnum> enumValue = builder.define("enumValue", ExampleEnum.VALUE_1);
Additional Features
You can add explanations to parameters using comment():
Supplier<Boolean> valueWithComment = builder.comment("this is a comment for 'valueWithComment'").define("valueWithComment ", true);
By default, values update when loading worlds. To change this behavior to reload only when starting Minecraft, use gameRestart():
Supplier<Boolean> notReloadedValue = builder.comment("this value will not be reloaded").define("notReloadedValue", true);
To disable parameter synchronization between client and server, use dontSync():
Supplier<Boolean> notSynchronizedValue = builder.comment("this value will not be synchronized").define("notSynchronizedValue", true);
Organization into Categories
Parameters can be grouped into categories using push() and pop():
builder.push("special");
Supplier<Boolean> specialValue = builder.comment("this parameter is in the 'special' category").define("specialValue", true);
builder.pop();
You can also add comments to categories using categoryComment():
builder.push("client").categoryComment("this is a comment for the 'client' category");
After defining all parameters, you must complete configuration creation by calling build():
builder.build();
Now your parameters will automatically update and synchronize. You can retrieve their values through the saved Supplier instances. The library is compatible with Minecraft versions 1.12, 1.14, 1.15, 1.16, 1.17, 1.18, and 1.19.
Usage Example
For a clear example of working with the library, check out the demonstration mod.