Getting started

Learn the structure of YACL to understand how it works.

This wiki is currently a work-in-progress and is incomplete!

Before we begin, it's important to note the wiki code examples will be using official Mojang mappings. You are also expected to have a basic knowledge of the Java programming language. If you don't, please learn Java first.

There is a simple structure: categories contains groups, groups contain options. You can also skip the groups and just add options to the category directly. They will always appear above any groups.

Before we start, lets go into detail about how to construct an Option, then we'll use that to make a GUI.

Option.<Boolean>createBuilder() // boolean is the type of option we'll be making
        .name(Component.literal("Boolean Option"))
        .description(OptionDescription.of(Component.literal("This text will appear as a tooltip when you hover over the option.")))
        .binding(
                true, // the default value
                () -> this.myBooleanOption, // a field to get the current value from
                newVal -> this.myBooleanOption = newVal
        )
        .controller(TickBoxControllerBuilder::create)
        .build()

An important concept in YACL options are the controllers. Each option type does not have a hardcoded way of being displayed. The logic of displaying the option in the GUI is held in the Controller. To learn more about controllers, click here.

To start making a GUI with YACL, you will need to build an instance of YetAnotherConfigLib. We will plug in our Option code from above...

YetAnotherConfigLib.createBuilder()
        .title(Component.literal("Used for narration. Could be used to render a title in the future."))
        .category(ConfigCategory.createBuilder()
                .name(Component.literal("Name of the category"))
                .tooltip(Component.literal("This text will appear as a tooltip when you hover or focus the button with Tab. There is no need to add \n to wrap as YACL will do it for you."))
                .group(OptionGroup.createBuilder()
                        .name(Component.literal("Name of the group"))
                        .description(OptionDescription.of(Component.literal("This text will appear when you hover over the name or focus on the collapse button with Tab.")))
                        .option(Option.<Boolean>createBuilder()
                                .name(Component.literal("Boolean Option"))
                                .description(OptionDescription.of(Component.literal("This text will appear as a tooltip when you hover over the option.")))
                                .binding(true, () -> this.myBooleanOption, newVal -> this.myBooleanOption = newVal)
                                .controller(TickBoxControllerBuilder::create)
                                .build())
                        .build())
                .build())
        .build()

All you have to do then is tell YACL to generate a Screen instance from it.

YetAnotherConfigLib.createBuilder()
        [...]
        .build()
        .generateScreen(parentScreen) // the screen that opens up when you close YACL

You must generate a new instance of YetAnotherConfigLib every time you want a GUI Screen. You cannot just call generateScreen() again!

It's that simple! You have made your first GUI with YACL!

Last updated