Class WeightedRandomList<T extends WeightedRandomList.IWeighted>

java.lang.Object
top.girlkisser.lazuli.api.collections.WeightedRandomList<T>
Type Parameters:
T - The type of entries in the list.

public class WeightedRandomList<T extends WeightedRandomList.IWeighted> extends Object
A list for picking random values with weights. Mojang does have a WeightedRandomList implementation, however theirs uses an immutable list. This one uses a mutable list, which makes it a little more flexible.
  • Field Details

  • Constructor Details

    • WeightedRandomList

      public WeightedRandomList(List<T> entries)
      Create a weighted random list using the given values.
      Parameters:
      entries - The values.
  • Method Details

    • getEntries

      public List<WeightedRandomList.Entry<T>> getEntries()
      Get the list's entries. **Do not remove values from this list**, if you absolutely must, make sure to change the accumulated weight of all entries after the removed entry *and* of the list.
      Returns:
      The entries.
    • pick

      @Nullable public T pick(net.minecraft.util.RandomSource random)
      Pick a random value from the list.
      Parameters:
      random - A random source to use.
      Returns:
      The value.
    • addEntry

      public void addEntry(T it)
      Add an entry to the list.
      Parameters:
      it - The entry.