From 88a95221a89bac2167ab876a8b8d3910806cfe56 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 4 Jan 2020 10:11:13 +0000 Subject: [PATCH] Make masks more stateless --- .../adapter/impl/FAWE_Spigot_v1_13_R2.java | 1 - .../filter/block/AbstractFilterBlock.java | 5 +- .../filter/block/ArrayFilterBlock.java | 18 +- .../filter/block/ExtentFilterBlock.java | 5 + .../filter/block/MultiFilterBlock.java | 39 ++++ .../filter/block/VectorSingleFilterBlock.java | 32 --- .../com/boydti/fawe/command/CFICommands.java | 2 +- .../fawe/object/brush/CopyPastaBrush.java | 12 +- .../boydti/fawe/object/brush/ImageBrush.java | 7 +- .../boydti/fawe/object/brush/LayerBrush.java | 51 +++-- .../fawe/object/brush/RecurseBrush.java | 5 +- .../fawe/object/brush/ScatterBrush.java | 12 +- .../object/brush/ScatterOverlayBrush.java | 2 +- .../fawe/object/brush/ShatterBrush.java | 2 +- .../fawe/object/brush/SplatterBrush.java | 20 +- .../boydti/fawe/object/brush/SplineBrush.java | 2 + .../fawe/object/brush/StencilBrush.java | 6 +- .../fawe/object/brush/SurfaceSphereBrush.java | 4 +- .../cfi/HeightMapMCAGenerator.java | 200 +++++++++--------- .../object/clipboard/LinearClipboard.java | 6 + .../object/collection/DifferentialArray.java | 20 +- .../fawe/object/extent/SourceMaskExtent.java | 22 +- .../function/mask/AbstractDelegateMask.java | 12 ++ .../fawe/object/mask/AdjacentAnyMask.java | 64 ++---- .../boydti/fawe/object/mask/AdjacentMask.java | 15 +- .../boydti/fawe/object/mask/AngleMask.java | 48 ++--- .../boydti/fawe/object/mask/BiomeMask.java | 4 +- .../fawe/object/mask/BlockLightMask.java | 3 +- .../fawe/object/mask/BrightnessMask.java | 3 +- .../boydti/fawe/object/mask/CachedMask.java | 11 +- .../com/boydti/fawe/object/mask/DataMask.java | 3 +- .../boydti/fawe/object/mask/ExtremaMask.java | 18 +- .../boydti/fawe/object/mask/IdDataMask.java | 3 +- .../com/boydti/fawe/object/mask/IdMask.java | 3 +- .../boydti/fawe/object/mask/LightMask.java | 6 +- .../fawe/object/mask/MaskedTargetBlock.java | 2 +- .../boydti/fawe/object/mask/OpacityMask.java | 6 +- .../boydti/fawe/object/mask/PlaneMask.java | 3 +- .../boydti/fawe/object/mask/ROCAngleMask.java | 12 +- .../boydti/fawe/object/mask/RadiusMask.java | 3 +- .../boydti/fawe/object/mask/RandomMask.java | 3 +- .../boydti/fawe/object/mask/SimplexMask.java | 3 +- .../boydti/fawe/object/mask/SkyLightMask.java | 6 +- .../fawe/object/mask/SolidPlaneMask.java | 3 +- .../boydti/fawe/object/mask/SurfaceMask.java | 4 +- .../com/boydti/fawe/object/mask/WallMask.java | 11 +- .../boydti/fawe/object/mask/XAxisMask.java | 3 +- .../boydti/fawe/object/mask/YAxisMask.java | 3 +- .../boydti/fawe/object/mask/ZAxisMask.java | 3 +- .../fawe/object/pattern/MaskedPattern.java | 3 +- .../fawe/object/regions/FuzzyRegion.java | 4 +- .../com/boydti/fawe/util/TextureUtil.java | 2 +- .../java/com/sk89q/worldedit/EditSession.java | 42 ++-- .../com/sk89q/worldedit/extent/Extent.java | 16 +- .../sk89q/worldedit/extent/MaskingExtent.java | 8 +- .../sk89q/worldedit/extent/NullExtent.java | 1 + .../worldedit/extent/buffer/ExtentBuffer.java | 4 +- .../extent/buffer/ForgetfulExtentBuffer.java | 6 +- .../function/FlatRegionMaskingFilter.java | 2 +- .../function/RegionMaskTestFunction.java | 3 +- .../function/RegionMaskingFilter.java | 10 +- .../worldedit/function/block/Naturalizer.java | 4 +- .../worldedit/function/generator/OreGen.java | 4 +- .../function/generator/SchemGen.java | 2 +- .../worldedit/function/mask/ABlockMask.java | 6 + .../function/mask/AbstractExtentMask.java | 12 ++ .../worldedit/function/mask/BiomeMask2D.java | 2 +- .../function/mask/BlockCategoryMask.java | 4 +- .../worldedit/function/mask/BlockMask.java | 4 +- .../function/mask/BlockStateMask.java | 4 +- .../function/mask/BlockTypeMask.java | 4 +- .../function/mask/BoundedHeightMask.java | 3 +- .../function/mask/DelegateExtentMask.java | 28 +++ .../function/mask/ExistingBlockMask.java | 4 +- .../function/mask/ExpressionMask.java | 3 +- .../function/mask/ExpressionMask2D.java | 3 +- .../worldedit/function/mask/InverseMask.java | 5 +- .../mask/InverseSingleBlockStateMask.java | 4 +- .../mask/InverseSingleBlockTypeMask.java | 4 +- .../sk89q/worldedit/function/mask/Mask.java | 24 ++- .../sk89q/worldedit/function/mask/Mask2D.java | 15 +- .../worldedit/function/mask/MaskFilter.java | 2 +- .../function/mask/MaskIntersection.java | 5 +- .../function/mask/MaskIntersection2D.java | 5 +- .../worldedit/function/mask/MaskUnion.java | 5 +- .../worldedit/function/mask/MaskUnion2D.java | 5 +- .../sk89q/worldedit/function/mask/Masks.java | 27 ++- .../worldedit/function/mask/NoiseFilter.java | 3 +- .../function/mask/NoiseFilter2D.java | 3 +- .../worldedit/function/mask/OffsetMask.java | 5 +- .../worldedit/function/mask/OffsetMask2D.java | 9 +- .../worldedit/function/mask/RegionMask.java | 3 +- .../function/mask/SingleBlockStateMask.java | 4 +- .../function/mask/SingleBlockTypeMask.java | 6 - .../function/operation/ForwardExtentCopy.java | 4 +- .../com/sk89q/worldedit/util/TargetBlock.java | 19 +- .../worldedit/world/block/BlockState.java | 7 + .../world/snapshot/SnapshotRestore.java | 2 +- 98 files changed, 617 insertions(+), 468 deletions(-) create mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/MultiFilterBlock.java delete mode 100644 worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/VectorSingleFilterBlock.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/DelegateExtentMask.java diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_13_R2.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_13_R2.java index 93c990cb9..72a061991 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_13_R2.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/FAWE_Spigot_v1_13_R2.java @@ -319,7 +319,6 @@ public final class FAWE_Spigot_v1_13_R2 extends CachedBukkitAdapter implements I BlockMaterial_1_13 material = (BlockMaterial_1_13) state.getMaterial(); return material.getCraftBlockData(); } catch (ClassCastException ignore) { - System.out.println(state.getAsString() + " cast"); throw ignore; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/AbstractFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/AbstractFilterBlock.java index 0a40471b6..18e0a139f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/AbstractFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/AbstractFilterBlock.java @@ -16,11 +16,8 @@ public abstract class AbstractFilterBlock extends FilterBlock { public abstract BaseBlock getFullBlock(); public abstract void setFullBlock(BaseBlock block); public abstract BlockVector3 getPosition(); - @Override - public Extent getExtent() { - return this; - } + public abstract Extent getExtent(); @Override public int getX() { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/ArrayFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/ArrayFilterBlock.java index f73f02bf8..e4f459a57 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/ArrayFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/ArrayFilterBlock.java @@ -19,9 +19,7 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock { private final int yOffset; private final int width, length; private int x, z, index; - private char ordinal; - // TODO use in CFI public ArrayFilterBlock(Extent extent, char[] blocks, byte[] heights, int width, int length, int yOffset) { super(extent); @@ -32,18 +30,16 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock { this.yOffset = yOffset; } - public void filter2D(Filter filter) { - for (z = 0; z < length; z++) { - for (x = 0; x < width; x++, index++) { - ordinal = blocks[ordinal]; - filter.applyBlock(this); - } - } + public void init(int x, int z, int index) { + this.x = x; + this.z = z; + this.index = index; } + @Override public int getOrdinal() { - return ordinal; + return blocks[index]; } @Override @@ -53,7 +49,7 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock { @Override public BlockState getBlock() { - return BlockTypesCache.states[ordinal]; + return BlockTypesCache.states[getOrdinal()]; } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/ExtentFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/ExtentFilterBlock.java index 4397f94dd..a2f86c3b0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/ExtentFilterBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/ExtentFilterBlock.java @@ -32,4 +32,9 @@ public class ExtentFilterBlock extends AbstractFilterBlock { public BlockVector3 getPosition() { return pos; } + + @Override + public Extent getExtent() { + return extent; + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/MultiFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/MultiFilterBlock.java new file mode 100644 index 000000000..c457556f3 --- /dev/null +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/MultiFilterBlock.java @@ -0,0 +1,39 @@ +package com.boydti.fawe.beta.implementation.filter.block; + +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; + +import javax.annotation.Nullable; + +public class MultiFilterBlock extends DelegateFilterBlock { + private final FilterBlock[] blocks; + private final int length; + + public MultiFilterBlock(FilterBlock... blocks) { + super(blocks[0]); + this.blocks = blocks; + this.length = blocks.length; + } + + @Override + public void setOrdinal(int ordinal) { + for (int i = 0; i < length; i++) blocks[i].setOrdinal(ordinal); + } + + @Override + public void setBlock(BlockState state) { + for (int i = 0; i < length; i++) blocks[i].setBlock(state); + } + + @Override + public void setFullBlock(BaseBlock block) { + for (int i = 0; i < length; i++) blocks[i].setFullBlock(block); + } + + @Override + public void setNbtData(@Nullable CompoundTag nbtData) { + for (int i = 0; i < length; i++) blocks[i].setNbtData(nbtData); + } +} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/VectorSingleFilterBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/VectorSingleFilterBlock.java deleted file mode 100644 index c96d714cc..000000000 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/filter/block/VectorSingleFilterBlock.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.boydti.fawe.beta.implementation.filter.block; - -import com.sk89q.worldedit.math.BlockVector3; -import com.sk89q.worldedit.world.block.BaseBlock; - -public class VectorSingleFilterBlock extends AbstractSingleFilterBlock { - private final BlockVector3 mutable; - - public VectorSingleFilterBlock(BlockVector3 mutable) { - this.mutable = mutable; - } - - public VectorSingleFilterBlock init(BaseBlock block) { - super.init(block); - return this; - } - - @Override - public int getX() { - return mutable.getX(); - } - - @Override - public int getY() { - return mutable.getY(); - } - - @Override - public int getZ() { - return mutable.getZ(); - } -} diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java index 6a0ed21fd..70c4a55c3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java @@ -456,7 +456,7 @@ public class CFICommands { for (int typeId : tu.getValidBlockIds()) { BlockType type = BlockTypes.get(typeId); extent.init(0, 0, 0, type.getDefaultState().toBaseBlock()); - if (mask.test(extent)) { + if (mask.test(extent, extent)) { blocks.add(type); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java index 55490f8b7..b894a9355 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java @@ -1,6 +1,8 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.config.Caption; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.function.mask.DelegateExtentMask; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.boydti.fawe.object.clipboard.ResizableClipboardBuilder; @@ -64,11 +66,11 @@ public class CopyPastaBrush implements Brush, ResettableTool { } final ResizableClipboardBuilder builder = new ResizableClipboardBuilder(editSession.getWorld()); final int minY = position.getBlockY(); - mask = new AbstractDelegateMask(mask) { + mask = new DelegateExtentMask(editSession, mask) { @Override - public boolean test(BlockVector3 vector) { - if (super.test(vector) && vector.getBlockY() >= minY) { - BaseBlock block = editSession.getFullBlock(vector); + public boolean test(Extent extent, BlockVector3 vector) { + if (super.test(extent, vector) && vector.getBlockY() >= minY) { + BaseBlock block = vector.getFullBlock(editSession); if (!block.getBlockType().getMaterial().isAir()) { builder.add(vector, BlockTypes.AIR.getDefaultState().toBaseBlock(), block); return true; @@ -78,7 +80,7 @@ public class CopyPastaBrush implements Brush, ResettableTool { } }; // Add origin - mask.test(position); + mask.test(editSession, position); RecursiveVisitor visitor = new RecursiveVisitor(mask, new NullRegionFunction(), (int) size); visitor.visit(position); Operations.completeBlindly(visitor); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java index 0e22ea96b..a2f08e1fc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java @@ -8,6 +8,7 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; @@ -86,11 +87,11 @@ public class ImageBrush implements Brush { float pitch = loc.getPitch(); AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX((pitch - 90) % 360).inverse(); - RecursiveVisitor visitor = new RecursiveVisitor(new Mask() { + RecursiveVisitor visitor = new RecursiveVisitor(new AbstractExtentMask(editSession) { private final MutableVector3 mutable = new MutableVector3(); @Override - public boolean test(BlockVector3 vector) { - if (solid.test(vector)) { + public boolean test(Extent extent, BlockVector3 vector) { + if (solid.test(extent, vector)) { int dx = vector.getBlockX() - cx; int dy = vector.getBlockY() - cy; int dz = vector.getBlockZ() - cz; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java index fd890ec46..df9ff4b56 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java @@ -6,7 +6,10 @@ import com.boydti.fawe.object.mask.RadiusMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.command.tool.brush.Brush; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.BlockMask; +import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; @@ -34,34 +37,42 @@ public class LayerBrush implements Brush { final AdjacentAnyMask adjacent = new AdjacentAnyMask(new BlockMask(editSession).add(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR)); final SolidBlockMask solid = new SolidBlockMask(editSession); final RadiusMask radius = new RadiusMask(0, (int) size); - visitor = new RecursiveVisitor(vector -> solid.test(vector) && radius.test(vector) && adjacent.test(vector), function -> true); + visitor = new RecursiveVisitor(new Mask() { + @Override + public boolean test(Extent extent, BlockVector3 vector) { + return solid.test(extent, vector) && radius.test(extent, vector) && adjacent.test(extent, vector); + } + }, function -> true); visitor.visit(position); visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS)); Operations.completeBlindly(visitor); BlockVectorSet visited = visitor.getVisited(); - visitor = new RecursiveVisitor(pos -> { - int depth = visitor.getDepth() + 1; - if (depth > 1) { - boolean found = false; - BlockState previous = layers[depth - 1]; - BlockState previous2 = layers[depth - 2]; - for (BlockVector3 dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) { - mutable.setComponents(pos.getBlockX() + dir.getBlockX(), pos.getBlockY() + dir.getBlockY(), pos.getBlockZ() + dir.getBlockZ()); - if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous) { - mutable.setComponents(pos.getBlockX() + dir.getBlockX() * 2, pos.getBlockY() + dir.getBlockY() * 2, pos.getBlockZ() + dir.getBlockZ() * 2); - if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous2) { - found = true; - break; - } else { - return false; + visitor = new RecursiveVisitor(new AbstractExtentMask(editSession) { + @Override + public boolean test(Extent extent, BlockVector3 pos) { + int depth = visitor.getDepth() + 1; + if (depth > 1) { + boolean found = false; + BlockState previous = layers[depth - 1]; + BlockState previous2 = layers[depth - 2]; + for (BlockVector3 dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) { + mutable.setComponents(pos.getBlockX() + dir.getBlockX(), pos.getBlockY() + dir.getBlockY(), pos.getBlockZ() + dir.getBlockZ()); + if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous) { + mutable.setComponents(pos.getBlockX() + dir.getBlockX() * 2, pos.getBlockY() + dir.getBlockY() * 2, pos.getBlockZ() + dir.getBlockZ() * 2); + if (visitor.isVisited(mutable) && editSession.getBlock(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous2) { + found = true; + break; + } else { + return false; + } } } + if (!found) { + return false; + } } - if (!found) { - return false; - } + return !adjacent.test(extent, pos); } - return !adjacent.test(pos); }, pos -> { int depth = visitor.getDepth(); BlockStateHolder currentPattern = layers[depth]; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java index 27c092e11..7e0ee0ee1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java @@ -6,6 +6,7 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.block.BlockReplace; +import com.sk89q.worldedit.function.mask.DelegateExtentMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.operation.Operations; @@ -27,6 +28,8 @@ public class RecurseBrush implements Brush { Mask mask = editSession.getMask(); if (mask == null) { mask = Masks.alwaysTrue(); + } else { + mask = mask.withExtent(editSession); } final int radius = (int) size; BlockStateHolder block = editSession.getBlock(position); @@ -42,7 +45,7 @@ public class RecurseBrush implements Brush { @Override public boolean isVisitable(BlockVector3 from, BlockVector3 to) { int y = to.getBlockY(); - return y < maxY && radMask.test(to) && super.isVisitable(from, to); + return y < maxY && radMask.test(editSession, to) && super.isVisitable(from, to); } }; visitor.visit(position); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java index 0b4dd8534..159027380 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java @@ -8,7 +8,11 @@ import com.boydti.fawe.object.mask.SurfaceMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.command.tool.brush.Brush; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.function.mask.AbstractExtentMask; +import com.sk89q.worldedit.function.mask.DelegateExtentMask; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.mask.MaskUnion; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; @@ -50,7 +54,7 @@ public class ScatterBrush implements Brush { final int distance = Math.min((int) size, this.distance); - RecursiveVisitor visitor = new RecursiveVisitor(vector -> radius.test(vector) && surface.test(vector), function -> true); + RecursiveVisitor visitor = new RecursiveVisitor(new MaskUnion(radius, surface).withExtent(editSession), function -> true); visitor.visit(position); visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS)); Operations.completeBlindly(visitor); @@ -87,11 +91,11 @@ public class ScatterBrush implements Brush { } public boolean canApply(EditSession editSession, BlockVector3 pos) { - return mask.test(pos); + return mask.test(editSession, pos); } - public BlockVector3 getDirection(BlockVector3 pt) { - return surface.direction(pt); + public BlockVector3 getDirection(Extent extent, BlockVector3 pt) { + return surface.direction(extent, pt); } public void apply(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 pt, Pattern p, double size) throws MaxChangedBlocksException { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java index 72ce8a9e8..96d003a2b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java @@ -16,7 +16,7 @@ public class ScatterOverlayBrush extends ScatterBrush { int x = pt.getBlockX(); int y = pt.getBlockY(); int z = pt.getBlockZ(); - BlockVector3 dir = getDirection(pt); + BlockVector3 dir = getDirection(editSession, pt); editSession.setBlock(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ(), p); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java index 62b78f249..903d4f80e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java @@ -76,7 +76,7 @@ public class ShatterBrush extends ScatterBrush { int dSqr = (dx * dx) + (dy * dy) + (dz * dz); if (dSqr <= radius2) { BlockVector3 bv = mutable.setComponents(x2, y2, z2); - if (surfaceTest.test(bv) && finalMask.test(bv)) { + if (surfaceTest.test(editSession, bv) && finalMask.test(editSession, bv)) { // (collision) If it's visited and part of another frontier, set the block if (!placed.add(x2, y2, z2)) { if (!frontierVisited.contains(x2, y2, z2)) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java index 6d89691ba..dc28716eb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java @@ -5,6 +5,9 @@ import com.boydti.fawe.object.mask.SurfaceMask; import com.boydti.fawe.object.pattern.BiomePattern; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.function.mask.AbstractExtentMask; +import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.BreadthFirstSearch; @@ -40,14 +43,17 @@ public class SplatterBrush extends ScatterBrush { final int size2 = (int) (size * size); SurfaceMask surface = new SurfaceMask(editSession); - RecursiveVisitor visitor = new RecursiveVisitor(vector -> { - double dist = vector.distanceSq(position); - if (dist < size2 && !placed.contains(vector) && ThreadLocalRandom.current().nextInt(5) < 2 - && surface.test(vector)) { - placed.add(vector); - return true; + RecursiveVisitor visitor = new RecursiveVisitor(new AbstractExtentMask(editSession) { + @Override + public boolean test(Extent extent, BlockVector3 vector) { + double dist = vector.distanceSq(position); + if (dist < size2 && !placed.contains(vector) && ThreadLocalRandom.current().nextInt(5) < 2 + && surface.test(extent, vector)) { + placed.add(vector); + return true; + } + return false; } - return false; }, vector -> editSession.setBlock(vector, finalPattern), recursion); visitor.setMaxBranch(2); visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java index 3cb6e5651..938344f27 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java @@ -1,6 +1,7 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.FaweCache; +import com.sk89q.worldedit.function.mask.DelegateExtentMask; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.boydti.fawe.object.mask.IdMask; @@ -52,6 +53,7 @@ public class SplineBrush implements Brush, ResettableTool { } else { mask = new MaskIntersection(mask, new IdMask(editSession)); } + mask = mask.withExtent(editSession); boolean visualization = editSession.getExtent() instanceof VisualExtent; if (visualization && positionSets.isEmpty()) { return; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/StencilBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/StencilBrush.java index b028af337..4791210f5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/StencilBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/StencilBrush.java @@ -5,7 +5,9 @@ import com.boydti.fawe.object.mask.AdjacentAnyMask; import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.mask.SolidBlockMask; @@ -61,10 +63,10 @@ public class StencilBrush extends HeightBrush { AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX(pitch - 90).inverse(); - RecursiveVisitor visitor = new RecursiveVisitor(new Mask() { + RecursiveVisitor visitor = new RecursiveVisitor(new AbstractExtentMask(editSession) { private final MutableVector3 mutable = new MutableVector3(); @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { if (solid.test(vector)) { int dx = vector.getBlockX() - cx; int dy = vector.getBlockY() - cy; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java index 194a43672..c04e4725e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java @@ -5,6 +5,8 @@ import com.boydti.fawe.object.mask.SurfaceMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.command.tool.brush.Brush; +import com.sk89q.worldedit.function.mask.DelegateExtentMask; +import com.sk89q.worldedit.function.mask.MaskUnion; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; @@ -20,7 +22,7 @@ public class SurfaceSphereBrush implements Brush { SurfaceMask surface = new SurfaceMask(editSession); final SolidBlockMask solid = new SolidBlockMask(editSession); final RadiusMask radius = new RadiusMask(0, (int) size); - RecursiveVisitor visitor = new RecursiveVisitor(vector -> surface.test(vector) && radius.test(vector), vector -> editSession.setBlock(vector, pattern)); + RecursiveVisitor visitor = new RecursiveVisitor(new MaskUnion(surface, radius).withExtent(editSession), vector -> editSession.setBlock(vector, pattern)); visitor.visit(position); visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS)); Operations.completeBlindly(visitor); 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 b32ff5a5e..8adb40108 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 @@ -7,6 +7,10 @@ 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.beta.implementation.filter.block.AbstractFilterBlock; +import com.boydti.fawe.beta.implementation.filter.block.ArrayFilterBlock; +import com.boydti.fawe.beta.implementation.filter.block.MultiFilterBlock; +import com.boydti.fawe.beta.implementation.filter.block.SingleFilterBlock; import com.boydti.fawe.beta.implementation.packet.ChunkPacket; import com.boydti.fawe.beta.implementation.blocks.FallbackChunkGet; import com.boydti.fawe.jnbt.anvil.MCAChunk; @@ -34,6 +38,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operation; @@ -54,6 +59,7 @@ import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.world.World; 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; @@ -552,7 +558,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr int y = heights[index] & 0xFF; mutable.mutX(x); mutable.mutY(y); - if (mask.test(mutable)) { + if (mask.test(this, mutable)) { int newHeight = table.average(x, z, index); setLayerHeightRaw(index, newHeight); } @@ -607,7 +613,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } mutable.mutX(x); mutable.mutY(y); - if (!mask.test(mutable)) { + if (!mask.test(this, mutable)) { continue; } if (placed.containsRadius(x, z, distance)) { @@ -654,7 +660,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } mutable.mutX(x); mutable.mutY(y); - if (!mask.test(mutable)) { + if (!mask.test(this, mutable)) { continue; } if (placed.containsRadius(x, z, distance)) { @@ -1066,7 +1072,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr if (mask != null) { mutable.mutX(z); mutable.mutY(heights.getByte(index) & 0xFF); - if (!mask.test(mutable)) continue; + if (!mask.test(this, mutable)) continue; } if (imgMask != null) { int height = imgMask.getRGB(x, z) & 0xFF; @@ -1181,7 +1187,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr for (int x = 0; x < getWidth(); x++, index++) { mutable.mutX(x); mutable.mutY(heights.getByte(index) & 0xFF); - if (mask.test(mutable)) { + if (mask.test(this, mutable)) { int color = img.getRGB(x, z); BlockType block = textureUtil.getNearestBlock(color); if (block != null) { @@ -1254,7 +1260,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr int y = heights.getByte(index) & 0xFF; mutable.mutX(x); mutable.mutY(y); - if (mask.test(mutable)) { + if (mask.test(this, mutable)) { biomes.setByte(index, biomeByte); } } @@ -1274,17 +1280,15 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } overlay.record(() -> { - char[] overlayArr = overlay.get(); + ArrayFilterBlock filter = new ArrayFilterBlock(this, overlay.get(), heights.get(), getWidth(), getLength(), 1); int index = 0; for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { int height = img.getRGB(x, z) & 0xFF; if (height == 255 || height > 0 && !white && ThreadLocalRandom.current() .nextInt(256) <= height) { - mutable.mutX(x); - mutable.mutY(height); - overlayArr[index] = pattern.apply(mutable).getOrdinalChar(); + filter.init(x, z, index); + pattern.apply(this, filter, filter); } } } @@ -1302,17 +1306,15 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr primitives.modifiedMain = true; main.record(() -> { - char[] mainArr = main.get(); + ArrayFilterBlock filter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1); int index = 0; for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { int height = img.getRGB(x, z) & 0xFF; if (height == 255 || height > 0 && !white && ThreadLocalRandom.current() .nextInt(256) <= height) { - mutable.mutX(x); - mutable.mutY(height); - mainArr[index] = pattern.apply(mutable).getOrdinalChar(); + filter.init(x, z, index); + pattern.apply(this, filter, filter); } } } @@ -1328,17 +1330,15 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr throw new IllegalArgumentException("Input image dimensions do not match the current height map!"); floor.record(() -> { - char[] floorArr = floor.get(); + ArrayFilterBlock filter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 1); int index = 0; for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { int height = img.getRGB(x, z) & 0xFF; if (height == 255 || height > 0 && !white && ThreadLocalRandom.current() .nextInt(256) <= height) { - mutable.mutX(x); - mutable.mutY(height); - floorArr[index] = pattern.apply(mutable).getOrdinalChar(); + filter.init(x, z, index); + pattern.apply(this, filter, filter); } } } @@ -1355,20 +1355,20 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr primitives.modifiedMain = true; main.record(() -> floor.record(() -> { - char[] floorArr = floor.get(); - char[] mainArr = main.get(); + ArrayFilterBlock filterFloor = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0); + ArrayFilterBlock filterMain = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1); + int index = 0; for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { int height = img.getRGB(x, z) & 0xFF; if (height == 255 || height > 0 && !white && ThreadLocalRandom.current() .nextInt(256) <= height) { - mutable.mutX(x); - mutable.mutY(height); - char combined = pattern.apply(mutable).getOrdinalChar(); - mainArr[index] = combined; - floorArr[index] = combined; + filterFloor.init(x, z, index); + filterMain.init(x, z, index); + + pattern.apply(this, filterFloor, filterFloor); + pattern.apply(this, filterMain, filterMain); } } } @@ -1380,19 +1380,20 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr if (pattern instanceof BlockStateHolder) { setOverlay(mask, ((BlockStateHolder) pattern).getOrdinalChar()); } else { - int index = 0; if (overlay == null) overlay = new DifferentialArray<>(new char[getArea()]); - for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); - for (int x = 0; x < getWidth(); x++, index++) { - int y = heights.getByte(index) & 0xFF; - mutable.mutX(x); - mutable.mutY(y); - if (mask.test(mutable)) { - overlay.setInt(index, pattern.apply(mutable).getOrdinalChar()); + overlay.record(() -> { + ArrayFilterBlock filter = new ArrayFilterBlock(this, overlay.get(), heights.get(), getWidth(), getLength(), 1); + int index = 0; + for (int z = 0; z < getLength(); z++) { + for (int x = 0; x < getWidth(); x++, index++) { + filter.init(x, z, index); + if (mask.test(this, filter)) { + pattern.apply(this, filter, filter); + } } } - } + }); + } } @@ -1400,18 +1401,18 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr if (pattern instanceof BlockStateHolder) { setFloor(mask, ((BlockStateHolder) pattern).getOrdinalChar()); } else { - int index = 0; - for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); - for (int x = 0; x < getWidth(); x++, index++) { - int y = heights.getByte(index) & 0xFF; - mutable.mutX(x); - mutable.mutY(y); - if (mask.test(mutable)) { - floor.setInt(index, pattern.apply(mutable).getOrdinalChar()); + floor.record(() -> { + ArrayFilterBlock filter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0); + int index = 0; + for (int z = 0; z < getLength(); z++) { + for (int x = 0; x < getWidth(); x++, index++) { + filter.init(x, z, index); + if (mask.test(this, filter)) { + pattern.apply(this, filter, filter); + } } } - } + }); } } @@ -1419,19 +1420,18 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr if (pattern instanceof BlockStateHolder) { setMain(mask, ((BlockStateHolder) pattern).getOrdinalChar()); } else { - primitives.modifiedMain = true; - int index = 0; - for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); - for (int x = 0; x < getWidth(); x++, index++) { - int y = heights.getByte(index) & 0xFF; - mutable.mutX(x); - mutable.mutY(y); - if (mask.test(mutable)) { - main.setInt(index, pattern.apply(mutable).getOrdinalChar()); + main.record(() -> { + ArrayFilterBlock filter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1); + primitives.modifiedMain = true; + int index = 0; + for (int z = 0; z < getLength(); z++) { + for (int x = 0; x < getWidth(); x++, index++) { + if (mask.test(this, filter)) { + pattern.apply(this, filter, filter); + } } } - } + }); } } @@ -1439,21 +1439,25 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr if (pattern instanceof BlockStateHolder) { setColumn(mask, ((BlockStateHolder) pattern).getOrdinalChar()); } else { - primitives.modifiedMain = true; - int index = 0; - for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); - for (int x = 0; x < getWidth(); x++, index++) { - int y = heights.getByte(index) & 0xFF; - mutable.mutX(x); - mutable.mutY(y); - if (mask.test(mutable)) { - int combined = pattern.apply(mutable).getOrdinalChar(); - floor.setInt(index, combined); - main.setInt(index, combined); + floor.record(() -> main.record(() -> { + ArrayFilterBlock floorFilter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0); + ArrayFilterBlock mainFilter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1); + primitives.modifiedMain = true; + int index = 0; + for (int z = 0; z < getLength(); z++) { + for (int x = 0; x < getWidth(); x++, index++) { + floorFilter.init(x, z, index); + mainFilter.init(x, z, index); + if (mask.test(this, mainFilter)) { + pattern.apply(this, mainFilter, mainFilter); + } + if (mask.test(this, floorFilter)) { + pattern.apply(this, floorFilter, floorFilter); + } } } - } + })); + } } @@ -1466,15 +1470,12 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr setFloor(((BlockStateHolder) value).getOrdinalChar()); } else { floor.record(() -> { - char[] floorArr = floor.get(); + ArrayFilterBlock filter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0); int index = 0; for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { - int y = heights.getByte(index) & 0xFF; - mutable.mutX(x); - mutable.mutY(y); - floorArr[index] = value.apply(mutable).getOrdinalChar(); + filter.init(x, z, index); + value.apply(this, filter, filter); } } }); @@ -1486,18 +1487,15 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr setColumn(((BlockStateHolder) value).getOrdinalChar()); } else { main.record(() -> floor.record(() -> { - char[] floorArr = floor.get(); - char[] mainArr = main.get(); + ArrayFilterBlock floorFilter = new ArrayFilterBlock(this, floor.get(), heights.get(), getWidth(), getLength(), 0); + ArrayFilterBlock mainFilter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1); int index = 0; for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { - int y = heights.getByte(index) & 0xFF; - mutable.mutX(x); - mutable.mutY(y); - char combined = value.apply(mutable).getOrdinalChar(); - mainArr[index] = combined; - floorArr[index] = combined; + floorFilter.init(x, z, index); + mainFilter.init(x, z, index); + value.apply(this, floorFilter, floorFilter); + value.apply(this, mainFilter, mainFilter); } } })); @@ -1509,15 +1507,12 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr setMain(((BlockStateHolder) value).getOrdinalChar()); } else { main.record(() -> { - char[] mainArr = main.get(); + ArrayFilterBlock filter = new ArrayFilterBlock(this, main.get(), heights.get(), getWidth(), getLength(), -1); int index = 0; for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { - int y = heights.getByte(index) & 0xFF; - mutable.mutX(x); - mutable.mutY(y); - mainArr[index] = value.apply(mutable).getOrdinalChar(); + filter.init(x, z, index); + value.apply(this, filter, filter); } } }); @@ -1530,15 +1525,12 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr setOverlay(((BlockStateHolder) value).getOrdinalChar()); } else { overlay.record(() -> { - char[] overlayArr = overlay.get(); + ArrayFilterBlock filter = new ArrayFilterBlock(this, overlay.get(), heights.get(), getWidth(), getLength(), 1); int index = 0; for (int z = 0; z < getLength(); z++) { - mutable.mutZ(z); for (int x = 0; x < getWidth(); x++, index++) { - int y = heights.getByte(index) & 0xFF; - mutable.mutX(x); - mutable.mutY(y); - overlayArr[index] = value.apply(mutable).getOrdinalChar(); + filter.init(x, z, index); + value.apply(this, filter, filter); } } }); @@ -1758,7 +1750,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr int y = heights.getByte(index) & 0xFF; mutable.mutX(x); mutable.mutY(y); - if (mask.test(mutable)) { + if (mask.test(this, mutable)) { overlay.setInt(index, combined); } } @@ -1773,7 +1765,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr int y = heights.getByte(index) & 0xFF; mutable.mutX(x); mutable.mutY(y); - if (mask.test(mutable)) { + if (mask.test(this, mutable)) { floor.setInt(index, combined); } } @@ -1789,7 +1781,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr int y = heights.getByte(index) & 0xFF; mutable.mutX(x); mutable.mutY(y); - if (mask.test(mutable)) { + if (mask.test(this, mutable)) { main.setInt(index, combined); } } @@ -1805,7 +1797,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr int y = heights.getByte(index) & 0xFF; mutable.mutX(x); mutable.mutY(y); - if (mask.test(mutable)) { + if (mask.test(this, mutable)) { floor.setInt(index, combined); main.setInt(index, combined); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LinearClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LinearClipboard.java index 380ea5301..47e70064d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LinearClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/LinearClipboard.java @@ -4,6 +4,7 @@ import com.boydti.fawe.beta.implementation.filter.block.AbstractFilterBlock; import com.boydti.fawe.jnbt.streamer.IntValueReader; import com.google.common.collect.ForwardingIterator; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.visitor.Order; import com.sk89q.worldedit.math.BlockVector3; @@ -111,5 +112,10 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa public BlockVector3 getPosition() { return position; } + + @Override + public Extent getExtent() { + return LinearClipboard.this; + } } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialArray.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialArray.java index 57482af1c..47ea5c752 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialArray.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/DifferentialArray.java @@ -294,14 +294,14 @@ public final class DifferentialArray implements DifferentialCollection { dataInts[index] = value; } -// public void setChar(int index, char value) { -// changed = true; -// try { -// changesChars[index] += dataChars[index] - value; -// } catch (NullPointerException ignore) { -// changes = (T) (changesChars = new char[dataChars.length]); -// changesChars[index] += dataChars[index] - value; -// } -// dataChars[index] = value; -// } + public void setChar(int index, char value) { + changed = true; + try { + changesChars[index] += dataChars[index] - value; + } catch (NullPointerException ignore) { + changes = (T) (changesChars = new char[dataChars.length]); + changesChars[index] += dataChars[index] - value; + } + dataChars[index] = value; + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java index 8f64589c6..bd953778c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java @@ -11,8 +11,20 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; public class SourceMaskExtent extends TemporalExtent { private Mask mask; + private Extent get; private MutableBlockVector3 mutable = new MutableBlockVector3(); + public SourceMaskExtent(Extent extent, Mask mask) { + this(extent, extent, mask); + } + + public SourceMaskExtent(Extent get, Extent set, Mask mask) { + super(set); + checkNotNull(get); + checkNotNull(mask); + this.get = get; + this.mask = mask; + } /** * Get the mask. @@ -33,16 +45,10 @@ public class SourceMaskExtent extends TemporalExtent { this.mask = mask; } - public SourceMaskExtent(Extent extent, Mask mask) { - super(extent); - checkNotNull(mask); - this.mask = mask; - } - @Override public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { set(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); - return mask.test(location) && super.setBlock(location, block); + return mask.test(get, location) && super.setBlock(location, block); } @Override @@ -51,6 +57,6 @@ public class SourceMaskExtent extends TemporalExtent { mutable.mutX(x); mutable.mutY(y); mutable.mutZ(z); - return mask.test(mutable) && super.setBlock(x, y, z, block); + return mask.test(get, mutable) && super.setBlock(x, y, z, block); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java index fd6e472fe..d8856a751 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.function.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask2D; @@ -24,9 +25,20 @@ public class AbstractDelegateMask extends AbstractMask { return mask.test(vector); } + @Override + public boolean test(Extent extent, BlockVector3 pos) { + return mask.test(extent, pos); + } + @Nullable @Override public Mask2D toMask2D() { return mask.toMask2D(); } + + @Override + public Mask withExtent(Extent extent) { + mask.withExtent(extent); + return this; + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java index e12205db3..c9603a5d6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; @@ -11,7 +12,7 @@ import com.sk89q.worldedit.math.MutableBlockVector3; public class AdjacentAnyMask extends AbstractMask implements ResettableMask { private final CachedMask mask; - private transient MutableBlockVector3 mutable = new MutableBlockVector3(); + private final MutableBlockVector3 mutable; public AdjacentAnyMask(Mask mask) { this.mask = CachedMask.cache(mask); @@ -20,7 +21,7 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { @Override public void reset() { - mutable = new MutableBlockVector3(); + mutable.setComponents(0, 0, 0); } public CachedMask getParentMask() { @@ -28,53 +29,28 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { } @Override - public boolean test(BlockVector3 v) { - int x = v.getBlockX(); - int y = v.getBlockY(); - int z = v.getBlockZ(); - if (mask.test(x + 1, y, z)) { - return true; - } - if (mask.test(x - 1, y, z)) { - return true; - } - if (mask.test(x, y, z + 1)) { - return true; - } - if (mask.test(x, y, z - 1)) { - return true; - } - if (y < 256 && mask.test(x, y + 1, z)) { - return true; - } - if (y > 0 && mask.test(x, y - 1, z)) { - return true; - } - return false; + public boolean test(Extent extent, BlockVector3 v) { + return direction(extent, v) != null; } - public BlockVector3 direction(BlockVector3 v) { + public BlockVector3 direction(Extent extent, BlockVector3 v) { int x = v.getBlockX(); int y = v.getBlockY(); int z = v.getBlockZ(); - if (mask.test(x + 1, y, z)) { - mutable.setComponents(1, 0, 0); - }else - if (mask.test(x - 1, y, z)) { - mutable.setComponents(-1, 0, 0); - }else - if (mask.test(x, y, z + 1)) { - mutable.setComponents(0, 0, 1); - }else - if (mask.test(x, y, z - 1)) { - mutable.setComponents(0, 0, -1); - }else - if (y < 256 && mask.test(x, y + 1, z)) { - mutable.setComponents(0, 1, 0); - }else - if (y > 0 && mask.test(x, y - 1, z)) { - mutable.setComponents(0, -1, 0); + if (mask.test(extent, x + 1, y, z)) { + return mutable.setComponents(1, 0, 0); + }else if (mask.test(extent, x - 1, y, z)) { + return mutable.setComponents(-1, 0, 0); + }else if (mask.test(extent, x, y, z + 1)) { + return mutable.setComponents(0, 0, 1); + }else if (mask.test(extent, x, y, z - 1)) { + return mutable.setComponents(0, 0, -1); + }else if (y < 256 && mask.test(extent, x, y + 1, z)) { + return mutable.setComponents(0, 1, 0); + }else if (y > 0 && mask.test(extent, x, y - 1, z)) { + return mutable.setComponents(0, -1, 0); + } else { + return null; } - return (mutable.getX() == 0 && mutable.getY() == 0 && mutable.getZ() == 0) ? null : mutable; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java index 8c363d1a2..c3a21bb38 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; @@ -18,41 +19,41 @@ public class AdjacentMask extends AbstractMask { } @Override - public boolean test(BlockVector3 bv) { + public boolean test(Extent extent, BlockVector3 bv) { v.setComponents(bv); int count = 0; double x = bv.getX(); double y = bv.getY(); double z = bv.getZ(); v.mutX(x + 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutX(x); return true; } v.mutX(x - 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutX(x); return true; } v.mutX(x); v.mutY(y + 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutY(y); return true; } v.mutY(y - 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutY(y); return true; } v.mutY(y); v.mutZ(z + 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutZ(z); return true; } v.mutZ(z - 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutZ(z); return true; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java index ad07972be..5607c2eda 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java @@ -58,8 +58,8 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { protected transient boolean foundY; protected transient boolean lastValue; - public int getHeight(int x, int y, int z) { -// return getExtent().getNearestSurfaceTerrainBlock(x, z, y, 0, maxY); + public int getHeight(Extent extent, int x, int y, int z) { +// return extent.getNearestSurfaceTerrainBlock(x, z, y, 0, maxY); try { int rx = x - cacheBotX + 16; int rz = z - cacheBotZ + 16; @@ -80,7 +80,7 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { } int result = cacheHeights[index] & 0xFF; if (y > result) { - cacheHeights[index] = (byte) (result = lastY = getExtent().getNearestSurfaceTerrainBlock(x, z, lastY, 0, maxY)); + cacheHeights[index] = (byte) (result = lastY = extent.getNearestSurfaceTerrainBlock(x, z, lastY, 0, maxY)); } return result; } catch (Throwable e) { @@ -89,72 +89,72 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { } } - protected boolean testSlope(int x, int y, int z) { + protected boolean testSlope(Extent extent, int x, int y, int z) { double slope; boolean aboveMin; lastY = y; - slope = Math.abs(getHeight(x + distance, y, z) - getHeight(x -distance, y, z)) * ADJACENT_MOD; + slope = Math.abs(getHeight(extent, x + distance, y, z) - getHeight(extent, x -distance, y, z)) * ADJACENT_MOD; if (checkFirst) { if (slope >= min) { return lastValue = true; } - slope = Math.max(slope, Math.abs(getHeight(x, y, z + distance) - getHeight(x, y, z - distance)) * ADJACENT_MOD); - slope = Math.max(slope, Math.abs(getHeight(x + distance, y, z + distance) - getHeight(x - distance, y, z - distance)) * DIAGONAL_MOD); - slope = Math.max(slope, Math.abs(getHeight(x - distance, y, z + distance) - getHeight(x + distance, y, z - distance)) * DIAGONAL_MOD); + slope = Math.max(slope, Math.abs(getHeight(extent, x, y, z + distance) - getHeight(extent, x, y, z - distance)) * ADJACENT_MOD); + slope = Math.max(slope, Math.abs(getHeight(extent, x + distance, y, z + distance) - getHeight(extent, x - distance, y, z - distance)) * DIAGONAL_MOD); + slope = Math.max(slope, Math.abs(getHeight(extent, x - distance, y, z + distance) - getHeight(extent, x + distance, y, z - distance)) * DIAGONAL_MOD); return lastValue = (slope >= min); } else { - slope = Math.max(slope, Math.abs(getHeight(x, y, z + distance) - getHeight(x, y, z - distance)) * ADJACENT_MOD); - slope = Math.max(slope, Math.abs(getHeight(x + distance, y, z + distance) - getHeight(x - distance, y, z - distance)) * DIAGONAL_MOD); - slope = Math.max(slope, Math.abs(getHeight(x - distance, y, z + distance) - getHeight(x + distance, y, z - distance)) * DIAGONAL_MOD); + slope = Math.max(slope, Math.abs(getHeight(extent, x, y, z + distance) - getHeight(extent, x, y, z - distance)) * ADJACENT_MOD); + slope = Math.max(slope, Math.abs(getHeight(extent, x + distance, y, z + distance) - getHeight(extent, x - distance, y, z - distance)) * DIAGONAL_MOD); + slope = Math.max(slope, Math.abs(getHeight(extent, x - distance, y, z + distance) - getHeight(extent, x + distance, y, z - distance)) * DIAGONAL_MOD); return lastValue = (slope >= min && slope <= max); } } - public boolean adjacentAir(BlockVector3 v) { + public boolean adjacentAir(Extent extent, BlockVector3 v) { int x = v.getBlockX(); int y = v.getBlockY(); int z = v.getBlockZ(); - if (!mask.test(x + 1, y, z)) { + if (!mask.test(extent, x + 1, y, z)) { return true; } - if (!mask.test(x - 1, y, z)) { + if (!mask.test(extent, x - 1, y, z)) { return true; } - if (!mask.test(x, y, z + 1)) { + if (!mask.test(extent, x, y, z + 1)) { return true; } - if (!mask.test(x, y, z - 1)) { + if (!mask.test(extent, x, y, z - 1)) { return true; } - if (y < 255 && !mask.test(x, y + 1, z)) { + if (y < 255 && !mask.test(extent, x, y + 1, z)) { return true; } - if (y > 0 && !mask.test(x, y - 1, z)) { + if (y > 0 && !mask.test(extent, x, y - 1, z)) { return true; } return false; } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { int x = vector.getBlockX(); int y = vector.getBlockY(); int z = vector.getBlockZ(); if ((lastX == (lastX = x) & lastZ == (lastZ = z))) { - int height = getHeight(x, y, z); + int height = getHeight(extent, x, y, z); if (y <= height) return overlay ? (lastValue && y == height) : lastValue; } - if (!mask.test(x, y, z)) { + if (!mask.test(extent, x, y, z)) { return false; } if (overlay) { - if (y < 255 && !mask.test(x, y + 1, z)) return lastValue = false; - } else if (!adjacentAir(vector)) { + if (y < 255 && !mask.test(extent, x, y + 1, z)) return lastValue = false; + } else if (!adjacentAir(extent, vector)) { return false; } - return testSlope(x, y, z); + return testSlope(extent, x, y, z); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BiomeMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BiomeMask.java index 0a1bd2d2b..480473d72 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BiomeMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BiomeMask.java @@ -22,8 +22,8 @@ public class BiomeMask extends AbstractExtentMask implements ResettableMask { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { BlockVector2 pos = mutable.setComponents(vector.getBlockX(), vector.getBlockZ()); - return getExtent().getBiome(pos).getId() == biome.getId(); + return extent.getBiome(pos).getId() == biome.getId(); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java index 618b5256b..e956df9ff 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java @@ -16,8 +16,7 @@ public class BlockLightMask extends AbstractExtentMask { } @Override - public boolean test(BlockVector3 vector) { - Extent extent = getExtent(); + public boolean test(Extent extent, BlockVector3 vector) { if (extent instanceof LightingExtent) { int light = ((LightingExtent) extent).getBlockLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return light >= min && light <= max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java index b8e274d1a..96692231b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java @@ -16,8 +16,7 @@ public class BrightnessMask extends AbstractExtentMask { } @Override - public boolean test(BlockVector3 vector) { - Extent extent = getExtent(); + public boolean test(Extent extent, BlockVector3 vector) { if (extent instanceof LightingExtent) { int light = ((LightingExtent) extent).getBrightness(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return light >= min && light <= max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java index 9c2160604..4afe9ca07 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java @@ -2,6 +2,7 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.collection.LocalBlockVectorSet; import com.boydti.fawe.object.function.mask.AbstractDelegateMask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableBlockVector3; @@ -41,21 +42,21 @@ public class CachedMask extends AbstractDelegateMask implements ResettableMask { } @Override - public boolean test(BlockVector3 vector) { - return test(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + public boolean test(Extent extent, BlockVector3 vector) { + return test(extent, vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); } - public boolean test(int x, int y, int z) { + public boolean test(Extent extent, int x, int y, int z) { try { boolean check = cache_checked.add(x, y, z); if (!check) { return cache_results.contains(x, y, z); } - boolean result = getMask().test(mutable.setComponents(x, y, z)); + boolean result = getMask().test(extent, mutable.setComponents(x, y, z)); if (result) cache_results.add(x, y, z); return result; } catch (UnsupportedOperationException ignore) { - boolean result = getMask().test(mutable.setComponents(x, y, z)); + boolean result = getMask().test(extent, mutable.setComponents(x, y, z)); if (y < 0 || y > 255) return result; resetCache(); cache_checked.setOffset(x, z); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/DataMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/DataMask.java index 2d1e3ae9e..353c87fb0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/DataMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/DataMask.java @@ -13,8 +13,7 @@ public class DataMask extends AbstractExtentMask implements ResettableMask { private transient int data = -1; @Override - public boolean test(BlockVector3 vector) { - Extent extent = getExtent(); + public boolean test(Extent extent, BlockVector3 vector) { if (data != -1) { return extent.getBlock(vector).getInternalPropertiesId() == data; } else { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ExtremaMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ExtremaMask.java index a60af2396..bd544326a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ExtremaMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ExtremaMask.java @@ -8,28 +8,28 @@ public class ExtremaMask extends AngleMask { } @Override - protected boolean testSlope(int x, int y, int z) { + protected boolean testSlope(Extent extent, int x, int y, int z) { double slope, tmp; boolean aboveMin; lastY = y; - int base = getHeight(x, y, z); + int base = getHeight(extent, x, y, z); - slope = get(base, x, y, z, 1, 0, distance) * ADJACENT_MOD; + slope = getHeight(extent, base, x, y, z, 1, 0, distance) * ADJACENT_MOD; - tmp = get(base, x, y, z, 0, 1, distance) * ADJACENT_MOD; + tmp = getHeight(extent, base, x, y, z, 0, 1, distance) * ADJACENT_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; - tmp = get(base, x, y, z, 1, 1, distance) * DIAGONAL_MOD; + tmp = getHeight(extent, base, x, y, z, 1, 1, distance) * DIAGONAL_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; - tmp = get(base, x, y, z, 1, -1, distance) * DIAGONAL_MOD; + tmp = getHeight(extent, base, x, y, z, 1, -1, distance) * DIAGONAL_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; return lastValue = (slope > min && slope < max); } - private int get(int base, int x, int y, int z, int OX, int OZ, int iterations) { + private int getHeight(Extent extent, int base, int x, int y, int z, int OX, int OZ, int iterations) { int sign = 0; int lastHeight1 = base; int lastHeight2 = base; @@ -40,8 +40,8 @@ public class ExtremaMask extends AngleMask { int z1 = z + coz; int x2 = x - cox; int z2 = z - coz; - int height1 = getHeight(x1, y, z1); - int height2 = getHeight(x2, y, z2); + int height1 = getHeight(extent, x1, y, z1); + int height2 = getHeight(extent, x2, y, z2); int diff1 = height1 - lastHeight1; int diff2 = height2 - lastHeight2; int sign1 = Integer.signum(diff1); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java index 2782dc5a4..d09750238 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java @@ -12,8 +12,7 @@ public class IdDataMask extends AbstractExtentMask implements ResettableMask { } @Override - public boolean test(BlockVector3 vector) { - Extent extent = getExtent(); + public boolean test(Extent extent, BlockVector3 vector) { if (combined != -1) { return extent.getBlock(vector).getInternalId() == combined; } else { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java index c235e93c5..5a55ad703 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java @@ -13,8 +13,7 @@ public class IdMask extends AbstractExtentMask implements ResettableMask { } @Override - public boolean test(BlockVector3 vector) { - Extent extent = getExtent(); + public boolean test(Extent extent, BlockVector3 vector) { if (id != -1) { return extent.getBlock(vector).getInternalBlockTypeId() == id; } else { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java index c6debf87d..5ab2ecfcb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java @@ -16,9 +16,9 @@ public class LightMask extends AbstractExtentMask { } @Override - public boolean test(BlockVector3 vector) { - if (getExtent() instanceof LightingExtent) { - int light = ((LightingExtent) getExtent()).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + public boolean test(Extent extent, BlockVector3 vector) { + if (extent instanceof LightingExtent) { + int light = ((LightingExtent) extent).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return light >= min && light <= max; } return false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java index 88b94072e..f7b87aac7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java @@ -21,7 +21,7 @@ public class MaskedTargetBlock extends TargetBlock { Location lastBlock = null; while (getNextBlock() != null) { Location current = getCurrentBlock(); - if (!mask.test(current.toBlockPoint())) { + if (!mask.test(world, current.toBlockPoint())) { if (searchForLastBlock) { lastBlock = current; if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java index 0a5dd7720..76b53938f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java @@ -16,9 +16,9 @@ public class OpacityMask extends AbstractExtentMask { } @Override - public boolean test(BlockVector3 vector) { - if (getExtent() instanceof LightingExtent) { - int light = ((LightingExtent) getExtent()).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); + public boolean test(Extent extent, BlockVector3 vector) { + if (extent instanceof LightingExtent) { + int light = ((LightingExtent) extent).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return light >= min && light <= max; } return false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java index 07227a34c..c2d1cbc6e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; @@ -12,7 +13,7 @@ public class PlaneMask extends AbstractMask implements ResettableMask { private transient int originX = Integer.MAX_VALUE, originY = Integer.MAX_VALUE, originZ = Integer.MAX_VALUE; @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { switch (mode) { case -1: originX = vector.getBlockX(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java index de4c437fc..826040550 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ROCAngleMask.java @@ -9,23 +9,23 @@ public class ROCAngleMask extends AngleMask { } @Override - protected boolean testSlope(int x, int y, int z) { + protected boolean testSlope(Extent extent, int x, int y, int z) { double tmp; lastY = y; - int base = getHeight(x, y, z); + int base = getHeight(extent, x, y, z); double slope = - (getHeight(x + distance, y, z) - base - (base - getHeight(x - distance, y, z))) + (getHeight(extent, x + distance, y, z) - base - (base - getHeight(extent, x - distance, y, z))) * ADJACENT_MOD; - tmp = (getHeight(x, y, z + distance) - base - (base - getHeight(x, y, z - distance))) * ADJACENT_MOD; + tmp = (getHeight(extent, x, y, z + distance) - base - (base - getHeight(extent, x, y, z - distance))) * ADJACENT_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; - tmp = (getHeight(x + distance, y, z + distance) - base - (base - getHeight(x - distance, y, + tmp = (getHeight(extent, x + distance, y, z + distance) - base - (base - getHeight(extent, x - distance, y, z - distance))) * DIAGONAL_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; - tmp = (getHeight(x - distance, y, z + distance) - base - (base - getHeight(x + distance, y, + tmp = (getHeight(extent, x - distance, y, z + distance) - base - (base - getHeight(extent, x + distance, y, z - distance))) * DIAGONAL_MOD; if (Math.abs(tmp) > Math.abs(slope)) slope = tmp; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java index fa3f94675..e5a6b2b42 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; @@ -19,7 +20,7 @@ public class RadiusMask extends AbstractMask implements ResettableMask { } @Override - public boolean test(BlockVector3 to) { + public boolean test(Extent extent, BlockVector3 to) { if (pos == null) { pos = to.toImmutable(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java index 05de613cc..fa0992a30 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; import java.util.SplittableRandom; @@ -14,7 +15,7 @@ public class RandomMask extends AbstractMask implements ResettableMask { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { return random.nextInt() <= threshold; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SimplexMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SimplexMask.java index 9358552ca..23658b595 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SimplexMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SimplexMask.java @@ -1,6 +1,7 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.random.SimplexNoise; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; @@ -14,7 +15,7 @@ public class SimplexMask extends AbstractMask { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { double value = SimplexNoise.noise(vector.getBlockX() * scale, vector.getBlockY() * scale, vector.getBlockZ() * scale); return value >= min && value <= max; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java index 9b49b58e4..bc4bf7ae4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java @@ -17,9 +17,9 @@ public class SkyLightMask extends AbstractExtentMask { } @Override - public boolean test(BlockVector3 vector) { - if (getExtent() instanceof LightingExtent) { - int light = ((LightingExtent) getExtent()) + public boolean test(Extent extent, BlockVector3 vector) { + if (extent instanceof LightingExtent) { + int light = ((LightingExtent) extent) .getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return light >= min && light <= max; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java index a560f7dc1..8de7c3d5a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java @@ -20,7 +20,7 @@ public class SolidPlaneMask extends SolidBlockMask implements ResettableMask { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { switch (mode) { case -1: if (!super.test(vector)) { @@ -30,7 +30,6 @@ public class SolidPlaneMask extends SolidBlockMask implements ResettableMask { originY = vector.getBlockY(); originZ = vector.getBlockZ(); mode = 0; - Extent extent = getExtent(); if (!extent.getBlock(mutable.setComponents(originX - 1, originY, originZ)).getMaterial().isAir() && !extent.getBlock(mutable.setComponents(originX + 1, originY, originZ)).getMaterial().isAir()) { mode &= 1; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java index dafc52a9b..266f5e587 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java @@ -19,7 +19,7 @@ public class SurfaceMask extends AdjacentAnyMask { } @Override - public boolean test(BlockVector3 v) { - return !getParentMask().test(v.getBlockX(), v.getBlockY(), v.getBlockZ()) && super.test(v); + public boolean test(Extent extent, BlockVector3 v) { + return !getParentMask().test(extent, v.getBlockX(), v.getBlockY(), v.getBlockZ()) && super.test(extent, v); } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/WallMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/WallMask.java index 83b2d110d..ca57027c9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/WallMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/WallMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; @@ -18,30 +19,30 @@ public class WallMask extends AbstractMask { } @Override - public boolean test(BlockVector3 bv) { + public boolean test(Extent extent, BlockVector3 bv) { v.setComponents(bv); int count = 0; double x = v.getX(); double y = v.getY(); double z = v.getZ(); v.mutX(x + 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutX(x); return true; } v.mutX(x - 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutX(x); return true; } v.mutX(x); v.mutZ(z + 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutZ(z); return true; } v.mutZ(z - 1); - if (mask.test(v) && ++count == min && max >= 8) { + if (mask.test(extent, v) && ++count == min && max >= 8) { v.mutZ(z); return true; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java index ec61666f3..fb5273f78 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; @@ -11,7 +12,7 @@ public class XAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { if (layer == -1) { layer = vector.getBlockX(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java index 239adec59..d698cd421 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; @@ -11,7 +12,7 @@ public class YAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { if (layer == -1) { layer = vector.getBlockY(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java index 28d315953..0c4aaddd9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java @@ -1,5 +1,6 @@ package com.boydti.fawe.object.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.math.BlockVector3; @@ -11,7 +12,7 @@ public class ZAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { if (layer == -1) { layer = vector.getBlockZ(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java index 6eadf7ffd..0ff4e1761 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java @@ -20,7 +20,6 @@ public class MaskedPattern extends AbstractPattern { this.secondary = secondary; } - @Override public BaseBlock apply(BlockVector3 position) { if (mask.test(position)) { @@ -31,7 +30,7 @@ public class MaskedPattern extends AbstractPattern { @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - if (mask.test(get)) { + if (mask.test(extent, get)) { return primary.apply(extent, get, set); } return secondary.apply(extent, get, set); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java index 6b97b8562..cf1a7122f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java @@ -5,6 +5,8 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.function.mask.AbstractExtentMask; +import com.sk89q.worldedit.function.mask.DelegateExtentMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; @@ -42,7 +44,7 @@ public class FuzzyRegion extends AbstractRegion { } public void select(int x, int y, int z) { - RecursiveVisitor search = new RecursiveVisitor(mask, new RegionFunction() { + RecursiveVisitor search = new RecursiveVisitor(mask.withExtent(extent), new RegionFunction() { @Override public boolean apply(BlockVector3 p) throws WorldEditException { setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java index d8cfd9582..41d193a3a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/TextureUtil.java @@ -375,7 +375,7 @@ public class TextureUtil implements TextureHolder { for (int typeId : tu.getValidBlockIds()) { BlockType block = BlockTypes.get(typeId); extent.init(0, 0, 0, block.getDefaultState().toBaseBlock()); - if (mask.test(extent)) { + if (mask.test(extent, extent)) { blocks.add(block); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index bd504fab7..6b320419f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -800,7 +800,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { @Override public int getHighestTerrainBlock(int x, int z, int minY, int maxY, Mask filter) { for (int y = maxY; y >= minY; --y) { - if (filter.test(mutablebv.setComponents(x, y, z))) { + if (filter.test(getExtent(), mutablebv.setComponents(x, y, z))) { return y; } } @@ -1079,8 +1079,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { if (direction.equals(BlockVector3.at(0, -1, 0))) { return fillXZ(origin, pattern, radius, depth, false); } - final Mask mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this))); - + Mask mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this))).withExtent(getExtent()); // Want to replace blocks final BlockReplace replace = new BlockReplace(EditSession.this, pattern); @@ -1127,13 +1126,12 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { checkArgument(radius >= 0, "radius >= 0"); checkArgument(depth >= 1, "depth >= 1"); - MaskIntersection mask = new MaskIntersection( + Mask mask = new MaskIntersection( new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), new BoundedHeightMask( Math.max(origin.getBlockY() - depth + 1, getMinimumPoint().getBlockY()), Math.min(getMaxY(), origin.getBlockY())), - Masks.negate(new ExistingBlockMask(this))); - + Masks.negate(new ExistingBlockMask(this))).withExtent(getExtent()); // Want to replace blocks BlockReplace replace = new BlockReplace(this, pattern); @@ -1341,15 +1339,18 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { if (region instanceof CuboidRegion) { return makeCuboidWalls(region, pattern); } else { - replaceBlocks(region, position -> { - int x = position.getBlockX(); - int y = position.getBlockY(); - int z = position.getBlockZ(); - if (!region.contains(x, z + 1) || !region.contains(x, z - 1) || !region.contains(x + 1, z) || !region.contains(x - 1, z)) { - return true; - } + replaceBlocks(region, new Mask() { + @Override + public boolean test(Extent extent, BlockVector3 position) { + int x = position.getBlockX(); + int y = position.getBlockY(); + int z = position.getBlockZ(); + if (!region.contains(x, z + 1) || !region.contains(x, z - 1) || !region.contains(x + 1, z) || !region.contains(x - 1, z)) { + return true; + } - return false; + return false; + } }, pattern); } return changes; @@ -1571,10 +1572,10 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { // } else { // } liquidMask = new BlockTypeMask(this, BlockTypes.LAVA, BlockTypes.WATER); - MaskIntersection mask = new MaskIntersection( + Mask mask = new MaskIntersection( new BoundedHeightMask(0, getWorld().getMaxY()), new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), - liquidMask); + liquidMask).withExtent(getExtent()); BlockReplace replace; if (waterlogged) { replace = new BlockReplace(this, new WaterloggedRemover(this)); @@ -1585,7 +1586,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { // Around the origin in a 3x3 block for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) { - if (mask.test(position)) { + if (mask.test(getExtent(), position)) { visitor.visit(position); } } @@ -1619,14 +1620,13 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { new BoundedHeightMask(0, Math.min(origin.getBlockY(), getWorld().getMaxY())), new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), blockMask - ); - + ).withExtent(getExtent()); BlockReplace replace = new BlockReplace(this, fluid.getDefaultState()); NonRisingVisitor visitor = new NonRisingVisitor(mask, replace); // Around the origin in a 3x3 block for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) { - if (liquidMask.test(position)) { + if (liquidMask.test(getExtent(), position)) { visitor.visit(position); } } @@ -2712,7 +2712,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable { while (iter.hasNext()) { final BlockVector3 current = iter.next(); iter.remove(); - if (mask.test(current)) { + if (mask.test(getExtent(), current)) { continue; } if (!outside.add(current)) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java index 418753116..5b7dc6b59 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java @@ -206,7 +206,7 @@ public interface Extent extends InputExtent, OutputExtent { maxY = Math.min(maxY, Math.max(0, maxY)); minY = Math.max(0, minY); for (int y = maxY; y >= minY; --y) { - if (filter.test(MutableBlockVector3.get(x, y, z))) { + if (filter.test(this, MutableBlockVector3.get(x, y, z))) { return y; } } @@ -276,22 +276,22 @@ public interface Extent extends InputExtent, OutputExtent { int clearanceAbove = maxY - y; int clearanceBelow = y - minY; int clearance = Math.min(clearanceAbove, clearanceBelow); - boolean state = !mask.test(MutableBlockVector3.get(x, y, z)); + boolean state = !mask.test(this, MutableBlockVector3.get(x, y, z)); int offset = state ? 0 : 1; for (int d = 0; d <= clearance; d++) { int y1 = y + d; - if (mask.test(MutableBlockVector3.get(x, y1, z)) != state) return y1 - offset; + if (mask.test(this, MutableBlockVector3.get(x, y1, z)) != state) return y1 - offset; int y2 = y - d; - if (mask.test(MutableBlockVector3.get(x, y2, z)) != state) return y2 + offset; + if (mask.test(this, MutableBlockVector3.get(x, y2, z)) != state) return y2 + offset; } if (clearanceAbove != clearanceBelow) { if (clearanceAbove < clearanceBelow) { for (int layer = y - clearance - 1; layer >= minY; layer--) { - if (mask.test(MutableBlockVector3.get(x, layer, z)) != state) return layer + offset; + if (mask.test(this, MutableBlockVector3.get(x, layer, z)) != state) return layer + offset; } } else { for (int layer = y + clearance + 1; layer <= maxY; layer++) { - if (mask.test(MutableBlockVector3.get(x, layer, z)) != state) return layer - offset; + if (mask.test(this, MutableBlockVector3.get(x, layer, z)) != state) return layer - offset; } } } @@ -508,7 +508,7 @@ public interface Extent extends InputExtent, OutputExtent { * @return the number of blocks that matched the mask */ default int countBlocks(Region region, Mask searchMask) { - RegionVisitor visitor = new RegionVisitor(region, searchMask::test); + RegionVisitor visitor = new RegionVisitor(region, position -> searchMask.test(this, position)); Operations.completeBlindly(visitor); return visitor.getAffected(); } @@ -606,7 +606,7 @@ public interface Extent extends InputExtent, OutputExtent { checkNotNull(pattern); BlockReplace replace = new BlockReplace(this, pattern); - RegionMaskingFilter filter = new RegionMaskingFilter(mask, replace); + RegionMaskingFilter filter = new RegionMaskingFilter(this, mask, replace); RegionVisitor visitor = new RegionVisitor(region, filter); Operations.completeLegacy(visitor); return visitor.getAffected(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java index 691ca6eee..7aea7c97a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java @@ -86,17 +86,17 @@ public class MaskingExtent extends AbstractDelegateExtent implements IBatchProce @Override public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { - return mask.test(location) && super.setBlock(location, block); + return mask.test(getExtent(), location) && super.setBlock(location, block); } @Override public boolean setBiome(BlockVector2 position, BiomeType biome) { - return mask.test(position.toBlockVector3()) && super.setBiome(position, biome); + return mask.test(getExtent(), position.toBlockVector3()) && super.setBiome(position, biome); } @Override public boolean setBiome(int x, int y, int z, BiomeType biome) { - return mask.test(BlockVector3.at(x, y, z)) && super.setBiome(x, y, z, biome); + return mask.test(getExtent(), BlockVector3.at(x, y, z)) && super.setBiome(x, y, z, biome); } @Override @@ -108,7 +108,7 @@ public class MaskingExtent extends AbstractDelegateExtent implements IBatchProce @Override public void applyBlock(FilterBlock block) { int ordinal = block.getOrdinal(); - if (ordinal != 0 && !mask.test(block)) { + if (ordinal != 0 && !mask.test(getExtent(), block)) { block.setOrdinal(0); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java index f1289383d..c2bc8f7a7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java @@ -45,6 +45,7 @@ import javax.annotation.Nullable; * pass on any changes. */ public class NullExtent implements Extent { + public static final NullExtent INSTANCE = new NullExtent(); @Override public BlockVector3 getMinimumPoint() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ExtentBuffer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ExtentBuffer.java index 08abcc2cb..26e984138 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ExtentBuffer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ExtentBuffer.java @@ -67,7 +67,7 @@ public class ExtentBuffer extends AbstractBufferingExtent { @Override protected Optional getBufferedBlock(BlockVector3 position) { - if (mask.test(position)) { + if (mask.test(getExtent(), position)) { return Optional.of(buffer.computeIfAbsent(position, (pos -> getExtent().getFullBlock(pos)))); } return Optional.empty(); @@ -75,7 +75,7 @@ public class ExtentBuffer extends AbstractBufferingExtent { @Override public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { - if (mask.test(location)) { + if (mask.test(getExtent(), location)) { buffer.put(location, block.toBaseBlock()); return true; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java index f060bf90e..0c3aa726e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java @@ -106,7 +106,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat max = max.getMaximum(location); } - if (mask.test(location)) { + if (mask.test(getExtent(), location)) { buffer.put(location, block.toBaseBlock()); return true; } else { @@ -130,7 +130,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat max2d = max2d.getMaximum(position); } - if (biomeMask.test(position)) { + if (biomeMask.test(getExtent(), position)) { biomeBuffer.put(position, biome); return true; } else { @@ -154,7 +154,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat max2d = max2d.getMaximum(BlockVector2.at(x,z)); } - if (biomeMask.test(BlockVector2.at(x,z))) { + if (biomeMask.test(getExtent(), BlockVector2.at(x,z))) { biomeBuffer.put(BlockVector2.at(x,z), biome); return true; } else { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionMaskingFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionMaskingFilter.java index 961a5721d..02b3f42d0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionMaskingFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionMaskingFilter.java @@ -54,4 +54,4 @@ public class FlatRegionMaskingFilter implements FlatRegionFunction { return mask.test(position) && function.apply(position); } -} +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskTestFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskTestFunction.java index e633a0e0a..1214497b7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskTestFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskTestFunction.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function; import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; @@ -51,7 +52,7 @@ public class RegionMaskTestFunction implements RegionFunction { @Override public boolean apply(BlockVector3 position) throws WorldEditException { - if (mask.test(position)) { + if (mask.test(NullExtent.INSTANCE, position)) { return pass.apply(position); } else { return fail.apply(position); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskingFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskingFilter.java index cea580d8b..d1ab8957d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskingFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskingFilter.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.function; import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.math.BlockVector3; @@ -33,7 +34,8 @@ import com.sk89q.worldedit.math.BlockVector3; public class RegionMaskingFilter implements RegionFunction { private final RegionFunction function; - private Mask mask; + private final Extent extent; + private final Mask mask; /** * Create a new masking filter. @@ -41,16 +43,18 @@ public class RegionMaskingFilter implements RegionFunction { * @param mask the mask * @param function the function */ - public RegionMaskingFilter(Mask mask, RegionFunction function) { + public RegionMaskingFilter(Extent extent, Mask mask, RegionFunction function) { checkNotNull(function); checkNotNull(mask); + checkNotNull(extent); + this.extent = extent; this.mask = mask; this.function = function; } @Override public boolean apply(BlockVector3 position) throws WorldEditException { - return mask.test(position) && function.apply(position); + return mask.test(extent, position) && function.apply(position); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java index da02904bd..51886a60a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java @@ -63,7 +63,7 @@ public class Naturalizer implements LayerFunction { @Override public boolean isGround(BlockVector3 position) { - return mask.test(position); + return mask.test(editSession, position); } private BlockState getTargetBlock(int depth) { @@ -95,7 +95,7 @@ public class Naturalizer implements LayerFunction { @Override public boolean apply(BlockVector3 position, int depth) throws WorldEditException { - if (mask.test(position)) { + if (mask.test(editSession, position)) { if (naturalize(position, depth)) { ++affected; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/OreGen.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/OreGen.java index f544de178..d8d46f8a8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/OreGen.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/OreGen.java @@ -42,7 +42,7 @@ public class OreGen implements Resource { @Override public boolean spawn(Random rand, int x, int z) throws WorldEditException { int y = rand.nextInt(maxY - minY) + minY; - if (!mask.test(mutable.setComponents(x, y, z))) { + if (!mask.test(extent, mutable.setComponents(x, y, z))) { return false; } double f = rand.nextDouble() * Math.PI; @@ -102,7 +102,7 @@ public class OreGen implements Resource { double dz = (zz + 0.5D - d9) * id11o2; double dxyz2 = dxy2 + dz * dz; if ((dxyz2 < 1)) { - if (mask.test(mutable)) + if (mask.test(extent, mutable)) pattern.apply(extent, mutable, mutable); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/SchemGen.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/SchemGen.java index 3ff43d429..8e65302c9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/SchemGen.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/SchemGen.java @@ -35,7 +35,7 @@ public class SchemGen implements Resource { int y = extent.getNearestSurfaceTerrainBlock(x, z, mutable.getBlockY(), 0, 255); if (y == -1) return false; mutable.mutY(y); - if (!mask.test(mutable)) { + if (!mask.test(extent, mutable)) { return false; } mutable.mutY(y + 1); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ABlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ABlockMask.java index 9b5ea1aca..5c22f44f2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ABlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ABlockMask.java @@ -2,6 +2,7 @@ package com.sk89q.worldedit.function.mask; import com.boydti.fawe.util.StringMan; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -15,6 +16,11 @@ public abstract class ABlockMask extends AbstractExtentMask { super(extent); } + @Override + public boolean test(Extent extent, BlockVector3 vector) { + return test(vector.getBlock(extent)); + } + public abstract boolean test(BlockState state); @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/AbstractExtentMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/AbstractExtentMask.java index dbb3f28cc..dd87fafdb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/AbstractExtentMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/AbstractExtentMask.java @@ -22,6 +22,8 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.session.request.Request; /** * An abstract implementation of {@link Mask} that takes uses an {@link Extent}. @@ -39,6 +41,11 @@ public abstract class AbstractExtentMask extends AbstractMask { setExtent(extent); } + @Override + public boolean test(BlockVector3 vector) { + return test(getExtent(), vector); + } + /** * Get the extent. * @@ -58,4 +65,9 @@ public abstract class AbstractExtentMask extends AbstractMask { this.extent = extent; } + @Override + public Mask withExtent(Extent extent) { + setExtent(extent); + return this; + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java index 633159acb..30124bb93 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java @@ -90,7 +90,7 @@ public class BiomeMask2D extends AbstractMask2D { } @Override - public boolean test(BlockVector2 vector) { + public boolean test(Extent extent, BlockVector2 vector) { BiomeType biome = extent.getBiome(vector); return biomes.contains(biome); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java index 318f8cb86..5b679f748 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java @@ -40,8 +40,8 @@ public class BlockCategoryMask extends AbstractExtentMask { } @Override - public boolean test(BlockVector3 vector) { - return category.contains(getExtent().getBlock(vector)); + public boolean test(Extent extent, BlockVector3 vector) { + return category.contains(vector.getBlock(extent)); } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java index a0b67290f..cd78a773a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java @@ -172,8 +172,8 @@ public class BlockMask extends ABlockMask { } @Override - public boolean test(BlockVector3 vector) { - return ordinals[vector.getOrdinal(getExtent())]; + public boolean test(Extent extent, BlockVector3 vector) { + return ordinals[vector.getOrdinal(extent)]; } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockStateMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockStateMask.java index 44e9dcdc3..b8bc72e8f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockStateMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockStateMask.java @@ -51,8 +51,8 @@ public class BlockStateMask extends AbstractExtentMask { } @Override - public boolean test(BlockVector3 vector) { - return test(vector.getBlock(getExtent())); + public boolean test(Extent extent, BlockVector3 vector) { + return test(vector.getBlock(extent)); } public boolean test(BlockState block) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java index b235d573f..c33db1738 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java @@ -106,8 +106,8 @@ public class BlockTypeMask extends AbstractExtentMask { } @Override - public boolean test(BlockVector3 vector) { - return test(vector.getBlock(getExtent()).getBlockType()); + public boolean test(Extent extent, BlockVector3 vector) { + return test(vector.getBlock(extent).getBlockType()); } public boolean test(BlockType block) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java index 108fcbe76..fce4714c5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkArgument; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; @@ -46,7 +47,7 @@ public class BoundedHeightMask extends AbstractMask { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { return vector.getY() >= minY && vector.getY() <= maxY; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/DelegateExtentMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/DelegateExtentMask.java new file mode 100644 index 000000000..7119ba96e --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/DelegateExtentMask.java @@ -0,0 +1,28 @@ +package com.sk89q.worldedit.function.mask; + +import com.boydti.fawe.object.function.mask.AbstractDelegateMask; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; + +public class DelegateExtentMask extends AbstractDelegateMask { + private final Extent extent; + + public DelegateExtentMask(Extent extent, Mask parent) { + super(parent); + this.extent = extent; + } + + @Override + public boolean test(BlockVector3 vector) { + return super.test(extent, vector); + } + + public Extent getExtent() { + return extent; + } + + @Override + public Mask withExtent(Extent extent) { + return new DelegateExtentMask(extent, getMask()); + } +} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java index 9c10590d9..730cb93aa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java @@ -39,8 +39,8 @@ public class ExistingBlockMask extends AbstractExtentMask { } @Override - public boolean test(BlockVector3 vector) { - return !vector.getBlock(getExtent()).getMaterial().isAir(); + public boolean test(Extent extent, BlockVector3 vector) { + return !vector.getBlock(extent).getMaterial().isAir(); } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask.java index d540a41af..55dd8e034 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.EvaluationException; @@ -67,7 +68,7 @@ public class ExpressionMask extends AbstractMask { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { try { if (expression.getEnvironment() instanceof WorldEditExpressionEnvironment) { ((WorldEditExpressionEnvironment) expression.getEnvironment()).setCurrentBlock(vector.toVector3()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask2D.java index 051e4692a..123c0a54c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask2D.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.EvaluationException; import com.sk89q.worldedit.internal.expression.ExpressionException; @@ -59,7 +60,7 @@ public class ExpressionMask2D extends AbstractMask2D { } @Override - public boolean test(BlockVector2 vector) { + public boolean test(Extent extent, BlockVector2 vector) { try { if (timeout == null) { return expression.evaluate(vector.getX(), 0, vector.getZ()) > 0; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseMask.java index 3999dfc44..9adc170ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseMask.java @@ -2,6 +2,7 @@ package com.sk89q.worldedit.function.mask; import javax.annotation.Nullable; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; public class InverseMask extends AbstractMask { @@ -12,8 +13,8 @@ public class InverseMask extends AbstractMask { } @Override - public boolean test(BlockVector3 vector) { - return !mask.test(vector); + public boolean test(Extent extent, BlockVector3 pos) { + return !mask.test(extent, pos); } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockStateMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockStateMask.java index 2ea0b3027..25efcfb03 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockStateMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockStateMask.java @@ -18,8 +18,8 @@ public class InverseSingleBlockStateMask extends ABlockMask { } @Override - public boolean test(BlockVector3 vector) { - return ordinal != vector.getOrdinal(getExtent()); + public boolean test(Extent extent, BlockVector3 vector) { + return ordinal != vector.getOrdinal(extent); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java index ba327b84a..1009ca3ad 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/InverseSingleBlockTypeMask.java @@ -16,8 +16,8 @@ public class InverseSingleBlockTypeMask extends ABlockMask { } @Override - public boolean test(BlockVector3 vector) { - return test(vector.getBlock(getExtent())); + public boolean test(Extent extent, BlockVector3 vector) { + return test(vector.getBlock(extent)); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java index bce8f1c34..24f473309 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java @@ -21,7 +21,13 @@ package com.sk89q.worldedit.function.mask; import com.boydti.fawe.beta.Filter; import com.boydti.fawe.beta.implementation.filter.block.FilterBlock; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extent.NullExtent; +import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.session.request.Request; + import javax.annotation.Nullable; import java.util.function.Consumer; @@ -36,12 +42,26 @@ public interface Mask { * @param vector the vector to test * @return true if the criteria is met */ - boolean test(BlockVector3 vector); + default boolean test(BlockVector3 vector) { + Extent extent = Request.request().getExtent(); + if (extent == null) { + extent = NullExtent.INSTANCE; + } + return test(extent, vector); + } + + default boolean test(Extent extent, BlockVector3 vector) { + return test(vector); + } default MaskFilter toFilter(T filter) { return new MaskFilter<>(filter, this); } + default Mask withExtent(Extent extent) { + return new DelegateExtentMask(extent, this); + } + /** * Get the 2D version of this mask if one exists. * @@ -97,7 +117,7 @@ public interface Mask { return new Filter() { @Override public void applyBlock(FilterBlock block) { - if (test(block)) { + if (test(block, block)) { run.accept(block); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java index 3e48a0e9a..dc81b27dd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java @@ -19,7 +19,10 @@ package com.sk89q.worldedit.function.mask; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.session.request.Request; /** * Tests whether a given vector meets a criteria. @@ -32,6 +35,16 @@ public interface Mask2D { * @param vector the vector to test * @return true if the criteria is met */ - boolean test(BlockVector2 vector); + default boolean test(BlockVector2 vector) { + Extent extent = Request.request().getExtent(); + if (extent == null) { + extent = NullExtent.INSTANCE; + } + return test(extent, vector); + } + + default boolean test(Extent extent, BlockVector2 vector) { + return test(vector); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskFilter.java index 6632ae17e..850a80cc0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskFilter.java @@ -26,7 +26,7 @@ public class MaskFilter extends DelegateFilter { @Override public void applyBlock(FilterBlock block) { - if (mask.test(block)) { + if (mask.test(block, block)) { getParent().applyBlock(block); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java index d7743c520..26374f2cf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; import static org.slf4j.LoggerFactory.getLogger; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import java.util.AbstractMap; import java.util.ArrayList; @@ -224,9 +225,9 @@ public class MaskIntersection extends AbstractMask { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { for (Mask mask : masksArray) { - if (!mask.test(vector)) { + if (!mask.test(extent, vector)) { return false; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java index eec35eab9..e10dfb53d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import java.util.Arrays; @@ -83,13 +84,13 @@ public class MaskIntersection2D implements Mask2D { } @Override - public boolean test(BlockVector2 vector) { + public boolean test(Extent extent, BlockVector2 vector) { if (masks.isEmpty()) { return false; } for (Mask2D mask : masks) { - if (!mask.test(vector)) { + if (!mask.test(extent, vector)) { return false; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java index 6151a6c15..9ba06d73a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.function.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import java.util.ArrayList; import java.util.Collection; @@ -84,11 +85,11 @@ public class MaskUnion extends MaskIntersection { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { Mask[] masks = getMasksArray(); for (Mask mask : masks) { - if (mask.test(vector)) { + if (mask.test(extent, vector)) { return true; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion2D.java index 678fcbdd4..f272c5bbb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion2D.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.function.mask; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import java.util.Collection; @@ -47,11 +48,11 @@ public class MaskUnion2D extends MaskIntersection2D { } @Override - public boolean test(BlockVector2 vector) { + public boolean test(Extent extent, BlockVector2 vector) { Collection masks = getMasks(); for (Mask2D mask : masks) { - if (mask.test(vector)) { + if (mask.test(extent, vector)) { return true; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java index 3b743d13b..a255a0436 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; @@ -89,8 +90,8 @@ public final class Masks { checkNotNull(mask); return new AbstractMask2D() { @Override - public boolean test(BlockVector2 vector) { - return !mask.test(vector); + public boolean test(Extent extent, BlockVector2 vector) { + return !mask.test(extent, vector); } }; } @@ -104,8 +105,8 @@ public final class Masks { public static Mask asMask(final Mask2D mask) { return new AbstractMask() { @Override - public boolean test(BlockVector3 vector) { - return mask.test(vector.toBlockVector2()); + public boolean test(Extent extent, BlockVector3 vector) { + return mask.test(extent, vector.toBlockVector2()); } @Nullable @@ -118,12 +119,12 @@ public final class Masks { protected static class AlwaysTrue implements Mask, Mask2D { @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { return true; } @Override - public boolean test(BlockVector2 vector) { + public boolean test(Extent extent, BlockVector2 vector) { return true; } @@ -142,16 +143,21 @@ public final class Masks { public Mask tryOr(Mask other) { return this; } + + @Override + public Mask withExtent(Extent extent) { + return this; + } } protected static class AlwaysFalse implements Mask, Mask2D { @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { return false; } @Override - public boolean test(BlockVector2 vector) { + public boolean test(Extent extent, BlockVector2 vector) { return false; } @@ -170,6 +176,11 @@ public final class Masks { public Mask tryOr(Mask other) { return other; } + + @Override + public Mask withExtent(Extent extent) { + return this; + } } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java index 6e1e247b9..22a77f209 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MutableVector3; import com.sk89q.worldedit.math.noise.NoiseGenerator; @@ -85,7 +86,7 @@ public class NoiseFilter extends AbstractMask { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { return noiseGenerator.noise(MutableVector3.get(vector.getX(), vector.getY(), vector.getZ())) <= density; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter2D.java index f7a2c992e..b4a7a5aad 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter2D.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.noise.NoiseGenerator; @@ -83,7 +84,7 @@ public class NoiseFilter2D extends AbstractMask2D { } @Override - public boolean test(BlockVector2 pos) { + public boolean test(Extent extent, BlockVector2 pos) { return noiseGenerator.noise(pos.toVector2()) <= density; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java index e5df3b153..5fab17454 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; @@ -86,8 +87,8 @@ public class OffsetMask extends AbstractMask { } @Override - public boolean test(BlockVector3 vector) { - return getMask().test(vector.add(offset)); + public boolean test(Extent extent, BlockVector3 pos) { + return getMask().test(extent, pos); } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask2D.java index 94b595fdf..cb0832beb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask2D.java @@ -21,7 +21,9 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.MutableBlockVector2; /** * Checks whether another mask tests true for a position that is offset @@ -31,6 +33,7 @@ public class OffsetMask2D extends AbstractMask2D { private Mask2D mask; private BlockVector2 offset; + private MutableBlockVector2 mutable; /** * Create a new instance. @@ -43,6 +46,7 @@ public class OffsetMask2D extends AbstractMask2D { checkNotNull(offset); this.mask = mask; this.offset = offset; + this.mutable = new MutableBlockVector2(); } /** @@ -84,8 +88,9 @@ public class OffsetMask2D extends AbstractMask2D { } @Override - public boolean test(BlockVector2 vector) { - return getMask().test(vector.add(offset)); + public boolean test(Extent extent, BlockVector2 vector) { + mutable.setComponents(vector.getX() + offset.getX(), vector.getZ() + offset.getZ()); + return getMask().test(extent, mutable); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java index 5ac7721e1..ce589776f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java @@ -21,6 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import javax.annotation.Nullable; @@ -61,7 +62,7 @@ public class RegionMask extends AbstractMask { } @Override - public boolean test(BlockVector3 vector) { + public boolean test(Extent extent, BlockVector3 vector) { return region.contains(vector); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java index 1ec097fcd..f9c90d718 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockStateMask.java @@ -18,8 +18,8 @@ public class SingleBlockStateMask extends ABlockMask { } @Override - public boolean test(BlockVector3 vector) { - return ordinal == vector.getOrdinal(getExtent()); + public boolean test(Extent extent, BlockVector3 vector) { + return ordinal == vector.getOrdinal(extent); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockTypeMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockTypeMask.java index 2ab4f2add..01d4aad7c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockTypeMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SingleBlockTypeMask.java @@ -1,7 +1,6 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -15,11 +14,6 @@ public class SingleBlockTypeMask extends ABlockMask { this.internalId = type.getInternalId(); } - @Override - public boolean test(BlockVector3 vector) { - return test(vector.getBlock(getExtent())); - } - @Override public final boolean test(BlockState state) { return state.getBlockType().getInternalId() == internalId; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index 8b46bb04e..b9e9fb180 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -317,7 +317,7 @@ public class ForwardExtentCopy implements Operation { } if (sourceMask != Masks.alwaysTrue()) { new MaskTraverser(sourceMask).reset(transExt); - copy = new RegionMaskingFilter(sourceMask, copy); + copy = new RegionMaskingFilter(source, sourceMask, copy); } if (copyingBiomes && source.isWorld() || (source instanceof Clipboard && ((Clipboard) source).hasBiomes())) { copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest)); @@ -371,7 +371,7 @@ public class ForwardExtentCopy implements Operation { } if (sourceMask != Masks.alwaysTrue()) { if (maskFunc != null) copy = new RegionMaskTestFunction(sourceMask, copy, maskFunc); - else copy = new RegionMaskingFilter(sourceMask, copy); + else copy = new RegionMaskingFilter(source, sourceMask, copy); } if (copyingBiomes && source.isWorld() || (source instanceof Clipboard && ((Clipboard) source).hasBiomes())) { copy = CombinedRegionFunction.combine(copy, new BiomeCopy(source, finalDest)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java index 820d813d3..6aeab5aed 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java @@ -20,6 +20,7 @@ package com.sk89q.worldedit.util; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.SolidBlockMask; @@ -38,7 +39,7 @@ import javax.annotation.Nullable; */ public class TargetBlock { - private final World world; + private final Extent world; private int maxDistance; private double checkDistance, curDistance; @@ -58,11 +59,7 @@ public class TargetBlock { * @param player player to work with */ public TargetBlock(Player player) { - this.world = player.getWorld(); - this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(), - 300, 1.65, 0.2); - this.stopMask = new ExistingBlockMask(world); - this.solidMask = new SolidBlockMask(world); + this(player, 300, 0.2); } /** @@ -73,6 +70,10 @@ public class TargetBlock { * @param checkDistance how often to check for blocks, the smaller the more precise */ public TargetBlock(Player player, int maxDistance, double checkDistance) { + this(player, player.getWorld(), maxDistance, checkDistance); + } + + public TargetBlock(Player player, Extent extent, int maxDistance, double checkDistance) { this.world = player.getWorld(); this.setValues(player.getLocation().toVector(), player.getLocation().getYaw(), player.getLocation().getPitch(), maxDistance, 1.65, checkDistance); this.stopMask = new ExistingBlockMask(world); @@ -145,7 +146,7 @@ public class TargetBlock { boolean searchForLastBlock = true; Location lastBlock = null; while (getNextBlock() != null) { - if (stopMask.test(targetPos)) { + if (stopMask.test(world, targetPos)) { break; } else { if (searchForLastBlock) { @@ -168,7 +169,7 @@ public class TargetBlock { */ public Location getTargetBlock() { //noinspection StatementWithEmptyBody - while (getNextBlock() != null && !stopMask.test(targetPos)) ; + while (getNextBlock() != null && !stopMask.test(world, targetPos)) ; return getCurrentBlock(); } @@ -180,7 +181,7 @@ public class TargetBlock { */ public Location getSolidTargetBlock() { //noinspection StatementWithEmptyBody - while (getNextBlock() != null && !solidMask.test(targetPos)) ; + while (getNextBlock() != null && !solidMask.test(world, targetPos)) ; return getCurrentBlock(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index ea2924cf9..1803b72af 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -31,7 +31,10 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.extent.OutputExtent; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.function.mask.SingleBlockStateMask; import com.sk89q.worldedit.function.pattern.FawePattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.AbstractProperty; @@ -227,6 +230,10 @@ public class BlockState implements BlockStateHolder, FawePattern { return this.toBaseBlock(); } + public Mask toMask() { + return new SingleBlockStateMask(new NullExtent(), this); + } + @Override public void applyTileEntity(OutputExtent output, int x, int y, int z) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java index 28404f30e..d0407dc98 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java @@ -103,7 +103,7 @@ public class SnapshotRestore { } private void checkAndAddBlock(BlockVector3 pos) { - if (editSession.getMask() != null && !editSession.getMask().test(pos)) + if (editSession.getMask() != null && !editSession.getMask().test(editSession, pos)) return; BlockVector2 chunkPos = ChunkStore.toChunk(pos);