GithubHelp home page GithubHelp logo

clothconfig's Introduction

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

clothconfig's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.