Not rated yet

Cloth Config API Mod

4081 views 93 downloadsJan 13, 2023 Jan 13, 2023

Creators and Publishers

shedaniel

Creator

mchoarder

Publisher

Share this post



Cloth Config API (also Auto Config) is a config API that allows the player to change the config of the game from Within the Game’s GUI. It is one of the most popular config APIs, and it is made by shedaniel, the author of Architectury API and Roughly Enough Items, and other big names. They have excellent documentation for Developers and are lightweight for players. There are also similar APIs, such as Cloth API, a general-purpose API for Fabric (distinct from Cloth Config/Cloth Config API) and Cloth Math, a Maths API that is not dependent on Minecraft.


There are multiple versions of Cloth Config, each of which has its API and Features. Each version of Cloth Config is linked to a specific version family of Minecraft.

Here is the Table:

  • V1 1.14.x (No Longer Developed)
  • v2 1.14.x-1.15.x (No Longer Developed)
  • v3 1.16 Snapshots before 20w17a (No Longer Developed)
  • v4 1.16.x 20w17a and newer (Supported)
  • v5 1.17.x (Supported)
  • v6 1.18.x (Supported)
  • v7 1.19 (No Longer Developed)
  • v8 1.19.x (Supported)


All stable versions of Minecraft have been supported since 1.16.


 It is important to note that Cloth API is not a fully functional config library; it is just a screen for setting the config, which shedaniel claims the others suck. Since Cloth is just a screen, it can work with existing APIs such as Forge Config API. It is also supposed to be primarily used with the client; however, some server features do exist, but it is suggested server mods do not use Cloth Config.


Cloth was initially designed with Fabric in mind because, at the time, Fabric was very lightweight and did not have much in the way of config, but it eventually got popular and was ported to Minecraft Forge.


For Players, install the mod like any other mod. Some mods may need Mod Menu to show configs where you edit the config from the Mod Menu entry.


For Developers, Cloth Config has many features such as Drop Down Menus, Integration with Mod Menu, Categories, and more.


Creating a Screen in your mod is easy and can be done with a single line of code.

```ConfigBuilder builder = ConfigBuilder.create()

.setParentScreen(parent)

.setTitle(new TranslatableText("title.examplemod.config"));

```

The Config Builder can be used to set the attributes of the Config Screen, such as the background, and is automatically localised with a translation key.


Note: a new builder is created every time the screen is opened.

```

builder.setSavingRunnable(() -> {

// Serialise the config into the config file. This will be called last after all variables are updated.

});


```

It saves the config to a file and requires custom parsing.

Entries are each different, and it is recommended you read the documentation for more details on creating entries and setup Cloth Config.


Another prominent feature of Cloth Config is Auto Config, which makes configuring your mod much easier with Annotations. Auto Config Annotations are flexible; they are put on top of Config files and have their annotations for fields, which can easily be set to whatever entry. e.g. @ConfigEntry.Gui.CollapsibleObject and can also be excluded @ConfigEntry.Gui.Excluded. The supported Field types by default are boolean, int, long, double, float, String, and enum.


Cloth Config is one of the most common Config Screens in Minecraft, so making your mod require it will not be a significant burden for most modpack devs, as many big mods, including many by Yung use it (such as Yung’s Better Dungeons).