use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.
the class EditSession method fillXZ.
/**
* Fills an area recursively in the X/Z directions.
*
* @param origin the origin to start the fill from
* @param pattern the pattern to fill with
* @param radius the radius of the spherical area to fill, with 0 as the smallest radius
* @param depth the maximum depth, starting from the origin, with 1 as the smallest depth
* @param recursive whether a breadth-first search should be performed
* @return number of blocks affected
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int fillXZ(BlockVector3 origin, Pattern pattern, double radius, int depth, boolean recursive) throws MaxChangedBlocksException {
checkNotNull(origin);
checkNotNull(pattern);
checkArgument(radius >= 0, "radius >= 0");
checkArgument(depth >= 1, "depth >= 1");
Mask mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, Vector3.at(radius, radius, radius))), new BoundedHeightMask(Math.max(origin.getBlockY() - depth + 1, minY), Math.min(maxY, origin.getBlockY())), Masks.negate(new ExistingBlockMask(this)));
// Want to replace blocks
BlockReplace replace = new BlockReplace(this, pattern);
// Pick how we're going to visit blocks
RecursiveVisitor visitor;
// FAWE start - provide extent for preloading, min/max y
if (recursive) {
visitor = new RecursiveVisitor(mask, replace, (int) (radius * 2 + 1), minY, maxY, this);
} else {
visitor = new DownwardVisitor(mask, replace, origin.getBlockY(), (int) (radius * 2 + 1), minY, maxY, this);
}
// FAWE end
// Start at the origin
visitor.visit(origin);
// Execute
Operations.completeLegacy(visitor);
// FAWE start
return this.changes = visitor.getAffected();
// FAWE end
}
use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.
the class LayerBrush method build.
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern ignore, double size) throws MaxChangedBlocksException {
final AdjacentAnyMask adjacent = new AdjacentAnyMask(new BlockMask(editSession).add(BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR), editSession.getMinY(), editSession.getMaxY());
final SolidBlockMask solid = new SolidBlockMask(editSession);
final RadiusMask radius = new RadiusMask(0, (int) size);
visitor = new RecursiveVisitor(new MaskIntersection(adjacent, solid, radius), funcion -> true, Integer.MAX_VALUE, editSession.getMinY(), editSession.getMaxY());
visitor.visit(position);
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
Operations.completeBlindly(visitor);
BlockVectorSet visited = visitor.getVisited();
visitor = new RecursiveVisitor(new LayerBrushMask(editSession, visitor, layers, adjacent), pos -> {
int depth = visitor.getDepth();
Pattern currentPattern = layers[depth];
return currentPattern.apply(editSession, pos, pos);
}, layers.length - 1, editSession.getMinY(), editSession.getMaxY());
for (BlockVector3 pos : visited) {
visitor.visit(pos);
}
Operations.completeBlindly(visitor);
visitor = null;
}
use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.
the class ScatterBrush method build.
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
this.mask = editSession.getMask();
if (this.mask == null) {
this.mask = Masks.alwaysTrue();
}
surface = new SurfaceMask(editSession);
final RadiusMask radius = new RadiusMask(0, (int) size);
final int distance = Math.min((int) size, this.distance);
RecursiveVisitor visitor = new RecursiveVisitor(new MaskIntersection(radius, surface), function -> true, Integer.MAX_VALUE, editSession.getMinY(), editSession.getMaxY());
visitor.visit(position);
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
Operations.completeBlindly(visitor);
BlockVectorSet visited = visitor.getVisited();
int length = visited.size();
if (size == 0) {
length = 1;
visited.add(position);
}
LocalBlockVectorSet placed = new LocalBlockVectorSet();
placed.setOffset(position.getX(), position.getZ());
int maxFails = 1000;
for (int i = 0; i < count; i++) {
int index = ThreadLocalRandom.current().nextInt(length);
BlockVector3 pos = visited.get(index);
if (pos != null && canApply(pos)) {
int x = pos.getBlockX();
int y = pos.getBlockY();
int z = pos.getBlockZ();
if (placed.containsRadius(x, y, z, distance)) {
if (maxFails-- <= 0) {
break;
}
i--;
continue;
}
placed.add(x, y, z);
apply(editSession, placed, pos, pattern, size);
}
}
finish(editSession, placed, position, pattern, size);
}
use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.
the class SplineBrush method build.
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws WorldEditException {
Mask mask = editSession.getMask();
if (mask == null) {
mask = new IdMask(editSession);
} else {
mask = new MaskIntersection(mask, new IdMask(editSession));
}
boolean newPos = !position.equals(this.position);
this.position = position;
if (newPos) {
if (positionSets.size() >= MAX_POINTS) {
throw FaweCache.MAX_CHECKS;
}
final ArrayList<BlockVector3> points = new ArrayList<>();
if (size > 0) {
DFSRecursiveVisitor visitor = new DFSRecursiveVisitor(mask, p -> {
points.add(p);
return true;
}, (int) size, 1);
List<BlockVector3> directions = visitor.getDirections();
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
if (x != 0 || y != 0 || z != 0) {
BlockVector3 pos = BlockVector3.at(x, y, z);
if (!directions.contains(pos)) {
directions.add(pos);
}
}
}
}
}
directions.sort((o1, o2) -> (int) Math.signum(o1.lengthSq() - o2.lengthSq()));
visitor.visit(position);
Operations.completeBlindly(visitor);
if (points.size() > numSplines) {
numSplines = points.size();
}
} else {
points.add(position);
}
this.positionSets.add(points);
player.print(Caption.of("fawe.worldedit.brush.spline.primary.2"));
return;
}
if (positionSets.size() < 2) {
player.print(Caption.of("fawe.worldedit.brush.brush.spline.secondary.error"));
return;
}
List<Vector3> centroids = new ArrayList<>();
for (List<BlockVector3> points : positionSets) {
centroids.add(getCentroid(points));
}
double tension = 0;
double bias = 0;
double continuity = 0;
final List<Node> nodes = new ArrayList<>(centroids.size());
for (Vector3 nodevector : centroids) {
final Node n = new Node(nodevector);
n.setTension(tension);
n.setBias(bias);
n.setContinuity(continuity);
nodes.add(n);
}
for (int i = 0; i < numSplines; i++) {
List<BlockVector3> currentSpline = new ArrayList<>();
for (ArrayList<BlockVector3> points : positionSets) {
int listSize = points.size();
int index = (int) (i * listSize / (double) numSplines);
currentSpline.add(points.get(index));
}
editSession.drawSpline(pattern, currentSpline, 0, 0, 0, 10, 0, true);
}
player.print(Caption.of("fawe.worldedit.brush.spline.secondary"));
positionSets.clear();
numSplines = 0;
}
use of com.sk89q.worldedit.function.mask.MaskIntersection in project FastAsyncWorldEdit by IntellectualSites.
the class SurfaceSphereBrush method build.
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
SurfaceMask surface = new SurfaceMask(editSession);
final RadiusMask radius = new RadiusMask(0, (int) size);
RecursiveVisitor visitor = new RecursiveVisitor(new MaskIntersection(surface, radius), vector -> editSession.setBlock(vector, pattern), Integer.MAX_VALUE, editSession.getMinY(), editSession.getMaxY());
visitor.visit(position);
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
Operations.completeBlindly(visitor);
}
Aggregations