Creating a Config Option

You can create options easily with the help of ConfigEntryBuilder, firstly create a new ConfigEntryBuilder:

[...]
ConfigEntryBuilder entryBuilder = builder.entryBuilder();

There is a lot of default provided option types that you can choose from, here is an example of adding a new String text field.

[...]
general.addEntry(entryBuilder.startStrField(new TranslatableText("option.examplemod.optionA"), currentValue)
        .setDefaultValue("This is the default value") // Recommended: Used when user click "Reset"
        .setTooltip(new TranslatableText("This option is awesome!")) // Optional: Shown when the user hover over this option
        .setSaveConsumer(newValue -> currentValue = newValue) // Recommended: Called when user save the config
        .build()); // Builds the option entry for cloth config

currentValue should be the field holding the value of the option, and the save consumer will save it back when the config is saved.

Last updated