Toggle

Toggle is an on/off setting drawn as a vanilla button that reads ON or OFF after its label, like the toggles on the game's options screens.

Last updated

On this page

An on/off setting, drawn as a vanilla button reading "label: ON" or "label: OFF", like the toggles on vanilla's options screens. A click flips it.

Toggle.builder("particles")
        .label(Text.translatable("mymod.particles", "Particles"))
        .value(() -> config.particles)
        .onChange(on -> config.particles = on)
        .build();

Builder#

Method Required Default Notes
label(Supplier<Text>) / label(Text) yes the text before ": ON/OFF"
value(BooleanSupplier) yes reads your current value; re-read on every refresh
onChange(Consumer<Boolean>) yes stores the new value; main thread
enabled, tooltip, visible no options every widget has

Behaviour#

Test it#

host.click("particles");               // flips it

Rendered as [toggle particles] Particles: ON.

See also#