Interface Selector<T>

Type Parameters:
T -
All Superinterfaces:
Iterable<T>
All Known Implementing Classes:
ConstantSelector, UniformlyRandomSelector, WeightedRandomSelector

public interface Selector<T> extends Iterable<T>
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.
  • 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

      static <T> Selector<T> uniform(T... elements)
      Creates a new instance of the UniformlyRandomSelector wit the given elements
      Type Parameters:
      T - The type
      Parameters:
      elements - The elements
      Returns:
      The new instance
    • uniform

      static <T> Selector<T> uniform(Iterable<T> elements)
      Creates a new instance of the UniformlyRandomSelector wit the given elements
      Type Parameters:
      T - The type
      Parameters:
      elements - The elements
      Returns:
      The new instance
    • constant

      static <T> Selector<T> constant(T element)
      Creates a new instance of the ConstantSelector
      Type Parameters:
      T - The type
      Parameters:
      element - The element
      Returns:
      The new instance