Heads up!
The configuration API is only for versions 1.16.5 and higher.
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
Heads up!
Objects are used for config nesting/splitting into multiple categories. Just include some @Configurable fields in the nested object instance.
Object
Example:
@Config(id = MyMod.MOD_ID)public class ModConfig {@Configurablepublic boolean myBoolean = true;@Configurablepublic int myInt = 3;@Configurablepublic int[] myIntArray = {30, 20, 10, 5};@Configurablepublic CustomEnum myEnum = CustomEnum.SOME_VALUE;@Configurablepublic NestedObject myNest = new NestedObject();public static class NestedObject {@Configurablepublic double myDouble = 3.14159265359;}}
Registering the Config
NeoForge/Forge | Fabric |
---|---|
|
|
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;}