Wiki 9Minecraft Cloth Config API Wiki

Cloth Config API — Guide

Version Support

Cloth Config has evolved through multiple major versions to support different Minecraft releases. For Minecraft, the mod typically utilizes version 11 (Stable).

Version Minecraft Support Status
v1 - v3 1.14.x - 1.16 (Early) Discontinued
v4 1.16.x (Stable) Active
v5 1.17.x Discontinued
v6 1.18.x Active
v8 1.19 - 1.19.2 Active
v9 1.19.3 Active
v10 1.19.4 Active
v11 1.20.x Active

Developer Setup

To use Cloth Config API in a development environment, developers must add the appropriate repositories and dependencies to their build.gradle file.

Fabric Setup

repositories {
 maven { url " }
 maven { url " }
}

dependencies {
 modApi("me.shedaniel.cloth:cloth-config-fabric:VERSION") {
 exclude(group: "net.fabricmc.fabric-api")
 }
}

Forge Setup

repositories {
 maven { url " }
}

dependencies {
 api(fg.deobf("me.shedaniel.cloth:cloth-config-forge:VERSION"))
}

Annotations Reference

Annotations allow developers to customize how fields are rendered in the Auto Config GUI.

Annotation Target Description
@Config Class Defines the config file name (required).
@Config.Gui.Background Class Sets a custom background texture for the config screen.
@ConfigEntry.BoundedDiscrete Field Renders an int or long as a slider with a min/max range.
@ConfigEntry.Gui.Excluded Field Hides the field from the GUI entirely.
@ConfigEntry.Gui.Tooltip Field Adds a hoverable tooltip (defined in lang files).
@ConfigEntry.Gui.CollapsibleObject Field Places nested object fields inside a collapsible sub-menu.
@ConfigEntry.Gui.TransitiveObject Field Flattens nested object fields into the current category level.
@ConfigEntry.Gui.PrefixText Field Injects a static text label above the entry.
@Comment Field (Jankson only) Adds a direct comment to the config file and a tooltip in-game.

GUI Entry Types

Cloth Config supports a wide variety of interactive elements to handle different data types:

  • Boolean Toggle: A simple button that cycles between True and False.
  • String Field: A text input box for strings.
  • Numeric Fields: Specialized inputs for int, long, float, and double with optional validation.
  • Sliders: Used for bounded numbers, allowing users to drag a handle to select a value.
  • Enum Selector: A button that cycles through all available values of a Java Enum.
  • Color Picker: A visual interface for selecting RGB or ARGB colors, including a preview box.
  • Keybinding: Allows players to click and press a key to assign a shortcut.
  • Lists: Dynamic lists where users can add, remove, or reorder multiple entries of a specific type (e.g., a list of player names or coordinates).
  • Dropdown Menus: A searchable selection menu for large sets of options.

Serialization & Storage

Cloth Config handles the complex task of saving and loading data from the disk. It supports three primary formats:

  1. Jankson (JSON5): The default and most flexible format. It supports comments and is more forgiving with syntax than standard JSON.
  2. GSON (JSON): Standard JSON format, highly compatible but does not support comments.
  3. TOML: A popular configuration format used by Forge, known for its readability.

Partitioning

For large mods, the PartitioningSerializer allows developers to split a single config class into multiple physical files on the disk, organized within a sub-directory. This is useful for modular mods where different features have distinct configuration needs.

ModMenu Integration

On the Fabric platform, Cloth Config is designed to work seamlessly with ModMenu. By implementing the ModMenuApi entry point, developers can ensure that their Cloth Config screen opens when a player clicks the "Configure" button in the ModMenu list.

public class ModMenuIntegration implements ModMenuApi {
 @Override
 public ConfigScreenFactory<?> getModConfigScreenFactory {
 return parent -> AutoConfig.getConfigScreen(ModConfig.class, parent).get;
 }
}

Mechanics & Advanced Customization

Post-Validation

Developers can implement validatePostLoad within their config class. This method runs immediately after the config is loaded from the disk, allowing the mod to "fix" invalid values (e.g., clamping a number that is out of range) before the game uses them.

Custom GUI Handlers

For highly specialized needs, developers can register GuiProvider and GuiTransformer objects. * GuiProvider: Maps a specific field type or annotation to a custom GUI component. * GuiTransformer: Modifies an existing GUI component after it has been generated, such as changing its color or adding extra logic.