Class NumberField.Builder<N extends Number>
- Type Parameters:
N- the number type
- Enclosing class:
NumberField<N extends Number>
public static final class NumberField.Builder<N extends Number>
extends Entry.Builder<NumberField.Builder<N>>
Builds a
NumberField; from NumberField.ofInt(String) or NumberField.ofDouble(String). Also has the options
every entry has (Entry.Builder).-
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the field.The number the field starts with, usually the mod's current value.A fixed label; seelabel(Supplier).The text above the field, re-read on every refresh.maxLength(int maxLength) The most characters the field accepts; 32 by default.Receives the number after each edit that leaves the text valid, on the main thread.The allowed range, both ends inclusive; either may benullfor no bound.An extra check for numbers that already passed parsing and the range: returns an error text, ornullif the number is valid.
-
Method Details
-
label
The text above the field, 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
-
initial
The number the field starts with, usually the mod's current value. Required. Shown without trailing zeros (2.50as2.5); not checked against the range or passed toonChange.- Parameters:
initial- the starting number- Returns:
- this builder
-
range
The allowed range, both ends inclusive; either may benullfor no bound. Unbounded by default (apart from theintrange forNumberField.ofInt(String)).- Parameters:
min- the smallest allowed number, ornullmax- the largest allowed number, ornull; not less thanmin- Returns:
- this builder
-
maxLength
The most characters the field accepts; 32 by default.- Parameters:
maxLength- the limit, positive- Returns:
- this builder
-
validator
An extra check for numbers that already passed parsing and the range: returns an error text, ornullif the number is valid. E.g.n -> n % 2 == 0 ? null : Text.literal("Must be even"). Optional.- Parameters:
validator- maps an in-range number to an error, ornull- Returns:
- this builder
-
onChange
Receives the number after each edit that leaves the text valid, on the main thread. Required.- Parameters:
onChange- receives valid numbers- Returns:
- this builder
-
build
Builds the field.- Returns:
- the field
- Throws:
IllegalStateException- iflabel,initialoronChangeis missing,initial,minormaxis NaN or infinite,min > max, ormaxLengthis not positive
-