From 82f5c4ebed7396c2bfbdc2c398106dd74de3198e Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 7 Nov 2019 10:28:17 +0000 Subject: [PATCH] Fix compile --- build.gradle.kts | 9 ++ buildSrc/src/main/kotlin/CommonConfig.kt | 2 +- gradle.properties | 5 ++ .../adapter/mc1_14/BukkitGetBlocks_1_14.java | 15 +--- worldedit-core/build.gradle.kts | 2 +- .../main/java/com/boydti/fawe/FaweCache.java | 2 + .../java/com/boydti/fawe/beta/Filter.java | 2 +- .../com/boydti/fawe/beta/IBatchProcessor.java | 4 +- .../java/com/boydti/fawe/beta/IBlocks.java | 7 +- .../java/com/boydti/fawe/beta/IChunk.java | 56 +++--------- .../com/boydti/fawe/beta/IDelegateChunk.java | 48 ++++++++--- .../fawe/beta/IDelegateQueueExtent.java | 12 +-- .../com/boydti/fawe/beta/IQueueChunk.java | 41 +++++++++ .../com/boydti/fawe/beta/IQueueExtent.java | 14 +-- .../beta/implementation/IChunkExtent.java | 4 +- .../implementation/blocks/BitSetBlocks.java | 2 +- .../implementation/blocks/CharBlocks.java | 22 ++--- .../blocks/DelegateChunkSet.java | 4 +- .../blocks/FallbackChunkGet.java | 8 +- .../implementation/blocks/NullChunkGet.java | 5 -- .../implementation/chunk/ChunkHolder.java | 45 +++++++--- .../implementation/chunk/DelegateChunk.java | 8 +- .../implementation/chunk/FinalizedChunk.java | 4 +- .../beta/implementation/chunk/NullChunk.java | 41 ++++++--- .../implementation/chunk/ReferenceChunk.java | 5 +- .../beta/implementation/chunk/SoftChunk.java | 3 +- .../beta/implementation/chunk/WeakChunk.java | 3 +- .../filter/block/CharFilterBlock.java | 4 +- .../implementation/queue/QueueHandler.java | 3 +- .../queue/SingleThreadQueueExtent.java | 31 +++---- .../com/boydti/fawe/jnbt/anvil/MCAChunk.java | 86 +++++++++++++++---- .../cfi/HeightMapMCAGenerator.java | 7 +- .../fawe/object/changeset/FaweChangeSet.java | 4 +- .../plotquared/FaweSchematicHandler.java | 4 - .../platform/PlatformCommandManager.java | 1 - .../sk89q/worldedit/regions/CuboidRegion.java | 2 +- .../com/sk89q/worldedit/regions/Region.java | 2 +- 37 files changed, 316 insertions(+), 201 deletions(-) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueChunk.java diff --git a/build.gradle.kts b/build.gradle.kts index 290ac2f78..ad2600d24 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -41,6 +41,15 @@ ext { buildNumber = index.toString(); } } + +allprojects { + gradle.projectsEvaluated { + tasks.withType(JavaCompile::class) { + options.compilerArgs.addAll(arrayOf("-Xmaxerrs", "1000")) + } + } +} + //def rootVersion = "1.13" //def revision = "" //def buildNumber = "" diff --git a/buildSrc/src/main/kotlin/CommonConfig.kt b/buildSrc/src/main/kotlin/CommonConfig.kt index b342b7992..eede45e43 100644 --- a/buildSrc/src/main/kotlin/CommonConfig.kt +++ b/buildSrc/src/main/kotlin/CommonConfig.kt @@ -8,7 +8,7 @@ fun Project.applyCommonConfiguration() { repositories { mavenCentral() mavenLocal() - maven { url = uri("http://ci.athion.net/job/PlotSquared-Breaking/ws/mvn/") } + maven { url = uri("http://ci.athion.net/job/PlotSquared-we/ws/mvn/") } maven { url = uri("https://maven.sk89q.com/repo/") } maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") } maven { url = uri("http://empcraft.com/maven2") } diff --git a/gradle.properties b/gradle.properties index 5432e7cfb..35ae55661 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,3 +2,8 @@ group=com.sk89q.worldedit #version=7.1.0-SNAPSHOT org.gradle.jvmargs=-Xmx1G +#org.gradle.jvmargs=-Xmx4g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +org.gradle.daemon=true +org.gradle.configureondemand=true +org.gradle.parallel=true +org.gradle.caching=true \ No newline at end of file diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java index 34effff64..742fa5a49 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/mc1_14/BukkitGetBlocks_1_14.java @@ -21,12 +21,10 @@ import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import net.minecraft.server.v1_14_R1.BiomeBase; import net.minecraft.server.v1_14_R1.BlockPosition; import net.minecraft.server.v1_14_R1.Chunk; -import net.minecraft.server.v1_14_R1.ChunkCoordIntPair; import net.minecraft.server.v1_14_R1.ChunkSection; import net.minecraft.server.v1_14_R1.DataBits; import net.minecraft.server.v1_14_R1.DataPalette; @@ -36,11 +34,8 @@ import net.minecraft.server.v1_14_R1.DataPaletteLinear; import net.minecraft.server.v1_14_R1.Entity; import net.minecraft.server.v1_14_R1.EntityTypes; import net.minecraft.server.v1_14_R1.IBlockData; -import net.minecraft.server.v1_14_R1.LightEngineThreaded; import net.minecraft.server.v1_14_R1.NBTTagCompound; import net.minecraft.server.v1_14_R1.NBTTagInt; -import net.minecraft.server.v1_14_R1.SectionPosition; -import net.minecraft.server.v1_14_R1.SystemUtils; import net.minecraft.server.v1_14_R1.TileEntity; import net.minecraft.server.v1_14_R1.WorldServer; import org.bukkit.World; @@ -51,7 +46,6 @@ import org.bukkit.event.entity.CreatureSpawnEvent; import org.jetbrains.annotations.NotNull; import javax.annotation.Nullable; -import java.lang.reflect.Method; import java.util.*; import java.util.concurrent.Callable; import java.util.concurrent.Future; @@ -205,11 +199,6 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { }; } - @Override - public char[] load(int layer) { - return load(layer, null); - } - private void updateGet(BukkitGetBlocks_1_14 get, Chunk nmsChunk, ChunkSection[] sections, ChunkSection section, char[] arr, int layer) { synchronized (get) { if (this.nmsChunk != nmsChunk) { @@ -271,7 +260,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { bitMask |= 1 << layer; - char[] setArr = set.getArray(layer); + char[] setArr = set.load(layer); ChunkSection newSection; ChunkSection existingSection = sections[layer]; if (existingSection == null) { @@ -506,7 +495,7 @@ public class BukkitGetBlocks_1_14 extends CharGetBlocks { } @Override - public synchronized char[] load(int layer, char[] data) { + public synchronized char[] update(int layer, char[] data) { ChunkSection section = getSections()[layer]; // Section is null, return empty array if (section == null) { diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index 361f06e93..a4d23ef91 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -7,7 +7,7 @@ plugins { } repositories { - maven { url = uri("http://ci.athion.net/job/PlotSquared-Breaking/ws/mvn/") } + maven { url = uri("http://ci.athion.net/job/PlotSquared-we/ws/mvn/") } } applyPlatformAndCoreConfiguration() diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java index fb0d6924e..a926bc7d2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweCache.java @@ -219,6 +219,8 @@ public enum FaweCache implements Trimable { public final CleanableThreadLocal BYTE_BUFFER_8192 = new CleanableThreadLocal<>(() -> new byte[8192]); + public final CleanableThreadLocal BYTE_BUFFER_256 = new CleanableThreadLocal<>(() -> new byte[256]); + public final CleanableThreadLocal BLOCK_TO_PALETTE = new CleanableThreadLocal<>(() -> { int[] result = new int[BlockTypesCache.states.length]; Arrays.fill(result, Integer.MAX_VALUE); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/Filter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/Filter.java index a4aaf9b3f..622d29b4e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/Filter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/Filter.java @@ -29,7 +29,7 @@ public interface Filter { * @param chunk * @return */ - default IChunk applyChunk(IChunk chunk, @Nullable Region region) { + default T applyChunk(T chunk, @Nullable Region region) { return chunk; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java index bbb522840..826208570 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBatchProcessor.java @@ -45,7 +45,7 @@ public interface IBatchProcessor { for (int layer = 0; layer <= minLayer; layer++) { if (set.hasSection(layer)) { if (layer == minLayer) { - char[] arr = set.getArray(layer); + char[] arr = set.load(layer); int index = (minY & 15) << 8; for (int i = 0; i < index; i++) arr[i] = 0; set.setBlocks(layer, arr); @@ -58,7 +58,7 @@ public interface IBatchProcessor { for (int layer = maxLayer; layer < FaweCache.IMP.CHUNK_LAYERS; layer++) { if (set.hasSection(layer)) { if (layer == minLayer) { - char[] arr = set.getArray(layer); + char[] arr = set.load(layer); int index = ((maxY + 1) & 15) << 8; for (int i = index; i < arr.length; i++) arr[i] = 0; set.setBlocks(layer, arr); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java index e0a5519b3..03cd25794 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IBlocks.java @@ -2,19 +2,16 @@ package com.boydti.fawe.beta; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.FaweOutputStream; -import com.boydti.fawe.object.collection.BitArray4096; import com.boydti.fawe.object.io.FastByteArrayOutputStream; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BiomeType; -import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.registry.BlockRegistry; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Map; import java.util.Set; @@ -26,7 +23,7 @@ public interface IBlocks extends Trimable { boolean hasSection(int layer); - char[] getArray(int layer); + char[] load(int layer); BlockState getBlock(int x, int y, int z); @@ -64,7 +61,7 @@ public interface IBlocks extends Trimable { for (int layer = 0; layer < FaweCache.IMP.CHUNK_LAYERS; layer++) { if (!this.hasSection(layer)) continue; - char[] ids = this.getArray(layer); + char[] ids = this.load(layer); int nonEmpty = 0; // TODO optimize into same loop as toPalette for (int i = 0; i < ids.length; i++) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java index 74298b190..d40602121 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IChunk.java @@ -7,17 +7,13 @@ 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; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; import javax.annotation.Nullable; /** * Represents a chunk in the queue {@link IQueueExtent} Used for getting and setting blocks / biomes * / entities */ -public interface IChunk> extends Trimable, Callable, IChunkGet { - +public interface IChunk extends Trimable, IChunkGet, IChunkSet { /** * Initialize at the location * (allows for reuse) @@ -26,8 +22,7 @@ public interface IChunk> extends Trimable, Callable, IChu * @param x * @param z */ - void init(IQueueExtent extent, int x, int z); - + default void init(IQueueExtent extent, int x, int z) {} /** * Get chunkX * @return @@ -56,30 +51,6 @@ public interface IChunk> extends Trimable, Callable, IChu */ boolean isEmpty(); - /** - * Apply the queued changes to the world containing this chunk. - *

