Client-Sided API for Minecraft 1.14

Danielshe c4dfdfc8e3 Update Crowdin configuration file 5 жил өмнө
.github 7ec90d2c15 Update gradle.yml 5 жил өмнө
gradle 1150ee90e3 Should be done 6 жил өмнө
src 866fa23f30 New translations en_us.json (de_de) 5 жил өмнө
.gitignore 1150ee90e3 Should be done 6 жил өмнө
.travis.yml 1150ee90e3 Should be done 6 жил өмнө
LICENSE 1150ee90e3 Should be done 6 жил өмнө
README.md efe21fadff 2.2 bug fix 5 жил өмнө
build.gradle 4bf878d75e 2.1 Dropdown Menu 5 жил өмнө
crowdin.yml c4dfdfc8e3 Update Crowdin configuration file 5 жил өмнө
gradle.properties 1cce3d9688 Bump Version 5 жил өмнө
gradlew 1150ee90e3 Should be done 6 жил өмнө
gradlew.bat 1150ee90e3 Should be done 6 жил өмнө
settings.gradle 1150ee90e3 Should be done 6 жил өмнө

README.md

Cloth Config Download

Help translate ClothConfig on Crowdin!

Maven

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

APIs

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());

Dropdown Menus

Start by doing entryBuilder.startDropdownMenu(), the SelectionTopCellElement is the search bar, and SelectionCellCreator is the cells below.

Create a SelectionTopCellElement with DropdownMenuBuilder.TopCellElementBuilder.of(), which takes three parameters:

  • value: The value of the field
  • toObjectFunction: The toObject function, turning String into T, returns null if error
  • toStringFunction: The toString function, which never returns null, affects the displayed text of your value.

You can also use the premade SelectionTopCellElement for items and blocks.

Create a SelectionCellCreator with DropdownMenuBuilder.CellCreatorBuilder.of(), which defines the cell height, the cell width, and how many cells are displayed at most.

  • toStringFunction: The toString function, which never returns null, affects the displayed text of the cell.

You can also use the premade SelectionCellCreator for items and blocks as well.

You should create your own cell creator extending the DefaultSelectionCellCreator to create custom cells.

Do .setSelections() with your builder to specify the list of suggestions.

This is what you should do if you got a config for items:

entryBuilder.startDropdownMenu("Field Key", 
    DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(configItem), // This should contain your saved item instead of an apple as shown here 
    DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()
)
    .setDefaultValue(Items.APPLE) // You should define a default value here
    .setSelections(Registry.ITEM.stream().collect(Collectors.toSet()))
    .setSaveConsumer(item -> configItem = (Item) item) // You should save it here, cast the item because Java is "smart"
    .build();