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.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAn entry in the list.static interfaceAn interface for a weighted value. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intThe total weight of all entries in the list.protected final List<WeightedRandomList.Entry<T>> The list's entries. -
Constructor Summary
ConstructorsConstructorDescriptionWeightedRandomList(List<T> entries) Create a weighted random list using the given values. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an entry to the list.Get the list's entries.pick(net.minecraft.util.RandomSource random) Pick a random value from the list.
-
Field Details
-
entries
The list's entries. -
accumulatedWeight
protected int accumulatedWeightThe total weight of all entries in the list.
-
-
Constructor Details
-
WeightedRandomList
Create a weighted random list using the given values.- Parameters:
entries- The values.
-
-
Method Details
-
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
Pick a random value from the list.- Parameters:
random- A random source to use.- Returns:
- The value.
-
addEntry
Add an entry to the list.- Parameters:
it- The entry.
-