Class WeightedRandomSelector<T>

java.lang.Object
com.pixelmonmod.pixelmon.api.selector.type.WeightedRandomSelector<T>
Type Parameters:
T - The type being selected
All Implemented Interfaces:
Selector<T>, Iterable<T>

public class WeightedRandomSelector<T> extends Object implements Selector<T>
This represents a random selector implementation of Selector where each value in the list has an assigned weight that dictates how likely that value is to be selected
  • Field Details

  • Constructor Details

  • Method Details

    • getRandom

      public T getRandom()
      Description copied from interface: Selector
      Gets a random element
      Specified by:
      getRandom in interface Selector<T>
      Returns:
      A random element
    • iterator

      @NotNull public @NotNull Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • codec

      public <A> Function<com.mojang.serialization.Codec<A>,com.mojang.serialization.Codec<? extends Selector<A>>> codec()
      Description copied from interface: Selector
      Gets the codec for this selector
      Specified by:
      codec in interface Selector<T>
      Type Parameters:
      A - The type of the codec and selector
      Returns:
      The codec
    • codec

      public static <A> com.mojang.serialization.Codec<WeightedRandomSelector<A>> codec(com.mojang.serialization.Codec<A> codec)
      Factory for creating an instanced version of this class
      Type Parameters:
      A - The type
      Parameters:
      codec - The type's codec
      Returns:
      The codec for the instanced selector
    • builder

      public static <T> WeightedRandomSelector.Builder<T> builder(T value, double weight)
      Creates a new builder instance
      Type Parameters:
      T - The type
      Parameters:
      value - One of the values
      weight - The weight of the value
      Returns:
      The builder