9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-30 04:29:05 +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:
StrangeOne101
2021-06-29 00:24:36 +12:00
parent 4a11ed6dc4
commit 7d59edc8a5
11 changed files with 261 additions and 15 deletions

View File

@@ -302,6 +302,17 @@ public interface Engine extends DataProvider, Fallible, GeneratorAccess, LootPro
int rx = b.getX();
int rz = b.getZ();
double he = getFramework().getComplex().getHeightStream().get(rx, rz);
PlacedObject po = getFramework().getEngine().getObjectPlacement(rx, b.getY(), rz);
if (po != null && po.getPlacement() != null) {
if(B.isStorageChest(b.getBlockData()))
{
IrisLootTable table = po.getPlacement().getTable(b.getBlockData(), getData());
if (table != null) {
return new KList<>(table);
}
}
}
IrisRegion region = getFramework().getComplex().getRegionStream().get(rx, rz);
IrisBiome biomeSurface = getFramework().getComplex().getTrueBiomeStream().get(rx, rz);
IrisBiome biomeUnder = b.getY() < he ? getFramework().getComplex().getCaveBiomeStream().get(rx, rz) : biomeSurface;

View File

@@ -1,17 +1,25 @@
package com.volmit.iris.scaffold.jigsaw;
import com.volmit.iris.Iris;
import com.volmit.iris.generator.IrisEngine;
import com.volmit.iris.manager.IrisDataManager;
import com.volmit.iris.object.*;
import com.volmit.iris.object.tile.TileData;
import com.volmit.iris.scaffold.IrisWorlds;
import com.volmit.iris.scaffold.engine.Engine;
import com.volmit.iris.scaffold.engine.IrisAccess;
import com.volmit.iris.util.AxisAlignedBB;
import com.volmit.iris.util.IObjectPlacer;
import com.volmit.iris.util.KList;
import com.volmit.iris.util.RNG;
import lombok.Data;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.util.BlockVector;
@Data
@@ -129,8 +137,17 @@ public class PlannedPiece {
}
public void place(World world) {
IrisAccess a = IrisWorlds.access(world);
int minY = 0;
if (a != null) {
minY = a.getCompound().getDefaultEngine().getMinHeight();
if (!a.getCompound().getRootDimension().isBedrock()) minY--; //If the dimension has no bedrock, allow it to go a block lower
}
getPiece().getPlacementOptions().getRotation().setEnabled(false);
int finalMinY = minY;
getObject().place(position.getX()+getObject().getCenter().getBlockX(), position.getY()+getObject().getCenter().getBlockY(), position.getZ()+getObject().getCenter().getBlockZ(), new IObjectPlacer() {
@Override
public int getHighest(int x, int z) {
@@ -144,7 +161,22 @@ public class PlannedPiece {
@Override
public void set(int x, int y, int z, BlockData d) {
world.getBlockAt(x,y,z).setBlockData(d);
Block block = world.getBlockAt(x, y, z);
//Prevent blocks being set in or bellow bedrock
if (y <= finalMinY || block.getType() == Material.BEDROCK) return;
block.setBlockData(d);
if (a != null && getPiece().getPlacementOptions().getLoot().isNotEmpty() &&
block.getState() instanceof InventoryHolder) {
IrisLootTable table = getPiece().getPlacementOptions().getTable(block.getBlockData(), getData());
if (table == null) return;
Engine engine = a.getCompound().getEngineForHeight(y);
engine.addItems(false, ((InventoryHolder) block.getState()).getInventory(), getStructure().getRng(),
new KList<>(table), InventorySlotType.STORAGE, x, y, z, 15);
}
}
@Override
@@ -183,6 +215,6 @@ public class PlannedPiece {
tile.toBukkitTry(state);
state.update();
}
}, piece.getPlacementOptions(), new RNG(), getData());
}, piece.getPlacementOptions(), getStructure().getRng(), getData());
}
}

View File

@@ -162,14 +162,15 @@ public class PlannedStructure {
{
if(j.getSpawnEntity() != null)
{
IrisAccess a = IrisWorlds.access(world);
if (a == null) {
Iris.warn("Cannot spawn entities from jigsaw in non Iris world!");
break;
}
IrisPosition p = i.getWorldPosition(j).add(new IrisPosition(j.getDirection().toVector().multiply(2)));
IrisEntity e = getData().getEntityLoader().load(j.getSpawnEntity());
IrisAccess a = IrisWorlds.access(world);
if(a != null)
{
e.spawn(a.getCompound().getEngineForHeight(p.getY()), new Location(world, p.getX(), p.getY(), p.getZ()), rng);
}
e.spawn(a.getCompound().getEngineForHeight(p.getY()), new Location(world, p.getX() + 0.5, p.getY(), p.getZ() + 0.5), rng);
}
}
});