The future returned may return another future. To ensure completion keep calling {@link - * Future#get()} on each result.

- * - * @return Future - */ - @Override - T call(); - - /** - * Call and join - * - Should be done async, if at all - * @throws ExecutionException - * @throws InterruptedException - */ - default void join() throws ExecutionException, InterruptedException { - T future = call(); - while (future != null) { - future = future.get(); - } - return; - } - /** * Filter through all the blocks in the chunk * @@ -89,14 +60,14 @@ public interface IChunk> extends Trimable, Callable, IChu */ void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region); - /** - * Flood through all the blocks in the chunk - * TODO not implemented - * @param flood - * @param mask - * @param block - */ - void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block); +// /** +// * Flood through all the blocks in the chunk +// * TODO not implemented +// * @param flood +// * @param mask +// * @param block +// */ +// void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block); /* set - queues a change */ boolean setBiome(int x, int y, int z, BiomeType biome); @@ -117,13 +88,8 @@ public interface IChunk> extends Trimable, Callable, IChu @Override CompoundTag getTag(int x, int y, int z); - /** - * Reset (defaults to just calling init) - * @return - */ @Override - default IBlocks reset() { - init(null, getX(), getZ()); + default IChunk reset() { return this; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java index 74c36d532..3e61d4d14 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateChunk.java @@ -21,13 +21,13 @@ import javax.annotation.Nullable; * * @param parent class */ -public interface IDelegateChunk extends IChunk { +public interface IDelegateChunk extends IQueueChunk { U getParent(); @Override - default IChunk getRoot() { - IChunk root = getParent(); + default IQueueChunk getRoot() { + IQueueChunk root = getParent(); while (root instanceof IDelegateChunk) { root = ((IDelegateChunk) root).getParent(); } @@ -49,10 +49,10 @@ public interface IDelegateChunk extends IChunk { return getParent().hasSection(layer); } - @Override - default void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) { - getParent().flood(flood, mask, block); - } +// @Override +// default void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) { +// getParent().flood(flood, mask, block); +// } @Override default boolean setTile(int x, int y, int z, CompoundTag tag) { @@ -84,11 +84,6 @@ public interface IDelegateChunk extends IChunk { return getParent().getFullBlock(x, y, z); } - @Override - default char[] load(int layer) { - return getParent().load(layer); - } - @Override default void init(IQueueExtent extent, int chunkX, int chunkZ) { getParent().init(extent, chunkX, chunkZ); @@ -146,8 +141,33 @@ public interface IDelegateChunk extends IChunk { } @Override - default char[] getArray(int layer) { - return getParent().getArray(layer); + default char[] load(int layer) { + return getParent().load(layer); + } + + @Override + default void setBlocks(int layer, char[] data) { + getParent().setBlocks(layer, data); + } + + @Override + default void setEntity(CompoundTag tag) { + getParent().setEntity(tag); + } + + @Override + default void removeEntity(UUID uuid) { + getParent().removeEntity(uuid); + } + + @Override + default Set getEntityRemoves() { + return getParent().getEntityRemoves(); + } + + @Override + default BiomeType[] getBiomes() { + return getParent().getBiomes(); } default T findParent(Class clazz) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java index c576049d7..a784baf31 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateQueueExtent.java @@ -35,9 +35,9 @@ import java.util.concurrent.Future; /** * Delegate for IQueueExtent */ -public interface IDelegateQueueExtent extends IQueueExtent { +public interface IDelegateQueueExtent extends IQueueExtent { - IQueueExtent getParent(); + IQueueExtent getParent(); @Override default boolean isQueueEnabled() { @@ -70,12 +70,12 @@ public interface IDelegateQueueExtent extends IQueueExtent { } @Override - default IChunk getOrCreateChunk(int x, int z) { + default T getOrCreateChunk(int x, int z) { return getParent().getOrCreateChunk(x, z); } @Override - default > T submit(IChunk chunk) { + default > V submit(T chunk) { return getParent().submit(chunk); } @@ -120,12 +120,12 @@ public interface IDelegateQueueExtent extends IQueueExtent { } @Override - default IChunk create(boolean isFull) { + default T create(boolean isFull) { return getParent().create(isFull); } @Override - default IChunk wrap(IChunk root) { + default T wrap(T root) { return getParent().wrap(root); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueChunk.java new file mode 100644 index 000000000..f60556029 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IQueueChunk.java @@ -0,0 +1,41 @@ +package com.boydti.fawe.beta; + +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +public interface IQueueChunk> extends IChunk, Callable { + /** + * Reset (defaults to just calling init) + * @return + */ + @Override + default IQueueChunk reset() { + init(null, getX(), getZ()); + return this; + } + + /** + * Apply the queued changes to the world containing this chunk. + *

