Class Slider.Builder
- Enclosing class:
Slider
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the slider.A fixed label; seelabel(Supplier).The text before ": value", re-read on every refresh.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.range(double min, double max) The range of values, both ends inclusive.step(double step) The distance between selectable values:1for whole numbers,0.1for one decimal, and so on.value(DoubleSupplier value) Reads the mod's current value; re-read on every refresh and during drags.valueText(DoubleFunction<Text> valueText) How the value is shown after "label: ".
-
Method Details
-
label
The text before ": value", re-read on every refresh. Required.- Parameters:
label- read on refresh- Returns:
- this builder
-
label
A fixed label; seelabel(Supplier).- Parameters:
label- the label- Returns:
- this builder
-
range
The range of values, both ends inclusive. Required.- Parameters:
min- the value at the left end; finitemax- the value at the right end; finite and greater thanmin- Returns:
- this builder
-
step
The distance between selectable values:1for whole numbers,0.1for one decimal, and so on. 0 (the default) allows any value in the range. At mostmax - min. If the step doesn't divide the range, the highest value is the last step belowmax.- Parameters:
step- the step, 0 or positive- Returns:
- this builder
-
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
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"), orv -> v == 0 ? Text.translatable("mymod.off", "Off") : Text.literal(String.valueOf((int) v)).- Parameters:
valueText- maps a (snapped) value to its text; never returnsnull- Returns:
- this builder
-
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
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
-