diff --git a/core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java b/core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java index a172f683..72b911c0 100644 --- a/core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java +++ b/core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java @@ -7,29 +7,33 @@ import com.sk89q.worldedit.function.mask.BlockMask; import java.util.Collection; public class AdjacentMask extends BlockMask { - public AdjacentMask(Extent extent, Collection blocks) { + private final int required; + + public AdjacentMask(Extent extent, Collection blocks, int required) { super(extent, blocks); + this.required = required; } @Override public boolean test(Vector v) { + int count = 0; double x = v.x; double y = v.y; double z = v.z; v.x = x + 1; - if (super.test(v)) { v.x = x; return true; } + if (super.test(v) && ++count == required) { v.x = x; return true; } v.x = x - 1; - if (super.test(v)) { v.x = x; return true; } + if (super.test(v) && ++count == required) { v.x = x; return true; } v.x = x; v.y = y + 1; - if (super.test(v)) { v.y = y; return true; } + if (super.test(v) && ++count == required) { v.y = y; return true; } v.y = y - 1; - if (super.test(v)) { v.y = y; return true; } + if (super.test(v) && ++count == required) { v.y = y; return true; } v.y = y; v.z = z + 1; - if (super.test(v)) { v.z = z; return true; } + if (super.test(v) && ++count == required) { v.z = z; return true; } v.z = z - 1; - if (super.test(v)) { v.z = z; return true; } + if (super.test(v) && ++count == required) { v.z = z; return true; } v.z = z; return false; } diff --git a/core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java b/core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java index 029ba0f0..1d05fb55 100644 --- a/core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java +++ b/core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java @@ -27,8 +27,8 @@ public class RadiusMask implements Mask, ResettableMask{ pos = new Vector(to); } int dx = Math.abs((int) (pos.x - to.x)); - int dy = Math.abs((int) (pos.x - to.x)); - int dz = Math.abs((int) (pos.x - to.x)); + int dy = Math.abs((int) (pos.y - to.y)); + int dz = Math.abs((int) (pos.z - to.z)); int d = dx * dx; if (d < minSqr || d > maxSqr) { return false; diff --git a/core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java b/core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java index a9f4fe1e..25fc1624 100644 --- a/core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java +++ b/core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java @@ -45,6 +45,7 @@ import java.util.HashSet; import java.util.List; import java.util.Set; + import static com.google.common.base.Preconditions.checkNotNull; /** @@ -147,7 +148,7 @@ public class DefaultMaskParser extends InputParser { throw new InputParseException("Unknown angle '" + component + "' (not in form `/#,#`)"); } } - case '{': + case '{': { String[] split = component.substring(1).split(","); if (split.length != 2) { throw new InputParseException("Unknown range '" + component + "' (not in form `{#,#`)"); @@ -159,11 +160,21 @@ public class DefaultMaskParser extends InputParser { } catch (NumberFormatException e) { throw new InputParseException("Unknown range '" + component + "' (not in form `{#,#`)"); } + } case '~': { + String[] split = component.substring(1).split("="); ParserContext tempContext = new ParserContext(context); tempContext.setRestricted(false); tempContext.setPreferringWildcard(true); - return new AdjacentMask(extent, worldEdit.getBlockFactory().parseFromListInput(component.substring(1), tempContext)); + try { + int requiredCount = 1; + if (split.length == 2) { + requiredCount = Integer.parseInt(split[1]); + } + return new AdjacentMask(extent, worldEdit.getBlockFactory().parseFromListInput(component.substring(1), tempContext)); + } catch (NumberFormatException e) { + throw new InputParseException("Unknown adjacent mask '" + component + "' (not in form `~[=count]`)"); + } } case '>': case '<':