From c48c74a0cf023c4c542901f9041695cee2f27646 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Wed, 21 Jul 2021 11:10:43 +0200 Subject: [PATCH] Remove saplings, update debug, improve object placing functions --- .../java/com/volmit/iris/core/TreeManager.java | 16 +++++++++------- .../volmit/iris/engine/object/IrisObject.java | 4 ++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/TreeManager.java b/src/main/java/com/volmit/iris/core/TreeManager.java index 11dcb6fd9..49a310231 100644 --- a/src/main/java/com/volmit/iris/core/TreeManager.java +++ b/src/main/java/com/volmit/iris/core/TreeManager.java @@ -8,6 +8,7 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.math.RNG; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.world.StructureGrowEvent; @@ -73,21 +74,25 @@ public class TreeManager implements Listener { // Find best object placement based on sizes IrisObjectPlacement placement = null; + IrisTreeSize bestSize = null; while (placement == null && keys.isNotEmpty()){ - IrisTreeSize bestSize = IrisTreeSize.bestSizeInSizes(keys); + bestSize = IrisTreeSize.bestSizeInSizes(keys); keys.remove(bestSize); placement = getObjectPlacement(worldAccess, event.getLocation(), type, bestSize); } // If none were found, just exit if (placement == null) { - Iris.debug(this.getClass().getName() + " had options but did not manage to find objectplacements for them"); + Iris.debug(this.getClass().getName() + " had options but did not manage to find objectPlacements for them"); return; } // Cancel the placement event.setCancelled(true); + // Delete existing saplings + sizes.get(bestSize).forEach(row -> row.forEach(location -> location.getBlock().setType(Material.AIR))); + // Get object from placer IrisObject f = worldAccess.getData().getObjectLoader().load(placement.getPlace().getRandom(RNG.r)); @@ -153,17 +158,14 @@ public class TreeManager implements Listener { // Place the object with the placer /* f.place( - event.getLocation().getBlockX(), - event.getLocation().getBlockY(), - event.getLocation().getBlockZ(), + event.getLocation() // TODO: Place the object at the right location (one of the center positions) placer, placement, RNG.r, Objects.requireNonNull(IrisWorlds.access(event.getWorld())).getData() ); */ - // TODO: Place the object at the right location (one of the center positions) - f.place(event.getLocation()); + //f.place(event.getLocation()); } /** diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index 9832af511..846546e58 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -415,6 +415,10 @@ public class IrisObject extends IrisRegistrant { return place(x, yv, z, placer, config, rng, null, null, rdata); } + public int place(Location loc, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisDataManager rdata) { + return place(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), placer, config, rng, rdata); + } + public int place(int x, int yv, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, Consumer listener, CarveResult c, IrisDataManager rdata) { IObjectPlacer placer = (config.getHeightmap() != null) ? new IObjectPlacer() { final long s = rng.nextLong() + yv + z - x;