Client-Sided API for Minecraft 1.14

Danielshe 2cf4e4b45b 1.1.2 %!s(int64=5) %!d(string=hai) anos
.github 2cf4e4b45b 1.1.2 %!s(int64=5) %!d(string=hai) anos
gradle 1150ee90e3 Should be done %!s(int64=6) %!d(string=hai) anos
src 2cf4e4b45b 1.1.2 %!s(int64=5) %!d(string=hai) anos
.gitignore 1150ee90e3 Should be done %!s(int64=6) %!d(string=hai) anos
.travis.yml 1150ee90e3 Should be done %!s(int64=6) %!d(string=hai) anos
LICENSE 1150ee90e3 Should be done %!s(int64=6) %!d(string=hai) anos
README.md 7609ffb34f Finally setup %!s(int64=6) %!d(string=hai) anos
build.gradle 2cf4e4b45b 1.1.2 %!s(int64=5) %!d(string=hai) anos
gradle.properties 2cf4e4b45b 1.1.2 %!s(int64=5) %!d(string=hai) anos
gradlew 1150ee90e3 Should be done %!s(int64=6) %!d(string=hai) anos
gradlew.bat 1150ee90e3 Should be done %!s(int64=6) %!d(string=hai) anos
settings.gradle 1150ee90e3 Should be done %!s(int64=6) %!d(string=hai) anos

README.md

Cloth Config Download

Maven

repositories {
    jcenter()
}
dependencies {
    'me.shedaniel.cloth:config-2:LATEST'
}

APIs

Config Screen v1 API

Start by using ConfigScreenBuilder.create, inside it you can do addCategory to get the category instance. Do addOption with the category instance to add an option.

ConfigScreenBuilder builder = ConfigScreenBuilder.create(parentScreen, screenTitleKey, saveConsumer);
builder.addCategory("text.category.key").addOption(option);

There are multiple builtin option types:

  • Boolean -> BooleanListEntry
  • String -> StringListEntry
  • Integer -> IntegerListEntry (Text Field), IntegerSliderEntry (Slider)
  • Long -> LongListEntry (Text Field), LongSliderEntry (Slider)
  • Float -> FloatListEntry
  • Double -> DoubleListEntry
  • Enum -> EnumListEntry (Override enumNameProvider for custom names, or make the enum implement Translatable, or override toString() in the enum for names)
  • Text for Description -> TextListEntry

And you can always build your own entry. Example of a boolean entry:

builder.addCategory("text.category.key").addOption(new BooleanListEntry(fieldKey, value, save));

fieldKey will be translated automatically using I18n, value is the true or false, for save, it will only be called when you press save.

Infect, you should do something like this:

AtomicBoolean configBool = new AtomicBoolean(false);
builder.addCategory("text.category.key").addOption(new BooleanListEntry("text.value.key", configBool, bool -> configBool.set(bool)));
builder.setOnSave(savedConfig -> {
    // Save your config data file here
});

Lastly, you can open the screen like this:

MinecraftClient.getInstance().openScreen(builder.build());

Config Screen v2 API

Start by using ConfigBuilder.create, inside it you can do getOrCreateCategory to get the category instance. Do addEntry with the category instance to add an option.

ConfigBuilder builder = ConfigBuilder.create().setParentScreen(parentScreen).setTitle(screenTitleKey).set(setSavingRunnable);
builder.getOrCreateCategory("text.category.key").addEntry(option);

To start adding fields, do ConfigEntryBuilder.create() to get the entry builder instance. Example to add a boolean field:

ConfigEntryBuilder entryBuilder = ConfigEntryBuilder.create();
category.addEntry(entryBuilder.startBooleanToggle("path.to.your.key", false).build());

All builtin entry builders can be found in ConfigEntryBuilder.

Lastly, you can open the screen like this:

MinecraftClient.getInstance().openScreen(builder.build());