From 5f4af7958fc9169733255790a503d14145e3fea0 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 6 Nov 2019 10:38:36 +0000 Subject: [PATCH] MCAFile is chunk based extent --- .../com/boydti/fawe/beta/IQueueExtent.java | 49 +--------------- .../beta/implementation/IChunkExtent.java | 56 +++++++++++++++++++ .../com/boydti/fawe/jnbt/anvil/MCAFile.java | 13 ++++- 3 files changed, 70 insertions(+), 48 deletions(-) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java index 219b37ff2..abe3b7462 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueExtent.java @@ -1,6 +1,7 @@ package com.boydti.fawe.beta; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.beta.implementation.IChunkExtent; import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock; import com.boydti.fawe.beta.implementation.processors.IBatchProcessorHolder; import com.sk89q.jnbt.CompoundTag; @@ -24,7 +25,7 @@ import java.util.concurrent.Future; * TODO: implement Extent (need to refactor Extent first) Interface for a queue based extent which * uses chunks */ -public interface IQueueExtent extends Flushable, Trimable, Extent, IBatchProcessorHolder { +public interface IQueueExtent extends Flushable, Trimable, IChunkExtent, IBatchProcessorHolder { @Override default boolean isQueueEnabled() { @@ -71,15 +72,6 @@ public interface IQueueExtent extends Flushable, Trimable, Extent, IBatchProcess */ IChunkSet getCachedSet(int x, int z); - /** - * Get the IChunk at a position (and cache it if it's not already) - * - * @param x - * @param z - * @return IChunk - */ - IChunk getOrCreateChunk(int x, int z); - /** * Submit the chunk so that it's changes are applied to the world * @@ -88,43 +80,6 @@ public interface IQueueExtent extends Flushable, Trimable, Extent, IBatchProcess */ > T submit(IChunk chunk); - // standard get / set - - @Override - default boolean setBlock(int x, int y, int z, BlockStateHolder state) { - final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); - return chunk.setBlock(x & 15, y, z & 15, state); - } - - @Override - default boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { - final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); - return chunk.setTile(x & 15, y, z & 15, tile); - } - - @Override - default boolean setBiome(int x, int y, int z, BiomeType biome) { - final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); - return chunk.setBiome(x & 15, y, z & 15, biome); - } - - @Override - default BlockState getBlock(int x, int y, int z) { - final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); - return chunk.getBlock(x & 15, y, z & 15); - } - - @Override - default BaseBlock getFullBlock(int x, int y, int z) { - final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); - return chunk.getFullBlock(x & 15, y, z & 15); - } - - default BiomeType getBiome(int x, int z) { - final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); - return chunk.getBiomeType(x & 15, z & 15); - } - @Override default BlockVector3 getMinimumPoint() { return BlockVector3.at(-30000000, 0, -30000000); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java new file mode 100644 index 000000000..22716424e --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/IChunkExtent.java @@ -0,0 +1,56 @@ +package com.boydti.fawe.beta.implementation; + +import com.boydti.fawe.beta.IChunk; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.world.biome.BiomeType; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockStateHolder; + +public interface IChunkExtent extends Extent { + /** + * Get the IChunk at a position (and cache it if it's not already) + * + * @param x + * @param z + * @return IChunk + */ + IChunk getOrCreateChunk(int chunkX, int chunkZ); + + @Override + default boolean setBlock(int x, int y, int z, BlockStateHolder state) { + final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); + return chunk.setBlock(x & 15, y, z & 15, state); + } + + @Override + default boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { + final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); + return chunk.setTile(x & 15, y, z & 15, tile); + } + + @Override + default boolean setBiome(int x, int y, int z, BiomeType biome) { + final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); + return chunk.setBiome(x & 15, y, z & 15, biome); + } + + @Override + default BlockState getBlock(int x, int y, int z) { + final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); + return chunk.getBlock(x & 15, y, z & 15); + } + + @Override + default BaseBlock getFullBlock(int x, int y, int z) { + final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); + return chunk.getFullBlock(x & 15, y, z & 15); + } + + default BiomeType getBiome(int x, int z) { + final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); + return chunk.getBiomeType(x & 15, z & 15); + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAFile.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAFile.java index ca8be79aa..b87de62b3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAFile.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAFile.java @@ -4,6 +4,7 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.Trimable; +import com.boydti.fawe.beta.implementation.IChunkExtent; import com.boydti.fawe.beta.implementation.processors.ExtentBatchProcessorHolder; import com.boydti.fawe.jnbt.streamer.StreamDelegate; import com.boydti.fawe.object.RunnableVal4; @@ -41,7 +42,7 @@ import java.util.zip.InflaterInputStream; * e.g.: `.Level.Entities.#` (Starts with a . as the root tag is unnamed) * Note: This class isn't thread safe. You can use it in an async thread, but not multiple at the same time */ -public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, Extent { +public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, IChunkExtent { private static Field fieldBuf2; private static Field fieldBuf3; @@ -255,6 +256,16 @@ public class MCAFile extends ExtentBatchProcessorHolder implements Trimable, Ext chunks[pair] = chunk; } + @Override + public MCAChunk getOrCreateChunk(int chunkX, int chunkZ) { + try { + return getChunk(chunkX, chunkZ); + } catch (IOException e) { + // TODO generate? + return null; + } + } + public MCAChunk getChunk(int cx, int cz) throws IOException { int pair = getIndex(cx, cz); MCAChunk chunk = chunks[pair];