diff --git a/core/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java b/core/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java index f45fe8787..b2c87fe4f 100644 --- a/core/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java +++ b/core/src/main/java/com/volmit/iris/engine/mantle/EngineMantle.java @@ -172,7 +172,7 @@ public interface EngineMantle { @ChunkCoordinates default void generateMatter(int x, int z, boolean multicore, ChunkContext context) { - if (!getEngine().getDimension().isUseMantle()) { + if (!getEngine().getDimension().isUseMantle() || getMantle().hasFlag(x, z, MantleFlag.PLANNED)) { return; } @@ -191,20 +191,15 @@ public interface EngineMantle { Position2 pos = p.getB(); int xx = pos.getX(); int zz = pos.getZ(); - MantleChunk mc = getMantle().getChunk(xx, zz).use(); - try { - IrisContext.getOr(getEngine()).setChunkContext(context); - generateMantleComponent(writer, xx, zz, c, mc, context); - } finally { - mc.release(); - } + IrisContext.getOr(getEngine()).setChunkContext(context); + generateMantleComponent(writer, xx, zz, c, writer.acquireChunk(xx, zz), context); }, multicore ? burst() : null ); if (!last) continue; forEach(streamRadius(x, z, radius), - p -> getMantle().flag(p.getX(), p.getZ(), MantleFlag.PLANNED, true), + p -> writer.acquireChunk(x, z).flag(MantleFlag.PLANNED, true), multicore ? burst() : null ); } diff --git a/core/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java b/core/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java index d9f39c9c2..408704925 100644 --- a/core/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java +++ b/core/src/main/java/com/volmit/iris/engine/mantle/MantleWriter.java @@ -31,6 +31,7 @@ import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.collection.KSet; import com.volmit.iris.util.data.B; import com.volmit.iris.util.data.IrisCustomData; +import com.volmit.iris.util.documentation.ChunkCoordinates; import com.volmit.iris.util.function.Function3; import com.volmit.iris.util.mantle.Mantle; import com.volmit.iris.util.mantle.MantleChunk; @@ -149,20 +150,11 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable { return; } - if (cx >= this.x - radius && cx <= this.x + radius - && cz >= this.z - radius && cz <= this.z + radius) { - MantleChunk chunk = cachedChunks.computeIfAbsent(Cache.key(cx, cz), k -> mantle.getChunk(cx, cz).use()); + MantleChunk chunk = acquireChunk(cx, cz); + if (chunk == null) return; - if (chunk == null) { - Iris.error("Mantle Writer Accessed " + cx + "," + cz + " and came up null (and yet within bounds!)"); - return; - } - - Matter matter = chunk.getOrCreate(y >> 4); - matter.slice(matter.getClass(t)).set(x & 15, y & 15, z & 15, t); - } else { - Iris.error("Mantle Writer Accessed chunk out of bounds" + cx + "," + cz); - } + Matter matter = chunk.getOrCreate(y >> 4); + matter.slice(matter.getClass(t)).set(x & 15, y & 15, z & 15, t); } public T getData(int x, int y, int z, Class type) { @@ -173,15 +165,8 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable { return null; } - if (cx < this.x - radius || cx > this.x + radius - || cz < this.z - radius || cz > this.z + radius) { - Iris.error("Mantle Writer Accessed chunk out of bounds" + cx + "," + cz); - return null; - } - MantleChunk chunk = cachedChunks.computeIfAbsent(Cache.key(cx, cz), k -> mantle.getChunk(cx, cz).use()); - + MantleChunk chunk = acquireChunk(cx, cz); if (chunk == null) { - Iris.error("Mantle Writer Accessed " + cx + "," + cz + " and came up null (and yet within bounds!)"); return null; } @@ -190,6 +175,18 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable { .get(x & 15, y & 15, z & 15); } + @ChunkCoordinates + public MantleChunk acquireChunk(int cx, int cz) { + if (cx < this.x - radius || cx > this.x + radius + || cz < this.z - radius || cz > this.z + radius) { + Iris.error("Mantle Writer Accessed chunk out of bounds" + cx + "," + cz); + return null; + } + MantleChunk chunk = cachedChunks.computeIfAbsent(Cache.key(cx, cz), k -> mantle.getChunk(cx, cz).use()); + if (chunk == null) Iris.error("Mantle Writer Accessed " + cx + "," + cz + " and came up null (and yet within bounds!)"); + return chunk; + } + @Override public int getHighest(int x, int z, IrisData data) { return engineMantle.getHighest(x, z, data);