diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilter.java
new file mode 100644
index 000000000..eb941c5a9
--- /dev/null
+++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/DelegateFilter.java
@@ -0,0 +1,16 @@
+package com.boydti.fawe.beta;
+
+public abstract class DelegateFilter implements IDelegateFilter {
+ private final Filter parent;
+
+ public DelegateFilter(Filter parent) {
+ this.parent = parent;
+ }
+ @Override
+ public Filter getParent() {
+ return parent;
+ }
+
+ @Override
+ public abstract Filter fork();
+}
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 9bcdf29c8..ba55e3ef9 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
@@ -1,7 +1,10 @@
package com.boydti.fawe.beta;
+import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock;
+import javax.annotation.Nullable;
+
/**
* A filter is an interface used for setting blocks
*/
@@ -13,8 +16,8 @@ public interface Filter {
* @param cz
* @return
*/
- default boolean appliesChunk(final int cx, final int cz) {
- return true;
+ default Filter appliesChunk(final int cx, final int cz) {
+ return this;
}
/**
@@ -25,10 +28,14 @@ public interface Filter {
* @param chunk
* @return
*/
- default IChunk applyChunk(final IChunk chunk) {
+ default IChunk applyChunk(final IChunk chunk, @Nullable Region region) {
return chunk;
}
+ default Filter appliesLayer(IChunk chunk, int layer) {
+ return this;
+ }
+
/**
* Make changes to the block here
* - e.g. block.setId(...)
diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlock.java
index e305dc43c..c2e6508b3 100644
--- a/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlock.java
+++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/FilterBlock.java
@@ -1,15 +1,18 @@
package com.boydti.fawe.beta;
import com.sk89q.jnbt.CompoundTag;
+import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
+import javax.annotation.Nullable;
+
public interface FilterBlock {
FilterBlock init(IQueueExtent queue);
FilterBlock init(int X, int Z, IGetBlocks chunk);
- void filter(IGetBlocks get, ISetBlocks set, int layer, Filter filter);
+ void filter(IGetBlocks get, ISetBlocks set, int layer, Filter filter, @Nullable Region region);
void setOrdinal(int ordinal);
diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java
new file mode 100644
index 000000000..9f8274ef0
--- /dev/null
+++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/IDelegateFilter.java
@@ -0,0 +1,54 @@
+package com.boydti.fawe.beta;
+
+public interface IDelegateFilter extends Filter {
+ Filter getParent();
+
+ @Override
+ default Filter appliesChunk(int cx, int cz) {
+ Filter copy = getParent().appliesChunk(cx, cz);
+ if (copy == null) return null;
+ if (copy != getParent()) {
+ return newInstance(copy);
+ } else {
+ return this;
+ }
+ }
+
+ @Override
+ default IChunk applyChunk(IChunk chunk) {
+ return getParent().applyChunk(chunk);
+ }
+
+ @Override
+ default Filter appliesLayer(IChunk chunk, int layer) {
+ Filter copy = getParent().appliesLayer(chunk, layer);
+ if (copy == null) return null;
+ if (copy != getParent()) {
+ return newInstance(copy);
+ } else {
+ return this;
+ }
+ }
+
+ @Override
+ default void applyBlock(FilterBlock block) {
+ getParent().applyBlock(block);
+ }
+
+ @Override
+ default void finishChunk(IChunk chunk) {
+ getParent().finishChunk(chunk);
+ }
+
+ @Override
+ default void join() {
+ getParent().join();
+ }
+
+ @Override
+ default Filter fork() {
+ return newInstance(getParent().fork());
+ }
+
+ Filter newInstance(Filter other);
+}
diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/ISetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/ISetBlocks.java
index dda0dfd5a..7ba1f664a 100644
--- a/worldedit-core/src/main/java/com/boydti/fawe/beta/ISetBlocks.java
+++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/ISetBlocks.java
@@ -27,10 +27,6 @@ public interface ISetBlocks extends IBlocks {
void removeEntity(UUID uuid);
- default void optimize() {
-
- }
-
BlockState getBlock(int x, int y, int z);
char[] getArray(int layer);
diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/RegionFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/RegionFilter.java
new file mode 100644
index 000000000..791e040d6
--- /dev/null
+++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/RegionFilter.java
@@ -0,0 +1,37 @@
+package com.boydti.fawe.beta;
+
+import com.sk89q.worldedit.regions.Region;
+
+public class RegionFilter extends DelegateFilter {
+ private final Region region;
+
+ public RegionFilter(Filter parent, Region region) {
+ super(parent);
+ this.region = region;
+ }
+
+ @Override
+ public Filter appliesChunk(int cx, int cz) {
+ return getParent().appliesChunk(cx, cz);
+ }
+
+ @Override
+ public Filter appliesLayer(IChunk chunk, int layer) {
+ return getParent().appliesLayer(chunk, layer);
+ }
+
+ @Override
+ public void applyBlock(FilterBlock block) {
+ getParent().applyBlock(block);
+ }
+
+ @Override
+ public void finishChunk(IChunk chunk) {
+ getParent().finishChunk(chunk);
+ }
+
+ @Override
+ public Filter newInstance(Filter other) {
+ return new RegionFilter(other, region);
+ }
+}
diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java
index b7965f2a3..26e7bf898 100644
--- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java
+++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/QueueHandler.java
@@ -170,13 +170,13 @@ public abstract class QueueHandler implements Trimable, Runnable {
X = pos.getX();
Z = pos.getZ();
}
+ if (!newFilter.appliesChunk(X, Z)) {
+ continue;
+ }
IChunk chunk = queue.getCachedChunk(X, Z);
// Initialize
chunk.init(queue, X, Z);
- if (!newFilter.appliesChunk(X, Z)) {
- continue;
- }
chunk = newFilter.applyChunk(chunk);
if (chunk == null) continue;
diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java
index fe5a0286e..5c92c09aa 100644
--- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java
+++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/blocks/CharGetBlocks.java
@@ -1,8 +1,5 @@
package com.boydti.fawe.beta.implementation.blocks;
-import com.boydti.fawe.beta.CharFilterBlock;
-import com.boydti.fawe.beta.Filter;
-import com.boydti.fawe.beta.FilterBlock;
import com.boydti.fawe.beta.IGetBlocks;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState;
diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/holder/ChunkHolder.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/holder/ChunkHolder.java
index 46c491cfa..878f3c039 100644
--- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/holder/ChunkHolder.java
+++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/holder/ChunkHolder.java
@@ -41,7 +41,7 @@ public abstract class ChunkHolder implements IChunk, Supplier {
final ISetBlocks set = getOrCreateSet();
block = block.init(X, Z, get);
for (int layer = 0; layer < 16; layer++) {
- if (!get.hasSection(layer)) continue;
+ if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
block.filter(get, set, layer, filter);
}
filter.finishChunk(this);
@@ -98,13 +98,6 @@ public abstract class ChunkHolder implements IChunk, Supplier {
return get();
}
-// @Override
-// public void optimize() {
-// if (set != null) {
-// set.optimize();
-// }
-// }
-
@Override
public void init(final IQueueExtent extent, final int X, final int Z) {
this.extent = extent;