Search in sources :

Example 1 with BlockVectorSet

use of com.fastasyncworldedit.core.math.BlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.

the class AbstractRegion method getChunkCubes.

@Override
public Set<BlockVector3> getChunkCubes() {
    final Set<BlockVector3> chunks = new BlockVectorSet();
    final BlockVector3 min = getMinimumPoint();
    final BlockVector3 max = getMaximumPoint();
    for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
        for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
            for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
                if (!contains(BlockVector3.at(x, y, z))) {
                    continue;
                }
                chunks.add(BlockVector3.at(x >> ChunkStore.CHUNK_SHIFTS, y >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS));
            }
        }
    }
    return chunks;
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVectorSet(com.fastasyncworldedit.core.math.BlockVectorSet)

Example 2 with BlockVectorSet

use of com.fastasyncworldedit.core.math.BlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.

the class CuboidRegion method getChunkCubes.

// FAWE end
@Override
public Set<BlockVector3> getChunkCubes() {
    // FAWE start - BlockVectorSet instead of HashMap
    Set<BlockVector3> chunks = new BlockVectorSet();
    // FAWE end
    BlockVector3 min = getMinimumPoint();
    BlockVector3 max = getMaximumPoint();
    for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) {
        for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) {
            for (int y = min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y <= max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; ++y) {
                chunks.add(BlockVector3.at(x, y, z));
            }
        }
    }
    return chunks;
}
Also used : BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVectorSet(com.fastasyncworldedit.core.math.BlockVectorSet)

Example 3 with BlockVectorSet

use of com.fastasyncworldedit.core.math.BlockVectorSet 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 BlockVectorSet

use of com.fastasyncworldedit.core.math.BlockVectorSet 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 BlockVectorSet

use of com.fastasyncworldedit.core.math.BlockVectorSet in project FastAsyncWorldEdit by IntellectualSites.

the class BreadthFirstSearch method resume.

@Override
public Operation resume(RunContext run) throws WorldEditException {
    // FAWE start - directions, visited and preloading
    MutableBlockVector3 mutable = new MutableBlockVector3();
    BlockVector3[] dirs = directions;
    BlockVectorSet tempQueue = new BlockVectorSet();
    BlockVectorSet chunkLoadSet = new BlockVectorSet();
    for (currentDepth = 0; !queue.isEmpty() && currentDepth <= maxDepth; currentDepth++) {
        int loadCount = 0;
        if (singleQueue != null && Settings.settings().QUEUE.PRELOAD_CHUNK_COUNT > 1) {
            int cx = Integer.MIN_VALUE;
            int cz = Integer.MIN_VALUE;
            outer: for (BlockVector3 from : queue) {
                for (BlockVector3 direction : dirs) {
                    if (loadCount > Settings.settings().QUEUE.PRELOAD_CHUNK_COUNT) {
                        break outer;
                    }
                    int x = from.getBlockX() + direction.getBlockX();
                    int z = from.getBlockZ() + direction.getBlockX();
                    if (cx != (cx = x >> 4) || cz != (cz = z >> 4)) {
                        int y = from.getBlockY() + direction.getBlockY();
                        if (y < singleQueue.getMinY() || y > singleQueue.getMaxY()) {
                            continue;
                        }
                        if (!visited.contains(x, y, z)) {
                            loadCount++;
                            chunkLoadSet.add(cx, 0, cz);
                        }
                    }
                }
            }
            for (BlockVector3 chunk : chunkLoadSet) {
                singleQueue.addChunkLoad(chunk.getBlockX(), chunk.getBlockZ());
            }
        }
        for (BlockVector3 from : queue) {
            if (function.apply(from)) {
                affected++;
            }
            for (int i = 0, j = 0; i < dirs.length && j < maxBranch; i++) {
                BlockVector3 direction = dirs[i];
                int y = from.getBlockY() + direction.getY();
                if (y < minY || y > maxY) {
                    continue;
                }
                int x = from.getBlockX() + direction.getX();
                int z = from.getBlockZ() + direction.getZ();
                if (!visited.contains(x, y, z)) {
                    if (isVisitable(from, mutable.setComponents(x, y, z))) {
                        j++;
                        visited.add(x, y, z);
                        tempQueue.add(x, y, z);
                    }
                }
            }
        }
        if (currentDepth == maxDepth) {
            break;
        }
        BlockVectorSet tmp = queue;
        queue = tempQueue;
        tmp.clear();
        tempQueue = tmp;
    }
    return null;
}
Also used : MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVectorSet(com.fastasyncworldedit.core.math.BlockVectorSet)

Aggregations

BlockVectorSet (com.fastasyncworldedit.core.math.BlockVectorSet)5 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)5 RadiusMask (com.fastasyncworldedit.core.function.mask.RadiusMask)2 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)2 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)2 RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)2 AdjacentAnyMask (com.fastasyncworldedit.core.function.mask.AdjacentAnyMask)1 LayerBrushMask (com.fastasyncworldedit.core.function.mask.LayerBrushMask)1 SurfaceMask (com.fastasyncworldedit.core.function.mask.SurfaceMask)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