From dfd5a7c21d180aa27f5bbb98269087a7cf00b287 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Mon, 13 Sep 2021 18:40:22 -0400 Subject: [PATCH] Locate objects --- .../components/MantleObjectComponent.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java index 293dac782..2e75773c1 100644 --- a/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java +++ b/src/main/java/com/volmit/iris/engine/mantle/components/MantleObjectComponent.java @@ -27,11 +27,14 @@ import com.volmit.iris.engine.object.IrisBiome; import com.volmit.iris.engine.object.IrisObject; import com.volmit.iris.engine.object.IrisObjectPlacement; import com.volmit.iris.engine.object.IrisRegion; +import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.documentation.BlockCoordinates; import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.mantle.MantleFlag; import com.volmit.iris.util.math.RNG; +import java.util.Set; + public class MantleObjectComponent extends IrisMantleComponent { public MantleObjectComponent(EngineMantle engineMantle) { super(engineMantle, MantleFlag.OBJECT); @@ -49,10 +52,13 @@ public class MantleObjectComponent extends IrisMantleComponent { @ChunkCoordinates private void placeObjects(MantleWriter writer, RNG rng, int x, int z, IrisBiome biome, IrisRegion region) { + long s = Cache.key(x, z) + seed(); + RNG rnp = new RNG(s); for (IrisObjectPlacement i : biome.getSurfaceObjects()) { if (rng.chance(i.getChance() + rng.d(-0.005, 0.005))) { try { - placeObject(writer, rng, x << 4, z << 4, i); + placeObject(writer, rnp, x << 4, z << 4, i); + rnp.setSeed(s); } catch (Throwable e) { Iris.reportError(e); Iris.error("Failed to place objects in the following biome: " + biome.getName()); @@ -66,7 +72,8 @@ public class MantleObjectComponent extends IrisMantleComponent { for (IrisObjectPlacement i : region.getSurfaceObjects()) { if (rng.chance(i.getChance() + rng.d(-0.005, 0.005))) { try { - placeObject(writer, rng, x << 4, z << 4, i); + placeObject(writer, rnp, x << 4, z << 4, i); + rnp.setSeed(s); } catch (Throwable e) { Iris.reportError(e); Iris.error("Failed to place objects in the following region: " + region.getName()); @@ -93,4 +100,43 @@ public class MantleObjectComponent extends IrisMantleComponent { v.getLoadKey() + "@" + id), null, getData()); } } + + @BlockCoordinates + private Set guessPlacedKeys(RNG rng, int x, int z, IrisObjectPlacement objectPlacement) { + Set f = new KSet<>(); + for (int i = 0; i < objectPlacement.getDensity(); i++) { + IrisObject v = objectPlacement.getScale().get(rng, objectPlacement.getObject(getComplex(), rng)); + if (v == null) { + continue; + } + + f.add(v.getLoadKey()); + } + + return f; + } + + public Set guess(int x, int z) { + RNG rng = new RNG(Cache.key(x, z) + seed()); + long s = Cache.key(x, z) + seed(); + RNG rngd = new RNG(s); + IrisBiome biome = getEngineMantle().getEngine().getSurfaceBiome((x << 4) + 8, (z << 4) + 8); + IrisRegion region = getEngineMantle().getEngine().getRegion((x << 4) + 8, (z << 4) + 8); + Set v = new KSet<>(); + for (IrisObjectPlacement i : biome.getSurfaceObjects()) { + if (rng.chance(i.getChance() + rng.d(-0.005, 0.005))) { + v.addAll(guessPlacedKeys(rngd, x, z, i)); + rngd.setSeed(s); + } + } + + for (IrisObjectPlacement i : region.getSurfaceObjects()) { + if (rng.chance(i.getChance() + rng.d(-0.005, 0.005))) { + v.addAll(guessPlacedKeys(rngd, x, z, i)); + rngd.setSeed(s); + } + } + + return v; + } }