The future returned may return another future. To ensure completion keep calling {@link + * Future#get()} on each result.

+ * + * @return Future + */ + @Override + T call(); + + /** + * Call and join + * - Should be done async, if at all + * @throws ExecutionException + * @throws InterruptedException + */ + default void join() throws ExecutionException, InterruptedException { + T future = call(); + while (future != null) { + future = future.get(); + } + return; + } +} 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 abe3b7462..899abf343 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 @@ -25,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, IChunkExtent, IBatchProcessorHolder { +public interface IQueueExtent extends Flushable, Trimable, IChunkExtent, IBatchProcessorHolder { @Override default boolean isQueueEnabled() { @@ -78,7 +78,7 @@ public interface IQueueExtent extends Flushable, Trimable, IChunkExtent, IBatchP * @param chunk * @return result */ - > T submit(IChunk chunk); + > V submit(T chunk); @Override default BlockVector3 getMinimumPoint() { @@ -93,12 +93,12 @@ public interface IQueueExtent extends Flushable, Trimable, IChunkExtent, IBatchP /** * Create a new root IChunk object
- Full chunks will be reused, so a more optimized chunk * can be returned in that case
- Don't wrap the chunk, that should be done in {@link - * #wrap(IChunk)} + * #wrap(T)} * * @param isFull true if a more optimized chunk should be returned * @return a more optimized chunk object */ - IChunk create(boolean isFull); + T create(boolean isFull); /** * Wrap the chunk object (i.e. for region restrictions / limits etc.) @@ -106,7 +106,7 @@ public interface IQueueExtent extends Flushable, Trimable, IChunkExtent, IBatchP * @param root * @return wrapped chunk */ - default IChunk wrap(IChunk root) { + default T wrap(T root) { return root; } @@ -148,11 +148,11 @@ public interface IQueueExtent extends Flushable, Trimable, IChunkExtent, IBatchP if (!filter.appliesChunk(chunkX, chunkZ)) { return block; } - IChunk chunk = this.getOrCreateChunk(chunkX, chunkZ); + T chunk = this.getOrCreateChunk(chunkX, chunkZ); // Initialize chunk.init(this, chunkX, chunkZ); - IChunk newChunk = filter.applyChunk(chunk, region); + T newChunk = filter.applyChunk(chunk, region); if (newChunk != null) { chunk = newChunk; if (block == null) { 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 index 22716424e..f26c0f37b 100644 --- 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 @@ -9,7 +9,7 @@ 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 { +public interface IChunkExtent extends Extent { /** * Get the IChunk at a position (and cache it if it's not already) * @@ -17,7 +17,7 @@ public interface IChunkExtent extends Extent { * @param z * @return IChunk */ - IChunk getOrCreateChunk(int chunkX, int chunkZ); + T getOrCreateChunk(int chunkX, int chunkZ); @Override default boolean setBlock(int x, int y, int z, BlockStateHolder state) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java index ed068a773..2f237324b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/BitSetBlocks.java @@ -80,7 +80,7 @@ public class BitSetBlocks implements IChunkSet { } @Override - public char[] getArray(int layer) { + public char[] load(int layer) { char[] arr = FaweCache.IMP.SECTION_BITS_TO_CHAR.get(); MemBlockSet.IRow nullRowY = row.getRow(layer); if (nullRowY instanceof MemBlockSet.RowY) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java index 9f12d31f8..900b265d3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharBlocks.java @@ -2,16 +2,9 @@ package com.boydti.fawe.beta.implementation.blocks; import com.boydti.fawe.beta.IBlocks; import com.boydti.fawe.beta.IChunkSet; -import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypesCache; -import java.util.Map; -import java.util.Set; - public abstract class CharBlocks implements IBlocks { public static final Section FULL = new Section() { @@ -26,9 +19,9 @@ public abstract class CharBlocks implements IBlocks { blocks.sections[layer] = FULL; char[] arr = blocks.blocks[layer]; if (arr == null) { - arr = blocks.blocks[layer] = blocks.load(layer); + arr = blocks.blocks[layer] = blocks.update(layer, null); } else { - blocks.blocks[layer] = blocks.load(layer, arr); + blocks.blocks[layer] = blocks.update(layer, arr); } return arr; } @@ -74,11 +67,10 @@ public abstract class CharBlocks implements IBlocks { sections[layer] = EMPTY; } - public char[] load(int layer) { - return new char[4096]; - } - - public char[] load(int layer, char[] data) { + public char[] update(int layer, char[] data) { + if (data == null) { + return new char[4096]; + } for (int i = 0; i < 4096; i++) { data[i] = 0; } @@ -91,7 +83,7 @@ public abstract class CharBlocks implements IBlocks { } @Override - public char[] getArray(int layer) { + public char[] load(int layer) { return sections[layer].get(this, layer); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/DelegateChunkSet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/DelegateChunkSet.java index e288ebd9c..53c237753 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/DelegateChunkSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/DelegateChunkSet.java @@ -54,8 +54,8 @@ public interface DelegateChunkSet extends IChunkSet { } @Override - default char[] getArray(int layer) { - return getParent().getArray(layer); + default char[] load(int layer) { + return getParent().load(layer); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/FallbackChunkGet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/FallbackChunkGet.java index 8cc1b5b9c..0e0c81100 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/FallbackChunkGet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/FallbackChunkGet.java @@ -4,7 +4,6 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.beta.IBlocks; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; -import com.boydti.fawe.util.MathMan; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; @@ -90,7 +89,7 @@ public class FallbackChunkGet implements IChunkGet { public > T call(IChunkSet set, Runnable finalize) { for (int layer = 0; layer < 16; layer++) { if (set.hasSection(layer)) { - char[] arr = set.getArray(layer); + char[] arr = set.load(layer); int by = layer << 4; for (int y = 0, i = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { @@ -160,11 +159,6 @@ public class FallbackChunkGet implements IChunkGet { return true; } - @Override - public char[] getArray(int layer) { - return new char[0]; - } - @Override public IBlocks reset() { return null; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.java index b6996623a..ffdb8ecc8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/NullChunkGet.java @@ -76,11 +76,6 @@ public enum NullChunkGet implements IChunkGet { return false; } - @Override - public char[] getArray(int layer) { - return new char[0]; - } - @Override public IBlocks reset() { return null; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java index 91db98cc0..aea573eed 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ChunkHolder.java @@ -1,10 +1,9 @@ package com.boydti.fawe.beta.implementation.chunk; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.beta.IQueueChunk; import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock; import com.boydti.fawe.beta.Filter; -import com.boydti.fawe.beta.FilterBlockMask; -import com.boydti.fawe.beta.Flood; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; @@ -27,7 +26,7 @@ import javax.annotation.Nullable; /** * An abstract {@link IChunk} class that implements basic get/set blocks */ -public class ChunkHolder> implements IChunk { +public class ChunkHolder> implements IQueueChunk { private static FaweCache.Pool POOL = FaweCache.IMP.registerPool(ChunkHolder.class, ChunkHolder::new, Settings.IMP.QUEUE.POOL); @@ -61,7 +60,32 @@ public class ChunkHolder> implements IChunk { @Override public boolean setTile(int x, int y, int z, CompoundTag tag) { - return false; + return delegate.set(this).setTile(x, y, z, tag); + } + + @Override + public void setEntity(CompoundTag tag) { + delegate.set(this).setEntity(tag); + } + + @Override + public void removeEntity(UUID uuid) { + delegate.set(this).removeEntity(uuid); + } + + @Override + public Set getEntityRemoves() { + return delegate.set(this).getEntityRemoves(); + } + + @Override + public BiomeType[] getBiomes() { + return delegate.set(this).getBiomes(); // TODO return get? + } + + @Override + public void setBlocks(int layer, char[] data) { + delegate.set(this).setBlocks(layer, data); } @Override @@ -259,10 +283,10 @@ public class ChunkHolder> implements IChunk { } }; - @Override - public void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) { -// block.flood(get, set, mask, block, ); - } +// @Override +// public void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) { +//// block.flood(get, set, mask, block, ); +// } @Override public CompoundTag getTag(int x, int y, int z) { @@ -285,11 +309,6 @@ public class ChunkHolder> implements IChunk { return chunkExisting != null && chunkExisting.hasSection(layer); } - @Override - public char[] getArray(int layer) { - return delegate.get(this).getArray(layer); - } - @Override public void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region) { final IChunkGet get = getOrCreateGet(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/DelegateChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/DelegateChunk.java index 7cc7bfb01..61f26467a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/DelegateChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/DelegateChunk.java @@ -2,11 +2,17 @@ package com.boydti.fawe.beta.implementation.chunk; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IDelegateChunk; +import com.boydti.fawe.beta.IQueueChunk; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.world.biome.BiomeType; + +import java.util.Set; +import java.util.UUID; /** * Implementation of IDelegateChunk */ -public class DelegateChunk implements IDelegateChunk { +public class DelegateChunk implements IDelegateChunk { private T parent; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/FinalizedChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/FinalizedChunk.java index 539923000..7f5de9101 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/FinalizedChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/FinalizedChunk.java @@ -1,6 +1,6 @@ package com.boydti.fawe.beta.implementation.chunk; -import com.boydti.fawe.beta.IChunk; +import com.boydti.fawe.beta.IQueueChunk; import com.boydti.fawe.beta.IQueueExtent; /** @@ -11,7 +11,7 @@ public class FinalizedChunk extends DelegateChunk { private final IQueueExtent queueExtent; - public FinalizedChunk(IChunk parent, IQueueExtent queueExtent) { + public FinalizedChunk(IQueueChunk parent, IQueueExtent queueExtent) { super(parent); this.queueExtent = queueExtent; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java index c93d0b43b..8083bdf2a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/NullChunk.java @@ -1,5 +1,6 @@ package com.boydti.fawe.beta.implementation.chunk; +import com.boydti.fawe.beta.IQueueChunk; import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock; import com.boydti.fawe.beta.Filter; import com.boydti.fawe.beta.FilterBlockMask; @@ -23,7 +24,7 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.Future; -public enum NullChunk implements IChunk { +public enum NullChunk implements IQueueChunk { INSTANCE; @Override @@ -54,10 +55,10 @@ public enum NullChunk implements IChunk { } - @Override - public void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) { - - } +// @Override +// public void flood(Flood flood, FilterBlockMask mask, ChunkFilterBlock block) { +// +// } @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { @@ -69,11 +70,36 @@ public enum NullChunk implements IChunk { return false; } + @Override + public void setEntity(CompoundTag tag) { + + } + + @Override + public void removeEntity(UUID uuid) { + + } + + @Override + public Set getEntityRemoves() { + return null; + } + + @Override + public BiomeType[] getBiomes() { + return null; + } + @Override public boolean setBlock(int x, int y, int z, BlockStateHolder block) { return false; } + @Override + public void setBlocks(int layer, char[] data) { + + } + @Override public BiomeType getBiomeType(int x, int z) { return null; @@ -84,11 +110,6 @@ public enum NullChunk implements IChunk { return false; } - @Override - public char[] getArray(int layer) { - return null; - } - @Override public BlockState getBlock(int x, int y, int z) { return BlockTypes.__RESERVED__.getDefaultState(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ReferenceChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ReferenceChunk.java index 4c8190066..5522c49bd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ReferenceChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/ReferenceChunk.java @@ -2,6 +2,7 @@ package com.boydti.fawe.beta.implementation.chunk; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IDelegateChunk; +import com.boydti.fawe.beta.IQueueChunk; import com.boydti.fawe.beta.IQueueExtent; import java.lang.ref.Reference; @@ -14,14 +15,14 @@ public abstract class ReferenceChunk implements IDelegateChunk { private final Reference reference; - public ReferenceChunk(IChunk parent, IQueueExtent queueExtent) { + public ReferenceChunk(IQueueChunk parent, IQueueExtent queueExtent) { this.reference = toReference(new FinalizedChunk(parent, queueExtent)); } protected abstract Reference toReference(FinalizedChunk parent); @Override - public IChunk getParent() { + public IQueueChunk getParent() { final FinalizedChunk finalized = reference.get(); return finalized != null ? finalized.getParent() : null; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/SoftChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/SoftChunk.java index ee69d6452..cd58d4c97 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/SoftChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/SoftChunk.java @@ -1,6 +1,7 @@ package com.boydti.fawe.beta.implementation.chunk; import com.boydti.fawe.beta.IChunk; +import com.boydti.fawe.beta.IQueueChunk; import com.boydti.fawe.beta.IQueueExtent; import java.lang.ref.Reference; import java.lang.ref.SoftReference; @@ -10,7 +11,7 @@ import java.lang.ref.SoftReference; */ public class SoftChunk extends ReferenceChunk { - public SoftChunk(IChunk parent, IQueueExtent queueExtent) { + public SoftChunk(IQueueChunk parent, IQueueExtent queueExtent) { super(parent, queueExtent); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/WeakChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/WeakChunk.java index 6b7d24561..4c5e556c3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/WeakChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/chunk/WeakChunk.java @@ -1,6 +1,7 @@ package com.boydti.fawe.beta.implementation.chunk; import com.boydti.fawe.beta.IChunk; +import com.boydti.fawe.beta.IQueueChunk; import com.boydti.fawe.beta.IQueueExtent; import java.lang.ref.Reference; @@ -11,7 +12,7 @@ import java.lang.ref.WeakReference; */ public class WeakChunk extends ReferenceChunk { - public WeakChunk(IChunk parent, IQueueExtent queueExtent) { + public WeakChunk(IQueueChunk parent, IQueueExtent queueExtent) { super(parent, queueExtent); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/CharFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/CharFilterBlock.java index f1048fd94..aead8fc15 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/CharFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/CharFilterBlock.java @@ -94,7 +94,7 @@ public class CharFilterBlock extends ChunkFilterBlock { this.set = iset; getArr = get.sections[layer].get(get, layer); if (set.hasSection(layer)) { - setArr = set.getArray(layer); + setArr = set.load(layer); delegate = FULL; } else { delegate = NULL; @@ -409,7 +409,7 @@ public class CharFilterBlock extends ChunkFilterBlock { Set delegate */ private SetDelegate initSet() { - setArr = set.getArray(layer); + setArr = set.load(layer); return delegate = FULL; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java index 6f3386d11..82ad93be9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/QueueHandler.java @@ -6,6 +6,7 @@ import com.boydti.fawe.beta.IBatchProcessor; import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunkGet; import com.boydti.fawe.beta.IChunkSet; +import com.boydti.fawe.beta.IQueueChunk; import com.boydti.fawe.beta.IQueueExtent; import com.boydti.fawe.beta.Trimable; import com.boydti.fawe.beta.implementation.cache.ChunkCache; @@ -228,7 +229,7 @@ public abstract class QueueHandler implements Trimable, Runnable { } } - public > T submit(IChunk chunk) { + public > T submit(IQueueChunk chunk) { // if (MemUtil.isMemoryFree()) { TODO NOT IMPLEMENTED - optimize this // return (T) forkJoinPoolSecondary.submit(chunk); // } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java index 3f5406d81..53c42cce5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/queue/SingleThreadQueueExtent.java @@ -1,6 +1,7 @@ package com.boydti.fawe.beta.implementation.queue; import com.boydti.fawe.Fawe; +import com.boydti.fawe.beta.IQueueChunk; import com.boydti.fawe.beta.implementation.filter.block.CharFilterBlock; import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock; import com.boydti.fawe.beta.IBatchProcessor; @@ -34,12 +35,12 @@ import java.util.concurrent.Future; *

* This queue is reusable {@link #init(IChunkCache)} */ -public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implements IQueueExtent { +public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implements IQueueExtent { // // Pool discarded chunks for reuse (can safely be cleared by another thread) // private static final ConcurrentLinkedQueue CHUNK_POOL = new ConcurrentLinkedQueue<>(); // Chunks currently being queued / worked on - private final Long2ObjectLinkedOpenHashMap chunks = new Long2ObjectLinkedOpenHashMap<>(); + private final Long2ObjectLinkedOpenHashMap chunks = new Long2ObjectLinkedOpenHashMap<>(); private IChunkCache cacheGet; private IChunkCache cacheSet; @@ -48,7 +49,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen private Thread currentThread; private ConcurrentLinkedQueue submissions = new ConcurrentLinkedQueue<>(); // Last access pointers - private IChunk lastChunk; + private IQueueChunk lastChunk; private long lastPair = Long.MAX_VALUE; private boolean enabledQueue = true; @@ -135,7 +136,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen } @Override - public > T submit(IChunk chunk) { + public > V submit(IQueueChunk chunk) { if (lastChunk == chunk) { lastPair = Long.MAX_VALUE; lastChunk = null; @@ -152,18 +153,18 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen * @param * @return */ - private > T submitUnchecked(IChunk chunk) { + private > V submitUnchecked(IQueueChunk chunk) { if (chunk.isEmpty()) { chunk.recycle(); Future result = Futures.immediateFuture(null); - return (T) result; + return (V) result; } if (Fawe.isMainThread()) { - return chunk.call(); + return (V) chunk.call(); } - return Fawe.get().getQueueHandler().submit(chunk); + return (V) Fawe.get().getQueueHandler().submit(chunk); } @Override @@ -195,14 +196,14 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen * @param Z * @return IChunk */ - private IChunk poolOrCreate(int X, int Z) { - IChunk next = create(false); + private ChunkHolder poolOrCreate(int X, int Z) { + ChunkHolder next = create(false); next.init(this, X, Z); return next; } @Override - public final IChunk getOrCreateChunk(int x, int z) { + public final IQueueChunk getOrCreateChunk(int x, int z) { final long pair = (long) x << 32 | z & 0xffffffffL; if (pair == lastPair) { return lastChunk; @@ -213,7 +214,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen return NullChunk.INSTANCE; } - IChunk chunk = chunks.get(pair); + IQueueChunk chunk = chunks.get(pair); if (chunk instanceof ReferenceChunk) { chunk = ((ReferenceChunk) chunk).getParent(); } @@ -251,7 +252,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen } @Override - public IChunk create(boolean isFull) { + public ChunkHolder create(boolean isFull) { return ChunkHolder.newInstance(); } @@ -299,7 +300,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen public synchronized void flush() { if (!chunks.isEmpty()) { if (MemUtil.isMemoryLimited()) { - for (IChunk chunk : chunks.values()) { + for (IQueueChunk chunk : chunks.values()) { final Future future = submitUnchecked(chunk); if (future != null && !future.isDone()) { pollSubmissions(Settings.IMP.QUEUE.PARALLEL_THREADS, true); @@ -307,7 +308,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen } } } else { - for (IChunk chunk : chunks.values()) { + for (IQueueChunk chunk : chunks.values()) { final Future future = submitUnchecked(chunk); if (future != null && !future.isDone()) { submissions.add(future); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java index e1bed5e96..f91070f1a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAChunk.java @@ -1,7 +1,11 @@ package com.boydti.fawe.jnbt.anvil; import com.boydti.fawe.FaweCache; +import com.boydti.fawe.beta.Filter; +import com.boydti.fawe.beta.IChunk; import com.boydti.fawe.beta.IChunkSet; +import com.boydti.fawe.beta.IQueueExtent; +import com.boydti.fawe.beta.implementation.filter.block.ChunkFilterBlock; import com.boydti.fawe.jnbt.streamer.StreamDelegate; import com.boydti.fawe.jnbt.streamer.ValueReader; import com.boydti.fawe.object.collection.BitArray4096; @@ -15,9 +19,11 @@ import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeTypes; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockID; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -25,6 +31,7 @@ import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypesCache; +import javax.annotation.Nullable; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -34,12 +41,13 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.concurrent.Future; -public class MCAChunk implements IChunkSet { +public class MCAChunk implements IChunk { public final boolean[] hasSections = new boolean[16]; public boolean hasBiomes = false; - public final byte[] biomes = new byte[256]; + public final BiomeType[] biomes = new BiomeType[256]; public final char[] blocks = new char[65536]; @@ -92,6 +100,13 @@ public class MCAChunk implements IChunkSet { read(nis, readPos); } + @Override + public void init(IQueueExtent extent, int x, int z) { + if (x != chunkX || z != chunkZ) { + throw new UnsupportedOperationException("Not reuse capable"); + } + } + public void read(NBTInputStream nis, boolean readPos) throws IOException { StreamDelegate root = createDelegate(nis, readPos); nis.readNamedTagLazy(root); @@ -153,7 +168,7 @@ public class MCAChunk implements IChunkSet { CompoundTag entity = FaweCache.IMP.asTag(value); entities.put(entity.getUUID(), entity); }); - level.add("Biomes").withInt((index, value) -> biomes[index] = (byte) value); + level.add("Biomes").withInt((index, value) -> biomes[index] = BiomeTypes.getLegacy(value)); return root; } @@ -177,11 +192,11 @@ public class MCAChunk implements IChunkSet { } @Override - public IChunkSet reset() { + public MCAChunk reset() { return this.reset(true); } - public IChunkSet reset(boolean full) { + public MCAChunk reset(boolean full) { if (!tiles.isEmpty()) { tiles.clear(); } @@ -226,7 +241,12 @@ public class MCAChunk implements IChunkSet { out.writeNamedTag("InhabitedTime", inhabitedTime); out.writeNamedTag("LastUpdate", lastUpdate); if (hasBiomes) { - out.writeNamedTag("Biomes", biomes); + int type = NBTConstants.TYPE_BYTE_ARRAY; + out.writeNamedTagName("Biomes", type); + out.writeInt(biomes.length); + for (int i = 0; i < biomes.length; i++) { + out.write(biomes[i].getLegacyId()); + } } int len = 0; for (boolean hasSection : hasSections) { @@ -424,16 +444,12 @@ public class MCAChunk implements IChunkSet { @Override public BiomeType getBiomeType(int x, int z) { - return BiomeTypes.get(this.biomes[(z << 4) | x] & 0xFF); + return this.biomes[(z << 4) | x]; } @Override public BiomeType[] getBiomes() { - BiomeType[] tmp = new BiomeType[256]; - for (int i = 0; i < 256; i++) { - tmp[i] = BiomeTypes.get(this.biomes[i] & 0xFF); - } - return tmp; + return this.biomes; } @Override @@ -444,7 +460,7 @@ public class MCAChunk implements IChunkSet { @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { setModified(); - biomes[x + (z << 4)] = (byte) biome.getInternalId(); + biomes[x + (z << 4)] = biome; return true; } @@ -479,6 +495,16 @@ public class MCAChunk implements IChunkSet { return BlockState.getFromOrdinal(ordinal); } + @Override + public BaseBlock getFullBlock(int x, int y, int z) { + return null; + } + + @Override + public CompoundTag getTag(int x, int y, int z) { + return null; + } + public Set getEntityRemoves() { return new HashSet<>(); } @@ -499,7 +525,7 @@ public class MCAChunk implements IChunkSet { } @Override - public char[] getArray(int layer) { + public char[] load(int layer) { char[] tmp = FaweCache.IMP.SECTION_BITS_TO_CHAR.get(); int offset = layer << 12; for (int i = 0; i < 4096; i++) { @@ -513,7 +539,7 @@ public class MCAChunk implements IChunkSet { } public void setBiome(BiomeType biome) { - Arrays.fill(biomes, (byte) biome.getInternalId()); + Arrays.fill(this.biomes, biome); } public void removeEntity(UUID uuid) { @@ -524,4 +550,34 @@ public class MCAChunk implements IChunkSet { public boolean trim(boolean aggressive) { return isEmpty(); } + + @Override + public CompoundTag getEntity(UUID uuid) { + return this.entities.get(uuid); + } + + @Override + public Future call(IChunkSet set, Runnable finalize) { + return null; + } + + @Override + public void filterBlocks(Filter filter, ChunkFilterBlock block, @Nullable Region region) { + try { + if (region != null) { + region.filter(this, filter, block, this, this); + } else { + block = block.init(chunkX, chunkZ, this); + for (int layer = 0; layer < 16; layer++) { + if (!this.hasSection(layer) || !filter.appliesLayer(this, layer)) { + continue; + } + block.init(this, this, layer); + block.filter(filter); + } + } + } finally { + filter.finishChunk(this); + } + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java index cd980c54f..6fbe803c8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/cfi/HeightMapMCAGenerator.java @@ -1584,7 +1584,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr int index; int maxY = 0; int minY = Integer.MAX_VALUE; - byte[] heightMap = chunk.biomes; + byte[] heightMap = FaweCache.IMP.BYTE_BUFFER_256.get(); int globalIndex; for (int z = csz; z <= cez; z++) { globalIndex = z * getWidth() + csx; @@ -1717,7 +1717,10 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } for (int i = 0; i < 256; i++) { - chunk.biomes[i] = biomes[indexes[i]]; + byte biomeId = biomes[indexes[i]]; + if (biomeId != 0) { + chunk.biomes[i] = BiomeTypes.get(biomeId); + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java index 7d823c525..b640ab3cb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java @@ -173,11 +173,11 @@ public abstract class FaweChangeSet implements ChangeSet, IBatchProcessor { for (int layer = 0; layer < 16; layer++) { if (!set.hasSection(layer)) continue; // add each block and tile - char[] blocksGet = get.getArray(layer); + char[] blocksGet = get.load(layer); if (blocksGet == null) { blocksGet = FaweCache.IMP.EMPTY_CHAR_4096; } - char[] blocksSet = set.getArray(layer); + char[] blocksSet = set.load(layer); int by = layer << 4; for (int y = 0, index = 0; y < 16; y++) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweSchematicHandler.java b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweSchematicHandler.java index d4001bf56..a5d8e9e22 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweSchematicHandler.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/integrations/plotquared/FaweSchematicHandler.java @@ -54,10 +54,6 @@ public class FaweSchematicHandler extends SchematicHandler { final CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ())); final EditSession editSession = new EditSessionBuilder(world).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build(); - final int mx = pos1.getX(); - final int my = pos1.getY(); - final int mz = pos1.getZ(); - ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region); Clipboard holder = new BlockArrayClipboard(region, clipboard); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index ffc90b6f8..c933b3d7e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -630,7 +630,6 @@ public final class PlatformCommandManager { Command cmd = optional.get(); CommandQueuedCondition queued = cmd.getCondition().as(CommandQueuedCondition.class).orElse(null); if (queued != null && !queued.isQueued()) { - System.out.println("Not queued"); handleCommandOnCurrentThread(event); return; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index 97d073fb9..3fed12362 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -741,7 +741,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { int indexY, index; for (int layer = 0; layer < FaweCache.IMP.CHUNK_LAYERS; layer++) { if (set.hasSection(layer)) { - char[] arr = set.getArray(layer); + char[] arr = set.load(layer); if (trimX || trimZ) { indexY = 0; for (int y = 0; y < 16; y++, indexY += 256) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index be8865d1c..571b6cfb0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -294,7 +294,7 @@ public interface Region extends Iterable, Cloneable, IBatchProcess } else { boolean changed = true; processExtra = true; - char[] arr = set.getArray(layer); + char[] arr = set.load(layer); for (int y = 0, index = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++, index++) {