Class Slider.Builder

Enclosing class:
Slider

public static final class Slider.Builder extends Entry.Builder<Slider.Builder>
Builds a Slider; from Slider.builder(String). Also has the options every entry has (Entry.Builder).
  • Method Details

    • label

      public Slider.Builder label(Supplier<Text> label)
      The text before ": value", re-read on every refresh. Required.
      Parameters:
      label - read on refresh
      Returns:
      this builder
    • label

      public Slider.Builder label(Text label)
      A fixed label; see label(Supplier).
      Parameters:
      label - the label
      Returns:
      this builder
    • range

      public Slider.Builder range(double min, double max)
      The range of values, both ends inclusive. Required.
      Parameters:
      min - the value at the left end; finite
      max - the value at the right end; finite and greater than min
      Returns:
      this builder
    • step

      public Slider.Builder step(double step)
      The distance between selectable values: 1 for whole numbers, 0.1 for one decimal, and so on. 0 (the default) allows any value in the range. At most max - min. If the step doesn't divide the range, the highest value is the last step below max.
      Parameters:
      step - the step, 0 or positive
      Returns:
      this builder
    • value

      public Slider.Builder value(DoubleSupplier value)
      Reads the mod's current value; re-read on every refresh and during drags. Required.
      Parameters:
      value - reads the value
      Returns:
      this builder
    • valueText

      public Slider.Builder valueText(DoubleFunction<Text> valueText)
      How the value is shown after "label: ". By default the number with as many decimals as the step has (none for whole steps, two without a step), e.g. "12" or "0.25". Use it for units or names: v -> Text.literal((int) v + " chunks"), or v -> v == 0 ? Text.translatable("mymod.off", "Off") : Text.literal(String.valueOf((int) v)).
      Parameters:
      valueText - maps a (snapped) value to its text; never returns null
      Returns:
      this builder
    • onChange

      public Slider.Builder onChange(DoubleConsumer onChange)
      Stores a new value; called on the main thread for every distinct snapped value while the player drags, not just on release. Required. Keep it fast; save to disk later (e.g. from the screen's Done button).
      Parameters:
      onChange - receives the new value, within the range and on a step
      Returns:
      this builder
    • build

      public Slider build()
      Builds the slider.
      Returns:
      the slider
      Throws:
      IllegalStateException - if a required field is missing, the range is empty or infinite, or the step is negative or larger than the range