diff --git a/core/src/main/java/com/volmit/iris/core/commands/CommandJigsaw.java b/core/src/main/java/com/volmit/iris/core/commands/CommandJigsaw.java index 922041241..a59aa2a69 100644 --- a/core/src/main/java/com/volmit/iris/core/commands/CommandJigsaw.java +++ b/core/src/main/java/com/volmit/iris/core/commands/CommandJigsaw.java @@ -57,7 +57,7 @@ public class CommandJigsaw implements DecreeExecutor { PrecisionStopwatch p = PrecisionStopwatch.start(); PlannedStructure ps = new PlannedStructure(structure, new IrisPosition(player().getLocation()), new RNG()); sender().sendMessage(C.GREEN + "Generated " + ps.getPieces().size() + " pieces in " + Form.duration(p.getMilliseconds(), 2)); - ps.place(world()); + ps.place(world(), failed -> sender().sendMessage(failed == 0 ? C.GREEN + "Placed the structure!" : C.RED + "Failed to place " + failed + " pieces!")); } @Decree(description = "Create a jigsaw piece") diff --git a/core/src/main/java/com/volmit/iris/engine/jigsaw/PlannedPiece.java b/core/src/main/java/com/volmit/iris/engine/jigsaw/PlannedPiece.java index e93fe5c7d..d2b0d43ea 100644 --- a/core/src/main/java/com/volmit/iris/engine/jigsaw/PlannedPiece.java +++ b/core/src/main/java/com/volmit/iris/engine/jigsaw/PlannedPiece.java @@ -165,7 +165,7 @@ public class PlannedPiece { return connected.size() >= piece.getConnectors().size() || isDead(); } - public void place(World world) { + public boolean place(World world) { PlatformChunkGenerator a = IrisToolbelt.access(world); int minY = 0; @@ -175,14 +175,16 @@ public class PlannedPiece { if (!a.getEngine().getDimension().isBedrock()) minY--; //If the dimension has no bedrock, allow it to go a block lower } + Engine engine = a != null ? a.getEngine() : IrisContext.get().getEngine(); getPiece().getPlacementOptions().setTranslate(new IrisObjectTranslate()); - getPiece().getPlacementOptions().setRotation(rotation); + getPiece().getPlacementOptions().getRotation().setEnabled(false); + getPiece().getPlacementOptions().setRotateTowardsSlope(false); int finalMinY = minY; RNG rng = getStructure().getRng().nextParallelRNG(37555); // TODO: REAL CLASSES!!!!!!! - getOgObject().place(position.getX() + getObject().getCenter().getBlockX(), position.getY() + getObject().getCenter().getBlockY(), position.getZ() + getObject().getCenter().getBlockZ(), new IObjectPlacer() { + return 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, IrisData data) { return position.getY(); @@ -207,7 +209,6 @@ public class PlannedPiece { IrisLootTable table = getPiece().getPlacementOptions().getTable(block.getBlockData(), getData()); if (table == null) return; - Engine engine = a.getEngine(); engine.addItems(false, ((InventoryHolder) block.getState()).getInventory(), rng.nextParallelRNG(BlockPosition.toLong(x, y, z)), new KList<>(table), InventorySlotType.STORAGE, x, y, z, 15); @@ -258,12 +259,8 @@ public class PlannedPiece { @Override public Engine getEngine() { - if (IrisToolbelt.isIrisWorld(world)) { - return IrisToolbelt.access(world).getEngine(); - } - - return IrisContext.get().getEngine(); + return engine; } - }, piece.getPlacementOptions(), rng, getData()); + }, piece.getPlacementOptions(), rng, getData().getEngine() == null ? engine.getData() : getData()) != -1; } } diff --git a/core/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java b/core/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java index fe727eebb..36cdcaa00 100644 --- a/core/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java +++ b/core/src/main/java/com/volmit/iris/engine/jigsaw/PlannedStructure.java @@ -34,6 +34,9 @@ import lombok.Data; import org.bukkit.Axis; import org.bukkit.World; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.IntConsumer; + @Data public class PlannedStructure { private static ConcurrentLinkedHashMap objectRotationCache @@ -138,9 +141,16 @@ public class PlannedStructure { }, null, getData()) != -1; } - public void place(World world) { + public void place(World world, IntConsumer consumer) { + AtomicInteger processed = new AtomicInteger(); + AtomicInteger failures = new AtomicInteger(); for (PlannedPiece i : pieces) { - Iris.sq(() -> i.place(world)); + Iris.sq(() -> { + if (!i.place(world)) failures.incrementAndGet(); + if (processed.incrementAndGet() == pieces.size()) { + consumer.accept(failures.get()); + } + }); } }