Serialize everything! Night Auto Config is a Night Config integration for Auto Config (now embedded in Cloth Config).
Night Auto Config introduces a NightConfigSerializer
to satisfy Auto Config's requirement of a serializer's implementation. You can choose from all the available config formats of Night Config, and use the serializer just as other common serializers, even along with a PartitioningSerializer
.
It is recommended to use JitPack to implement Night Auto Config into your project.
Groovy
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
modApi "com.github.KessokuTeaTime:Night-Auto-Config:${project.nightautoconfig_version}"
// You'll need to implement Cloth Config API here.
}
nightautoconfig_version={latest}
Kotlin DSL
repositories {
maven { url = uri("https://jitpack.io") }
}
dependencies {
modApi("com.github.KessokuTeaTime:Night-Auto-Config:${project.nightautoconfig_version}")
// You'll need to implement Cloth Config API here.
}
nightautoconfig_version={latest}
Note
You should replace {latest}
with the latest tag name
of Night Auto Config.
Don't forget to reference Night Auto Config as dependency in your mod's metadata.
{
"depends": {
"nightautoconfig": "*"
}
}
The serializer implementation is at band.kessokuteatime.nightautoconfig.config.NightConfigSerializer
.
Here's a brief example:
MyConfig.java
// Use annotations provided by Night Auto Config to define serializer providers and deserializer providers at runtime!
@SerializerProvider(MyClassSerializerProvider.class)
@Config(name = "my_config")
public class MyConfig implements ConfigData {
// Something...
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 some interfaces for convenience implementations
// For example, `UnifiedSerializerProvider<T, R>` satisfies 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();
}
MyMod.java
public class MyMod implements ModInitializer {
@Override
public void onInitialize() {
// Don't remember to register into Auto Config at initialize
AutoConfig.register(NightExampleConfig.class, ConfigType.DEFAULT_COMMENTED::fileWatcherSerializer);
}
}
For runtime examples, checkout this package.
Important
Please annotate your fields with com.electronwill.nightconfig.core.serde.annotations.SerdeDefault
for basic compatibilities! Otherwise, serialization exceptions may happen casually.
This repository is licensed under the GNU General Public License v3.