mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-06 15:56:27 +00:00
Added Object & Jigsaw Loot Tables
- Added the ability for placed objects and jigsaws to have select loot tables
- Includes the ability to filter loot tables based on block type/block state
- Overrides loot tables from the biome/region, but if no loot tables are provided for an object, they will still be used
- Uses weight based system for determining which table to pick (so it's guaranteed rather than by chance)
- Added WeightedRandom util class
- Fixed loot tables not being random based on the seed
- Fixed jigsaws breaking bedrock
- Fixed enchantments in loot tables not working for enchanted books
- Fixed mobs spawned in Jigsaws not being spawned in the center like they should be
This commit is contained in:
41
src/main/java/com/volmit/iris/util/WeightedRandom.java
Normal file
41
src/main/java/com/volmit/iris/util/WeightedRandom.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class WeightedRandom<T> {
|
||||
|
||||
private KList<KeyPair<T, Integer>> weightedObjects = new KList<>();
|
||||
private Random random;
|
||||
private int totalWeight = 0;
|
||||
|
||||
public WeightedRandom(Random random) {
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
public WeightedRandom() {
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
public void put(T object, int weight) {
|
||||
weightedObjects.add(new KeyPair<>(object, weight));
|
||||
totalWeight += weight;
|
||||
}
|
||||
|
||||
public T pullRandom() {
|
||||
int pull = random.nextInt(totalWeight);
|
||||
int index = 0;
|
||||
while (pull > 0) {
|
||||
pull -= weightedObjects.get(index).getV();
|
||||
index++;
|
||||
}
|
||||
return weightedObjects.get(index).getK();
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return weightedObjects.size();
|
||||
}
|
||||
|
||||
public void shuffle() {
|
||||
weightedObjects.shuffle(random);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user