Search in sources :

Example 1 with LocalBlockVectorSet

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

the class SnapshotRestore method checkAndAddBlock.

private void checkAndAddBlock(BlockVector3 pos) {
    if (editSession.getMask() != null && !editSession.getMask().test(pos)) {
        return;
    }
    BlockVector2 chunkPos = ChunkStore.toChunk(pos);
    // Unidentified chunk
    if (!neededChunks.containsKey(chunkPos)) {
        neededChunks.put(chunkPos, new LocalBlockVectorSet());
    }
    neededChunks.get(chunkPos).add(pos);
}
Also used : LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) BlockVector2(com.sk89q.worldedit.math.BlockVector2)

Example 2 with LocalBlockVectorSet

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

the class EditSession method getHollowed.

// FAWE end
public Set<BlockVector3> getHollowed(Set<BlockVector3> vset) {
    final Set<BlockVector3> returnset = new LocalBlockVectorSet();
    final LocalBlockVectorSet newset = new LocalBlockVectorSet();
    newset.addAll(vset);
    for (BlockVector3 v : newset) {
        final int x = v.getX();
        final int y = v.getY();
        final int z = v.getZ();
        if (!(newset.contains(x + 1, y, z) && newset.contains(x - 1, y, z) && newset.contains(x, y + 1, z) && newset.contains(x, y - 1, z) && newset.contains(x, y, z + 1) && newset.contains(x, y, z - 1))) {
            returnset.add(v);
        }
    }
    return returnset;
}
Also used : LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 3 with LocalBlockVectorSet

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

the class EditSession method drawSpline.

/**
 * Draws a spline (out of blocks) between specified vectors.
 *
 * @param pattern     The block pattern used to draw the spline.
 * @param nodevectors The list of vectors to draw through.
 * @param tension     The tension of every node.
 * @param bias        The bias of every node.
 * @param continuity  The continuity of every node.
 * @param quality     The quality of the spline. Must be greater than 0.
 * @param radius      The radius (thickness) of the spline.
 * @param filled      If false, only a shell will be generated.
 * @return number of blocks affected
 * @throws MaxChangedBlocksException thrown if too many blocks are changed
 */
public int drawSpline(Pattern pattern, List<BlockVector3> nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled) throws MaxChangedBlocksException {
    LocalBlockVectorSet vset = new LocalBlockVectorSet();
    List<Node> nodes = new ArrayList<>(nodevectors.size());
    Interpolation interpol = new KochanekBartelsInterpolation();
    for (BlockVector3 nodevector : nodevectors) {
        Node n = new Node(nodevector.toVector3());
        n.setTension(tension);
        n.setBias(bias);
        n.setContinuity(continuity);
        nodes.add(n);
    }
    interpol.setNodes(nodes);
    double splinelength = interpol.arcLength(0, 1);
    for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) {
        BlockVector3 tipv = interpol.getPosition(loop).toBlockPoint();
        if (radius == 0) {
            pattern.apply(this, tipv, tipv);
            changes++;
        } else {
            vset.add(tipv);
        }
    }
    Set<BlockVector3> newVset;
    if (radius != 0) {
        newVset = getBallooned(vset, radius);
        if (!filled) {
            newVset = this.getHollowed(newVset);
        }
        return this.changes += setBlocks(newVset, pattern);
    }
    return changes;
}
Also used : KochanekBartelsInterpolation(com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation) Interpolation(com.sk89q.worldedit.math.interpolation.Interpolation) LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) Node(com.sk89q.worldedit.math.interpolation.Node) KochanekBartelsInterpolation(com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation) ArrayList(java.util.ArrayList) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) BlockVector3(com.sk89q.worldedit.math.BlockVector3)

Example 4 with LocalBlockVectorSet

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

the class BlockVector3Set method getAppropriateVectorSet.

static BlockVector3Set getAppropriateVectorSet(Region region) {
    BlockVector3 max = region.getMaximumPoint();
    BlockVector3 min = region.getMinimumPoint();
    BlockVector3 size = region.getDimensions();
    if (size.getBlockX() > 2048 || size.getBlockZ() > 2048 || size.getBlockY() > 512) {
        return new BlockVectorSet();
    } else {
        // Set default offset as many operations utilising a region are likely to start in a corner, this initialising the
        // LocalBlockVectorSet poorly
        // This needs to be ceiling as LocalBlockVector extends 1 block further "negative"
        int offsetX = (int) Math.ceil((min.getX() + max.getX()) / 2d);
        int offsetZ = (int) Math.ceil((min.getZ() + max.getZ()) / 2d);
        int offsetY;
        if (region.getMinimumY() < -128 || region.getMaximumY() > 320) {
            offsetY = (min.getY() + max.getY()) / 2;
        } else {
            offsetY = 128;
        }
        return new LocalBlockVectorSet(offsetX, offsetY, offsetZ);
    }
}
Also used : LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) BlockVector3(com.sk89q.worldedit.math.BlockVector3) LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) BlockVectorSet(com.fastasyncworldedit.core.math.BlockVectorSet)

