Search in sources :

Example 1 with RadiusMask

use of com.fastasyncworldedit.core.function.mask.RadiusMask 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 2 with RadiusMask

use of com.fastasyncworldedit.core.function.mask.RadiusMask 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 3 with RadiusMask

use of com.fastasyncworldedit.core.function.mask.RadiusMask 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

RadiusMask (com.fastasyncworldedit.core.function.mask.RadiusMask)3 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)3 RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)3 SurfaceMask (com.fastasyncworldedit.core.function.mask.SurfaceMask)2 BlockVectorSet (com.fastasyncworldedit.core.math.BlockVectorSet)2 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)2 AdjacentAnyMask (com.fastasyncworldedit.core.function.mask.AdjacentAnyMask)1 LayerBrushMask (com.fastasyncworldedit.core.function.mask.LayerBrushMask)1 LocalBlockVectorSet (com.fastasyncworldedit.core.math.LocalBlockVectorSet)1 EditSession (com.sk89q.worldedit.EditSession)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 Brush (com.sk89q.worldedit.command.tool.brush.Brush)1 BlockMask (com.sk89q.worldedit.function.mask.BlockMask)1 SolidBlockMask (com.sk89q.worldedit.function.mask.SolidBlockMask)1 Operations (com.sk89q.worldedit.function.operation.Operations)1 Pattern (com.sk89q.worldedit.function.pattern.Pattern)1 BreadthFirstSearch (com.sk89q.worldedit.function.visitor.BreadthFirstSearch)1 BlockState (com.sk89q.worldedit.world.block.BlockState)1 BlockTypes (com.sk89q.worldedit.world.block.BlockTypes)1 Arrays (java.util.Arrays)1