Search in sources :

Example 1 with RecursiveVisitor

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();
    }
}
Also used : Player(com.sk89q.worldedit.entity.Player) ClipboardHolder(com.sk89q.worldedit.session.ClipboardHolder) AbstractDelegateMask(com.fastasyncworldedit.core.function.mask.AbstractDelegateMask) Mask(com.sk89q.worldedit.function.mask.Mask) RecursiveVisitor(com.sk89q.worldedit.function.visitor.RecursiveVisitor) Operation(com.sk89q.worldedit.function.operation.Operation) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BaseBlock(com.sk89q.worldedit.world.block.BaseBlock) NullRegionFunction(com.fastasyncworldedit.core.function.NullRegionFunction) Actor(com.sk89q.worldedit.extension.platform.Actor) AffineTransform(com.sk89q.worldedit.math.transform.AffineTransform) ResizableClipboardBuilder(com.fastasyncworldedit.core.extent.clipboard.ResizableClipboardBuilder) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) AbstractDelegateMask(com.fastasyncworldedit.core.function.mask.AbstractDelegateMask) Location(com.sk89q.worldedit.util.Location)

Example 2 with RecursiveVisitor

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
}
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 3 with RecursiveVisitor

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;
}
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 4 with RecursiveVisitor

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);
}
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 5 with RecursiveVisitor

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

Aggregations

RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)11 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)6 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)6 BlockReplace (com.sk89q.worldedit.function.block.BlockReplace)5 Mask (com.sk89q.worldedit.function.mask.Mask)5 RadiusMask (com.fastasyncworldedit.core.function.mask.RadiusMask)3 ResettableMask (com.fastasyncworldedit.core.function.mask.ResettableMask)3 SingleBlockTypeMask (com.fastasyncworldedit.core.function.mask.SingleBlockTypeMask)3 SurfaceMask (com.fastasyncworldedit.core.function.mask.SurfaceMask)3 WallMakeMask (com.fastasyncworldedit.core.function.mask.WallMakeMask)3 EditSession (com.sk89q.worldedit.EditSession)3 BlockStateMask (com.sk89q.worldedit.function.mask.BlockStateMask)3 BlockTypeMask (com.sk89q.worldedit.function.mask.BlockTypeMask)3 BoundedHeightMask (com.sk89q.worldedit.function.mask.BoundedHeightMask)3 ExistingBlockMask (com.sk89q.worldedit.function.mask.ExistingBlockMask)3 RegionMask (com.sk89q.worldedit.function.mask.RegionMask)3 EllipsoidRegion (com.sk89q.worldedit.regions.EllipsoidRegion)3 BlockVectorSet (com.fastasyncworldedit.core.math.BlockVectorSet)2 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)2 Pattern (com.sk89q.worldedit.function.pattern.Pattern)2