use of com.sk89q.worldedit.function.visitor.RecursiveVisitor in project FastAsyncWorldEdit by IntellectualSites.
the class CopyPastaBrush method build.
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
ClipboardHolder clipboard = session.getExistingClipboard();
if (clipboard == null) {
Mask mask = editSession.getMask();
if (mask == null) {
mask = Masks.alwaysTrue();
}
final ResizableClipboardBuilder builder = new ResizableClipboardBuilder(editSession.getWorld());
final int minY = position.getBlockY();
mask = new AbstractDelegateMask(mask) {
@Override
public boolean test(BlockVector3 vector) {
if (super.test(vector) && vector.getBlockY() >= minY) {
BaseBlock block = editSession.getFullBlock(vector);
if (!block.getBlockType().getMaterial().isAir()) {
builder.add(vector, BlockTypes.AIR.getDefaultState().toBaseBlock(), block);
return true;
}
}
return false;
}
};
// Add origin
mask.test(position);
RecursiveVisitor visitor = new RecursiveVisitor(mask, new NullRegionFunction(), (int) size, editSession.getMinY(), editSession.getMaxY());
visitor.visit(position);
Operations.completeBlindly(visitor);
// Build the clipboard
Clipboard newClipboard = builder.build();
newClipboard.setOrigin(position);
ClipboardHolder holder = new ClipboardHolder(newClipboard);
session.setClipboard(holder);
int blocks = builder.size();
player.print(Caption.of("fawe.worldedit.copy.command.copy", blocks));
} else {
AffineTransform transform = null;
if (randomRotate) {
transform = new AffineTransform();
int rotate = 90 * ThreadLocalRandom.current().nextInt(4);
transform = transform.rotateY(rotate);
}
if (autoRotate) {
if (transform == null) {
transform = new AffineTransform();
}
Location loc = player.getLocation();
float yaw = loc.getYaw();
float pitch = loc.getPitch();
transform = transform.rotateY(-yaw % 360);
transform = transform.rotateX(pitch - 90);
}
if (transform != null && !transform.isIdentity()) {
clipboard.setTransform(transform);
}
Operation operation = clipboard.createPaste(editSession).to(position.add(0, 1, 0)).ignoreAirBlocks(true).build();
Operations.completeLegacy(operation);
editSession.flushQueue();
}
}
use of com.sk89q.worldedit.function.visitor.RecursiveVisitor 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.visitor.RecursiveVisitor 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.visitor.RecursiveVisitor 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.visitor.RecursiveVisitor in project FastAsyncWorldEdit by IntellectualSites.
the class SplatterBrush method apply.
@Override
public void apply(final EditSession editSession, final LocalBlockVectorSet placed, final BlockVector3 position, Pattern p, double size) throws MaxChangedBlocksException {
final Pattern finalPattern;
if (solid) {
finalPattern = p.applyBlock(position);
} else {
finalPattern = p;
}
final int size2 = (int) (size * size);
SurfaceMask surface = new SurfaceMask(editSession);
RecursiveVisitor visitor = new RecursiveVisitor(new SplatterBrushMask(editSession, position, size2, surface, placed), vector -> editSession.setBlock(vector, finalPattern), recursion, editSession.getMinY(), editSession.getMaxY());
visitor.setMaxBranch(2);
visitor.setDirections(Arrays.asList(BreadthFirstSearch.DIAGONAL_DIRECTIONS));
visitor.visit(position);
Operations.completeBlindly(visitor);
}
Aggregations