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);
}
}
Aggregations