Interface Selector<T>
- Type Parameters:
T
-
- All Superinterfaces:
Iterable<T>
- All Known Implementing Classes:
ConstantSelector
,UniformlyRandomSelector
,WeightedRandomSelector
An interface that represents a random selector for a given type.
The sub-classes of this interface are used to both store, and select random elements of the given type.
The random selection is dictated by the implementation of the class. It is also note-worthy that some implementations may not be random.
The sub-classes of this interface are used to both store, and select random elements of the given type.
The random selection is dictated by the implementation of the class. It is also note-worthy that some implementations may not be random.
-
Method Summary
Modifier and TypeMethodDescription<A> Function<com.mojang.serialization.Codec<A>,
com.mojang.serialization.Codec<? extends Selector<A>>> codec()
Gets the codec for this selectorstatic <T> Selector<T>
constant
(T element) Creates a new instance of theConstantSelector
Gets a random elementstatic <T> Selector<T>
Creates a new instance of theUniformlyRandomSelector
wit the given elementsstatic <T> Selector<T>
uniform
(T... elements) Creates a new instance of theUniformlyRandomSelector
wit the given elementsMethods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Method Details
-
getRandom
T getRandom()Gets a random element- Returns:
- A random element
-
codec
<A> Function<com.mojang.serialization.Codec<A>,com.mojang.serialization.Codec<? extends Selector<A>>> codec()Gets the codec for this selector- Type Parameters:
A
- The type of the codec and selector- Returns:
- The codec
-
uniform
Creates a new instance of theUniformlyRandomSelector
wit the given elements- Type Parameters:
T
- The type- Parameters:
elements
- The elements- Returns:
- The new instance
-
uniform
Creates a new instance of theUniformlyRandomSelector
wit the given elements- Type Parameters:
T
- The type- Parameters:
elements
- The elements- Returns:
- The new instance
-
constant
Creates a new instance of theConstantSelector
- Type Parameters:
T
- The type- Parameters:
element
- The element- Returns:
- The new instance
-