Controllers
In-depth review of Controllers.
Built-in controllers
This is an incomplete list of controllers!
There are many different built-in controllers to get you set up quickly.
BooleanController
A toggleable controller that displays a different Text based on the state of the option.
.controller(BooleanControllerBuilder::create)- valueFormatterparameter is a function to return- Textbased on the state of the option. (optional)
- colouredparameter is a boolean that colours the returned text red or green based on the state. (optional)
To pass extra parameters, you need to construct a BooleanController like so.
.controller(opt -> BooleanControllerBuilder.create(opt)
        .valueFormatter(val -> val ? Component.literal("Amazing") : Component.literal("Not Amazing"))
        .coloured(true))

TickBoxController
A toggleable controller that displays a tick box.
.controller(TickBoxControllerBuilder::create)There are no optional parameters for this controller.

<Number>SliderController
Replace <Number> with either Double, Float, Integer and Long.
Slider controllers take a minimum, a maximum and a step for the slider in their respected number types.
.controller(opt -> FloatSliderController.create(opt)
        .range(0, 10)
        .step(1)
        .valueFormatter(val -> Component.literal(val + " ticks"))) // sliders can also take a formatter







EnumController
A controller that allows you to cycle through Enum constants.
.controller(opt -> EnumControllerBuilder.create(opt)
        .enumClass(Alphabet.class))Enums can implement the NameableEnum interface to automatically name each constant without a value formatter function.
public enum Alphabet implements NameableEnum {
    A,
    B,
    C;
    
    @Override
    public Component getDisplayName() {
        return Component.translatable("mymod.alphabet." + name().toLowerCase());
    }
}Or alternatively, just pass a valueFormatter to the controller as usual;
.controller(opt -> EnumControllerBuilder.create(opt)
        .enumClass(Alphabet.class)
        .valueFormatter(v -> Component.translatable("mymod.alphabet." + v.name().toLowerCase())))
StringController
An input box that allows users to input text as a String. This allows for highlighting text with the keyboard and strings that are longer than the option itself, similarly to Minecraft's EditBox
.controller(StringControllerBuilder::create)This controller has no arguments, though its functionality can be extended by creating your own controller, implementing IStringController, more on this here.

ColorController
A controller that allows users to input colors as RGB hex format, with a preview.
.controller(ColorControllerBuilder::create)- allowAlphaparameter adds an alpha channel to the hex format as RGBA.
.controller(opt -> ColorControllerBuilder.create(opt)
        .alpha(true))
<Number>FieldController
Replace <Number> with either Double, Float, Long or Integer.
Similar to StringController,  but forces a number format, doubles and floats allow decimals, but longs and integers do not.
.controller(<Number>SliderControllerBuilder::create)It also has a optional range where you can specify the upper and lower bound if necessary. And like usual has a value formatter.
.controller(opt -> <Number>SliderControllerBuilder.create(opt)
        .min(0).max(10)
        .valueFormatter(...))Creating a custom Controller
Last updated
Was this helpful?
