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:
StrangeOne101
2021-06-29 00:24:36 +12:00
parent 4a11ed6dc4
commit 7d59edc8a5
11 changed files with 261 additions and 15 deletions

View 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);
}
}