Controllers
In-depth review of Controllers.
This is an incomplete list of controllers!
There are many different built-in controllers to get you set up quickly.
A toggleable controller that displays a different
Text
based on the state of the option..controller(BooleanControllerBuilder::create)
valueFormatter
parameter is a function to returnText
based on the state of the option. (optional)coloured
parameter 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))


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 -> <Number>SliderController.create(opt)
.range(0, 10)
.step(1)
.valueFormatter(val -> Component.literal(val + " ticks"))) // sliders can also take a formatter








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

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.

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(...))
Last modified 1mo ago