Night Auto Config
Transform any data into configuration files! Night Auto Config is an integration of the Night Config library with the Auto Config system, which is now embedded in Cloth Config.
How It Works
This mod provides an implementation of NightConfigSerializer that meets Auto Config's requirements for serializers. You can choose any of the configuration formats supported by Night Config and use this serializer just like other standard serializers, including working together with PartitioningSerializer.
Project Installation
To add Night Auto Config to your project, it is recommended to use the JitPack service.
Groovy
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
modApi "com.github.KessokuTeaTime:Night-Auto-Config:${project.nightautoconfig_version}"
// You also need to include Cloth Config API here
}
Kotlin DSL
repositories {
maven { url = uri("https://jitpack.io") }
}
dependencies {
modApi("com.github.KessokuTeaTime:Night-Auto-Config:${project.nightautoconfig_version}")
// You also need to include Cloth Config API here
}
In the gradle.properties file, specify:
nightautoconfig_version={latest_version}
Replace {latest_version} with the current version number of Night Auto Config.
Dependency Declaration
Remember to specify Night Auto Config as a dependency in your mod's metadata.
{
"depends": {
"nightautoconfig": "*"
}
}
Usage Example
The serializer implementation is located at band.kessokuteatime.nightautoconfig.config.NightConfigSerializer.
Here's a simple configuration example:
// Use Night Auto Config annotations to define serializer and deserializer providers at runtime!
@SerializerProvider(MyClassSerializerProvider.class)
@Config(name = "my_config")
public class MyConfig implements ConfigData {
// Some fields...
private transient final Supplier<String> someStringProvider = () -> "default";
// All Night Config annotations are available
@SerdeDefault(provider = "someStringProvider")
public String someString = someStringProvider.get();
// Night Auto Config provides interfaces for convenient implementations
// For example, UnifiedSerializerProvider<T, R> implements both ValueSerializer<T, R> and ValueSerializerProvider<T, R>
public static class MyClassSerializerProvider implements UnifiedSerializerProvider<MyClass, String> {
// ...
}
// A custom serializer provider for MyClass is already specified at type definition
public MyClass someInstance = new MyClass();
}
Example mod initialization:
public class MyMod implements ModInitializer {
@Override
public void onInitialize() {
// Don't forget to register the configuration in Auto Config during initialization
AutoConfig.register(NightExampleConfig.class, ConfigType.DEFAULT_COMMENTED::fileWatcherSerializer);
}
}
For more detailed runtime examples, check the corresponding package in the repository.
To ensure basic compatibility, it is recommended to annotate fields using com.electronwill.nightconfig.core.serde.annotations.SerdeDefault. Otherwise, random serialization errors may occur.