protected void Erosion(EditHelper editSession, int brushSize, int erodeFaces, int erodeRec, int fillFaces, int fillRec, Level level, BlockCoordinates targetBlock) { double brushSizeSquared = brushSize * brushSize; int tx = targetBlock.X; int ty = targetBlock.Y; int tz = targetBlock.Z; BlockBuffer buffer1 = new BlockBuffer(); BlockBuffer buffer2 = new BlockBuffer(); for (int x = -brushSize - 1; x <= brushSize + 1; x++) { int x0 = x + tx; for (int y = -brushSize - 1; y <= brushSize + 1; y++) { int y0 = y + ty; for (int z = -brushSize - 1; z <= brushSize + 1; z++) { int z0 = z + tz; var block = level.GetBlock(new BlockCoordinates(x0, y0, z0)); buffer1[new BlockCoordinates(x, y, z)] = block; buffer2[new BlockCoordinates(x, y, z)] = block; } } } int swap = 0; for (int i = 0; i < erodeRec; ++i) { ErosionIteration(brushSize, erodeFaces, swap % 2 == 0 ? buffer1 : buffer2, swap % 2 == 1 ? buffer1 : buffer2); swap++; } for (int i = 0; i < fillRec; ++i) { FillIteration(brushSize, fillFaces, swap % 2 == 0 ? buffer1 : buffer2, swap % 2 == 1 ? buffer1 : buffer2); swap++; } BlockBuffer finalBuffer = swap % 2 == 0 ? buffer1 : buffer2; // apply the buffer to the world for (int x = -brushSize; x <= brushSize; x++) { int x0 = x + tx; for (int y = -brushSize; y <= brushSize; y++) { int y0 = y + ty; for (int z = -brushSize; z <= brushSize; z++) { int z0 = z + tz; var coord = new BlockCoordinates(x, y, z); if (x * x + y * y + z * z <= brushSizeSquared && finalBuffer.ContainsKey(coord)) { var block = finalBuffer[coord]; block.Coordinates = new BlockCoordinates(x0, y0, z0); Block old = level.GetBlock(block.Coordinates); if (block.Id == old.Id && block.Metadata == old.Metadata) { continue; } editSession.SetBlock(block); } } } } }