Search in sources :

Example 6 with MaskIntersection

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
}
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)

Example 7 with MaskIntersection

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;
}
Also used : BlockVectorSet(com.fastasyncworldedit.core.math.BlockVectorSet) EditSession(com.sk89q.worldedit.EditSession) Arrays(java.util.Arrays) BlockTypes(com.sk89q.worldedit.world.block.BlockTypes) BlockVector3(com.sk89q.worldedit.math.BlockVector3) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) AdjacentAnyMask(com.fastasyncworldedit.core.function.mask.AdjacentAnyMask) BlockMask(com.sk89q.worldedit.function.mask.BlockMask) RadiusMask(com.fastasyncworldedit.core.function.mask.RadiusMask) BreadthFirstSearch(com.sk89q.worldedit.function.visitor.BreadthFirstSearch) LayerBrushMask(com.fastasyncworldedit.core.function.mask.LayerBrushMask) MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) Brush(com.sk89q.worldedit.command.tool.brush.Brush) Operations(com.sk89q.worldedit.function.operation.Operations) BlockState(com.sk89q.worldedit.world.block.BlockState) Pattern(com.sk89q.worldedit.function.pattern.Pattern) Pattern(com.sk89q.worldedit.function.pattern.Pattern) MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) BlockMask(com.sk89q.worldedit.function.mask.BlockMask) RadiusMask(com.fastasyncworldedit.core.function.mask.RadiusMask) LayerBrushMask(com.fastasyncworldedit.core.function.mask.LayerBrushMask) SolidBlockMask(com.sk89q.worldedit.function.mask.SolidBlockMask) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) BlockVector3(com.sk89q.worldedit.math.BlockVector3) AdjacentAnyMask(com.fastasyncworldedit.core.function.mask.AdjacentAnyMask) BlockVectorSet(com.fastasyncworldedit.core.math.BlockVectorSet)

Example 8 with MaskIntersection

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);
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) RadiusMask(com.fastasyncworldedit.core.function.mask.RadiusMask) LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVectorSet(com.fastasyncworldedit.core.math.BlockVectorSet) LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) SurfaceMask(com.fastasyncworldedit.core.function.mask.SurfaceMask)

Example 9 with MaskIntersection

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;
}
Also used : DFSRecursiveVisitor(com.fastasyncworldedit.core.function.visitor.DFSRecursiveVisitor) MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) Node(com.sk89q.worldedit.math.interpolation.Node) IdMask(com.fastasyncworldedit.core.function.mask.IdMask) Mask(com.sk89q.worldedit.function.mask.Mask) ArrayList(java.util.ArrayList) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Vector3(com.sk89q.worldedit.math.Vector3) MutableVector3(com.fastasyncworldedit.core.math.MutableVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3) IdMask(com.fastasyncworldedit.core.function.mask.IdMask)

Example 10 with MaskIntersection

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);
}
Also used : MaskIntersection(com.sk89q.worldedit.function.mask.MaskIntersection) RadiusMask(com.fastasyncworldedit.core.function.mask.RadiusMask) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) SurfaceMask(com.fastasyncworldedit.core.function.mask.SurfaceMask)

Aggregations

MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)14 Mask (com.sk89q.worldedit.function.mask.Mask)11 ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)7 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)7 RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)5 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)5 BlockStateMask (com.sk89q.worldedit.function.mask.BlockStateMask)5 BlockTypeMask (com.sk89q.worldedit.function.mask.BlockTypeMask)5 BoundedHeightMask (com.sk89q.worldedit.function.mask.BoundedHeightMask)5 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)5 BlockReplace (com.sk89q.worldedit.function.block.BlockReplace)4 SolidBlockMask (com.sk89q.worldedit.function.mask.SolidBlockMask)4 EllipsoidRegion (com.sk89q.worldedit.regions.EllipsoidRegion)4 RadiusMask (com.fastasyncworldedit.core.function.mask.RadiusMask)3 MaskUnion (com.fastasyncworldedit.core.function.mask.MaskUnion)2 SurfaceMask (com.fastasyncworldedit.core.function.mask.SurfaceMask)2 BlockVectorSet (com.fastasyncworldedit.core.math.BlockVectorSet)2 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)2