Adjacent mask range parameter

This commit is contained in:
Jesse Boyd 2016-09-25 05:11:34 +10:00
parent c676d89aa6
commit 479c6c5172
2 changed files with 19 additions and 13 deletions

View File

@ -7,11 +7,12 @@ import com.sk89q.worldedit.function.mask.BlockMask;
import java.util.Collection; import java.util.Collection;
public class AdjacentMask extends BlockMask { public class AdjacentMask extends BlockMask {
private final int required; private final int min, max;
public AdjacentMask(Extent extent, Collection<BaseBlock> blocks, int required) { public AdjacentMask(Extent extent, Collection<BaseBlock> blocks, int requiredMin, int requiredMax) {
super(extent, blocks); super(extent, blocks);
this.required = required; this.min = requiredMin;
this.max = requiredMax;
} }
@Override @Override
@ -21,20 +22,20 @@ public class AdjacentMask extends BlockMask {
double y = v.y; double y = v.y;
double z = v.z; double z = v.z;
v.x = x + 1; v.x = x + 1;
if (super.test(v) && ++count == required) { v.x = x; return true; } if (super.test(v) && ++count == min && max >= 8) { v.x = x; return true; }
v.x = x - 1; v.x = x - 1;
if (super.test(v) && ++count == required) { v.x = x; return true; } if (super.test(v) && ++count == min && max >= 8) { v.x = x; return true; }
v.x = x; v.x = x;
v.y = y + 1; v.y = y + 1;
if (super.test(v) && ++count == required) { v.y = y; return true; } if (super.test(v) && ++count == min && max >= 8) { v.y = y; return true; }
v.y = y - 1; v.y = y - 1;
if (super.test(v) && ++count == required) { v.y = y; return true; } if (super.test(v) && ++count == min && max >= 8) { v.y = y; return true; }
v.y = y; v.y = y;
v.z = z + 1; v.z = z + 1;
if (super.test(v) && ++count == required) { v.z = z; return true; } if (super.test(v) && ++count == min && max >= 8) { v.z = z; return true; }
v.z = z - 1; v.z = z - 1;
if (super.test(v) && ++count == required) { v.z = z; return true; } if (super.test(v) && ++count == min && max >= 8) { v.z = z; return true; }
v.z = z; v.z = z;
return false; return count >= min && count <= max;
} }
} }

View File

@ -167,11 +167,16 @@ public class DefaultMaskParser extends InputParser<Mask> {
tempContext.setRestricted(false); tempContext.setRestricted(false);
tempContext.setPreferringWildcard(true); tempContext.setPreferringWildcard(true);
try { try {
int requiredCount = 1; int requiredMin = 1;
int requiredMax = 8;
if (split.length == 2) { if (split.length == 2) {
requiredCount = Integer.parseInt(split[1]); String[] split2 = split[1].split(",");
requiredMin = Integer.parseInt(split2[0]);
if (split2.length == 2) {
requiredMax = Integer.parseInt(split2[1]);
} }
return new AdjacentMask(extent, worldEdit.getBlockFactory().parseFromListInput(component.substring(1), tempContext), requiredCount); }
return new AdjacentMask(extent, worldEdit.getBlockFactory().parseFromListInput(component.substring(1), tempContext), requiredMin, requiredMax);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new InputParseException("Unknown adjacent mask '" + component + "' (not in form `~<ids>[=count]`)"); throw new InputParseException("Unknown adjacent mask '" + component + "' (not in form `~<ids>[=count]`)");
} }