Example 5 with LocalBlockVectorSet

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

the class ShatterBrush method finish.

@Override
public void finish(EditSession editSession, LocalBlockVectorSet placed, final BlockVector3 position, Pattern pattern, double size) {
    int radius2 = (int) (size * size);
    // Individual frontier for each point
    LocalBlockVectorSet[] frontiers = new LocalBlockVectorSet[placed.size()];
    // Keep track of where each frontier has visited
    LocalBlockVectorSet[] frontiersVisited = new LocalBlockVectorSet[placed.size()];
    // Initiate the frontier with the starting points
    int i = 0;
    for (BlockVector3 pos : placed) {
        LocalBlockVectorSet set = new LocalBlockVectorSet();
        set.add(pos);
        frontiers[i] = set;
        frontiersVisited[i] = set.clone();
        i++;
    }
    // Mask
    Mask mask = editSession.getMask();
    if (mask == null) {
        mask = Masks.alwaysTrue();
    }
    final Mask finalMask = mask;
    final SurfaceMask surfaceTest = new SurfaceMask(editSession);
    // Expand
    boolean notEmpty = true;
    // Keep track of where we've visited
    LocalBlockVectorSet tmp = new LocalBlockVectorSet();
    while (notEmpty) {
        notEmpty = false;
        for (i = 0; i < frontiers.length; i++) {
            LocalBlockVectorSet frontier = frontiers[i];
            notEmpty |= !frontier.isEmpty();
            final LocalBlockVectorSet frontierVisited = frontiersVisited[i];
            // This is a temporary set with the next blocks the frontier will visit
            final LocalBlockVectorSet finalTmp = tmp;
            frontier.forEach((x, y, z, index) -> {
                if (ThreadLocalRandom.current().nextInt(2) == 0) {
                    finalTmp.add(x, y, z);
                    return;
                }
                for (int i1 = 0; i1 < BreadthFirstSearch.DIAGONAL_DIRECTIONS.length; i1++) {
                    BlockVector3 direction = BreadthFirstSearch.DIAGONAL_DIRECTIONS[i1];
                    int x2 = x + direction.getBlockX();
                    int y2 = y + direction.getBlockY();
                    int z2 = z + direction.getBlockZ();
                    // Check boundary
                    int dx = position.getBlockX() - x2;
                    int dy = position.getBlockY() - y2;
                    int dz = position.getBlockZ() - z2;
                    int dSqr = (dx * dx) + (dy * dy) + (dz * dz);
                    if (dSqr <= radius2) {
                        BlockVector3 bv = mutable.setComponents(x2, y2, z2);
                        if (surfaceTest.test(bv) && finalMask.test(bv)) {
                            // (collision) If it's visited and part of another frontier, set the block
                            if (!placed.add(x2, y2, z2)) {
                                if (!frontierVisited.contains(x2, y2, z2)) {
                                    editSession.setBlock(x2, y2, z2, pattern);
                                }
                            } else {
                                // Hasn't visited and not a collision = add it
                                finalTmp.add(x2, y2, z2);
                                frontierVisited.add(x2, y2, z2);
                            }
                        }
                    }
                }
            });
            // Swap the frontier with the temporary set
            frontiers[i] = tmp;
            tmp = frontier;
            tmp.clear();
        }
    }
}
Also used : LocalBlockVectorSet(com.fastasyncworldedit.core.math.LocalBlockVectorSet) Mask(com.sk89q.worldedit.function.mask.Mask) SurfaceMask(com.fastasyncworldedit.core.function.mask.SurfaceMask) BlockVector3(com.sk89q.worldedit.math.BlockVector3) MutableBlockVector3(com.fastasyncworldedit.core.math.MutableBlockVector3) SurfaceMask(com.fastasyncworldedit.core.function.mask.SurfaceMask)

Aggregations

LocalBlockVectorSet (com.fastasyncworldedit.core.math.LocalBlockVectorSet)12 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)11 MutableBlockVector3 (com.fastasyncworldedit.core.math.MutableBlockVector3)8 SurfaceMask (com.fastasyncworldedit.core.function.mask.SurfaceMask)2 BlockVectorSet (com.fastasyncworldedit.core.math.BlockVectorSet)2 KochanekBartelsInterpolation (com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation)2 Node (com.sk89q.worldedit.math.interpolation.Node)2 ArrayList (java.util.ArrayList)2 RadiusMask (com.fastasyncworldedit.core.function.mask.RadiusMask)1 Mask (com.sk89q.worldedit.function.mask.Mask)1 MaskIntersection (com.sk89q.worldedit.function.mask.MaskIntersection)1 RecursiveVisitor (com.sk89q.worldedit.function.visitor.RecursiveVisitor)1 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)1 Vector3 (com.sk89q.worldedit.math.Vector3)1 Interpolation (com.sk89q.worldedit.math.interpolation.Interpolation)1 BlockState (com.sk89q.worldedit.world.block.BlockState)1 BlockType (com.sk89q.worldedit.world.block.BlockType)1