AzureLib

Using the Config API


Creating the Config class

To create a new config class, define a class annotated with @Config. The id parameter of the annotation should match your mod's ID. Here's an example:

@Config(id = "yourmodid")
public class ModConfig {
// Configuration fields will be defined here
}

Once created, simply register your fields for the configs you wish to use. These can only public, non-final and instance fields only.

Supported datatypes include:

  • boolean, boolean[]
  • char
  • int, int[]
  • long, long[]
  • float, float[]
  • double, double[]
  • String, String[]
  • Enums
  • Object

Example:

@Config(id = MyMod.MOD_ID)
public class ModConfig {
@Configurable
public boolean myBoolean = true;
@Configurable
public int myInt = 3;
@Configurable
public int[] myIntArray = {30, 20, 10, 5};
@Configurable
public CustomEnum myEnum = CustomEnum.SOME_VALUE;
@Configurable
public NestedObject myNest = new NestedObject();
public static class NestedObject {
@Configurable
public double myDouble = 3.14159265359;
}
}

Registering the Config

NeoForge/ForgeFabric

In your mods constructor, add the following:

public static ModConfig config;
public YourMod() {
config = AzureLibMod.registerConfig(ModConfig.class,
//you can use .json or .yaml formats
ConfigFormats.json()).getConfigInstance();
}

In your mods Initializer class, add the following:

public static ModConfig config;
@Override
public void onInitialize() {
config = AzureLibMod.registerConfig(ModConfig.class,
//you can use .json or .yaml formats
ConfigFormats.json()).getConfigInstance();
}

Calling your Config class

To call, simply use above created config value where you wish to use it!

Example:

public void someMethod() {
MyMod.config.configvalue;
}