Cycle

Cycle steps through a few fixed values, one per click, showing the current one after its label like vanilla's Graphics button. Ideal for enums.

Last updated

On this page

A button that steps through a fixed list of values, shown as "label: value" like vanilla's option buttons (for example "Graphics: Fancy"). Each click selects the next value, wrapping around after the last. Good for a handful of values, typically an enum.

Cycle.<Mode>builder("mode")
        .label(Text.translatable("mymod.mode", "Mode"))
        .values(Arrays.asList(Mode.values()))
        .value(() -> config.mode)
        .valueText(m -> Text.translatable("mymod.mode." + m.name().toLowerCase(Locale.ROOT), m.name()))
        .onChange(m -> config.mode = m)
        .build();

Builder#

Method Required Default Notes
label(Supplier<Text>) / label(Text) yes the text before ": value"
values(List<T>) yes the values in cycling order, not empty. Copied at build time.
value(Supplier<T>) yes your current value; re-read on every refresh
valueText(Function<? super T, Text>) yes how a value is shown after "label: "
onChange(Consumer<? super T>) yes stores the newly selected value; main thread
enabled, tooltip, visible no options every widget has

build() throws if a required field is missing or values is empty.

Behaviour#

Test it#

host.click("mode");                    // selects the next value

Rendered as [cycle mode] Mode: Balanced.

See also#