-
Notifications
You must be signed in to change notification settings - Fork 0
Modules Config
The Config module for Compound provides a simple way to define configuration options for your mod.
To define a configuration for your mod using the Config module all you have to do is create a class and add fields that should be configurable by users. Once you have your configuration class annotate it with @ConfigType
then annotate each field with @ConfigValue
.
To start using your configuration you just have to create a new instance using CompoundConfig.of
For example this could be my config class:
import com.tridevmc.compound.config.ConfigType;
import com.tridevmc.compound.config.ConfigValue;
import net.minecraftforge.fml.config.ModConfig;
@ConfigType(ModConfig.Type.COMMON)
public class CommonConfig {
@ConfigValue(comment = "Common Integer")
public int commonInt = 32;
@ConfigValue(comment = "Common Double")
public double commonDouble = 32.32D;
@ConfigValue(comment = "Common Boolean")
public boolean commonBoolean = false;
@ConfigValue(comment = "Common String")
public String commonString = "Thirty-Two";
}
Then to use this config I could create a static reference to an instance in my Mod like so:
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import com.tridevmc.compound.config.CompoundConfig;
@Mod("testmod")
public final class TestMod {
public static CommonConfig CFG;
public TestMod(){
TestMod.CFG = CompoundConfig.of(CommonConfig.class, ModLoadingContext.get().getActiveContainer());
}
}
That's it, now a configuration has been defined and registered. Config reloads are automatically handled and applied to your config instance.
If there's a custom data type you need to serialize and de-serialize then much like the Network Module you just need to implement IConfigObjectSerializer
and annotate it with @RegisteredConfigObjectSerializer
If you need to apply minimum and maximum values to any ints, longs or doubles then you can annotate the field with @RangedInt
, @RangedLong
or @RangedDouble
respectively.
For a full example of Compound Config in use please see Molecule