Search in sources :

Example 1 with DownwardVisitor

use of com.sk89q.worldedit.function.visitor.DownwardVisitor 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
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) BlockTypeMask(com.sk89q.worldedit.function.mask.BlockTypeMask) SingleBlockTypeMask(com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) BlockStateMask(com.sk89q.worldedit.function.mask.BlockStateMask) WallMakeMask(com.fastasyncworldedit.core.function.mask.WallMakeMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) BoundedHeightMask(com.sk89q.worldedit.function.mask.BoundedHeightMask) ResettableMask(com.fastasyncworldedit.core.function.mask.ResettableMask) Mask(com.sk89q.worldedit.function.mask.Mask) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) RegionMask(com.sk89q.worldedit.function.mask.RegionMask) ExistingBlockMask(com.sk89q.worldedit.function.mask.ExistingBlockMask) DownwardVisitor(com.sk89q.worldedit.function.visitor.DownwardVisitor) BoundedHeightMask(com.sk89q.worldedit.function.mask.BoundedHeightMask) BlockReplace(com.sk89q.worldedit.function.block.BlockReplace) EllipsoidRegion(com.sk89q.worldedit.regions.EllipsoidRegion)

Aggregations

ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)1 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)1 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)1 BlockReplace (com.sk89q.worldedit.function.block.BlockReplace)1 BlockStateMask (com.sk89q.worldedit.function.mask.BlockStateMask)1 BlockTypeMask (com.sk89q.worldedit.function.mask.BlockTypeMask)1 BoundedHeightMask (com.sk89q.worldedit.function.mask.BoundedHeightMask)1 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)1 Mask (com.sk89q.worldedit.function.mask.Mask)1 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)1 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)1 DownwardVisitor (com.sk89q.worldedit.function.visitor.DownwardVisitor)1 RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)1 EllipsoidRegion (com.sk89q.worldedit.regions.EllipsoidRegion)1