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(BooleanController::new)
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 -> new BooleanController(opt, valueFormatter, coloured))


Replace
<Number>
with either Double
, Float
, Integer
and Long
.Slider controllers take a minimum, a maximum and an interval for the slider in their respected number types.
.controller(opt -> new <Number>SliderController(opt, min, max, interval))
Sliders can also take a
valueFormatter
to return a Text
based on the slider value..controller(opt -> new <Number>SliderController(opt, min, max, interval, valueFormatter))








A controller that allows you to cycle through Enum constants.
.controller(EnumController::new)
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 -> new EnumController(opt, 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(StringController::new)
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.min
andmax
parameters specify how small and big the number is allowed to be. This is applied when the user unfocuses from the field or clicks apply changes.valueFormatter
parameter is a function to convert the current value into aComponent
to be displayed when the user is not focused on the option.
.controller(<Number>SliderController::new)
Last modified 1mo ago