Search in sources :

Example 1 with CPUOptimizedClipboard

use of com.fastasyncworldedit.core.extent.clipboard.CPUOptimizedClipboard in project FastAsyncWorldEdit by IntellectualSites.

the class ErodeBrush method erosion.

public void erosion(final EditSession es, int erodeFaces, int erodeRecursion, int fillFaces, int fillRecursion, BlockVector3 target, double size) {
    int brushSize = (int) size;
    int brushSizeSquared = (int) (size * size);
    Location min = new Location(es.getWorld(), target.toVector3().subtract(size, size, size));
    Location max = new Location(es.getWorld(), target.toVector3().add(size, size, size));
    Region region = new CuboidRegion(es.getWorld(), min.toBlockPoint(), max.toBlockPoint());
    Clipboard buffer1 = new CPUOptimizedClipboard(region);
    Clipboard buffer2 = new CPUOptimizedClipboard(region);
    final int bx = target.getBlockX();
    final int by = target.getBlockY();
    final int bz = target.getBlockZ();
    for (int x = -brushSize, relx = 0; x <= brushSize; x++, relx++) {
        int x0 = x + bx;
        for (int y = -brushSize, rely = 0; y <= brushSize; y++, rely++) {
            int y0 = y + by;
            for (int z = -brushSize, relz = 0; z <= brushSize; z++, relz++) {
                int z0 = z + bz;
                BlockState state = es.getBlock(x0, y0, z0);
                buffer1.setBlock(relx, rely, relz, state);
                buffer2.setBlock(relx, rely, relz, state);
            }
        }
    }
    int swap = 0;
    for (int i = 0; i < erodeRecursion; ++i) {
        erosionIteration(brushSize, brushSizeSquared, erodeFaces, swap % 2 == 0 ? buffer1 : buffer2, swap % 2 == 1 ? buffer1 : buffer2);
        swap++;
    }
    for (int i = 0; i < fillRecursion; ++i) {
        fillIteration(brushSize, brushSizeSquared, fillFaces, swap % 2 == 0 ? buffer1 : buffer2, swap % 2 == 1 ? buffer1 : buffer2);
        swap++;
    }
    Clipboard finalBuffer = swap % 2 == 0 ? buffer1 : buffer2;
    for (BlockVector3 pos : finalBuffer) {
        BlockState block = pos.getBlock(finalBuffer);
        es.setBlock(pos.getX() + bx - brushSize, pos.getY() + by - brushSize, pos.getZ() + bz - brushSize, block);
    }
}
Also used : BlockState(com.sk89q.worldedit.world.block.BlockState) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) CPUOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.CPUOptimizedClipboard) BlockVector3(com.sk89q.worldedit.math.BlockVector3) Location(com.sk89q.worldedit.util.Location) CPUOptimizedClipboard(com.fastasyncworldedit.core.extent.clipboard.CPUOptimizedClipboard)

Aggregations

CPUOptimizedClipboard (com.fastasyncworldedit.core.extent.clipboard.CPUOptimizedClipboard)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 Region (com.sk89q.worldedit.regions.Region)1 Location (com.sk89q.worldedit.util.Location)1 BlockState (com.sk89q.worldedit.world.block.BlockState)1