mirror of
https://github.com/boy0001/FastAsyncWorldedit.git
synced 2024-11-28 13:45:36 +01:00
Fix radius mask
This commit is contained in:
parent
f2e576a14f
commit
fca33e5e87
@ -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<BaseBlock> blocks) {
|
||||
private final int required;
|
||||
|
||||
public AdjacentMask(Extent extent, Collection<BaseBlock> 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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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<Mask> {
|
||||
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<Mask> {
|
||||
} 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 `~<ids>[=count]`)");
|
||||
}
|
||||
}
|
||||
case '>':
|
||||
case '<':
|
||||
|
Loading…
Reference in New Issue
Block a user