Source:
<code>public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double doubleSize) throws MaxChangedBlocksException { int size = (int) Math.ceil(doubleSize); int diameter = size * 2 + 1; BufferedImage resizedPattern = new BufferedImage(diameter, diameter, 1); Graphics2D graphic = null; try { graphic = resizedPattern.createGraphics(); graphic.drawImage(this.image, 0, 0, diameter, diameter, null); } finally { graphic.dispose(); } <START> double random = RANDOM.nextDouble(); <END> for (int offX = -size; offX <= size; offX++) { for (int offZ = -size; offZ <= size; offZ++) { int posX = position.getX() + offX; int posZ = position.getZ() + offZ; int posY = editSession.getHighestTerrainBlock(posX, posZ, 0, 255, editSession.getMask()); BlockVector3 block = BlockVector3.at(posX, posY, posZ); if (editSession.getMask() != null && !editSession.getMask().test(block)) { continue; } double height = getHeightAt(resizedPattern, offX + size, resizedPattern.getHeight() - 1 - (offZ + size)); if (random > 1 - height % 1) { height += 1; } BaseBlock baseBlock = fill ? editSession.getBlock(block).toBaseBlock() : null; for (int y = 0; y < height; y++) { if (fill) { if (!flat || block.getY() + y <= position.getY()) { editSession.setBlock(block.withY(block.getY() + y), baseBlock); } } else if ((!flat || block.getY() - y > position.getY()) && block.getY() - y >= 0 && (editSession.getMask() == null || editSession.getMask().test(block.withY(block.getY() - y)))) { editSession.setBlock(block.withY(block.getY() - y), BlockTypes.AIR.getDefaultState()); } } } } }</code><technical_language>This random feature a good candidate for another @Switch, I annoying for making exact replicas</technical_language>

Target:
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double doubleSize) throws MaxChangedBlocksException { int size = (int) Math.ceil(doubleSize); int diameter = size * 2 + 1; BufferedImage resizedPattern = new BufferedImage(diameter, diameter, 1); Graphics2D graphic = null; try { graphic = resizedPattern.createGraphics(); graphic.drawImage(this.image, 0, 0, diameter, diameter, null); } finally { graphic.dispose(); } double random = randomize ? RANDOM.nextDouble() : 0; for (int offX = -size; offX <= size; offX++) { for (int offZ = -size; offZ <= size; offZ++) { int posX = position.getX() + offX; int posZ = position.getZ() + offZ; int posY = editSession.getHighestTerrainBlock(posX, posZ, 0, 255, editSession.getMask()); BlockVector3 block = BlockVector3.at(posX, posY, posZ); if (editSession.getMask() != null && !editSession.getMask().test(block)) { continue; } double height = getHeightAt(resizedPattern, offX + size, resizedPattern.getHeight() - 1 - (offZ + size)); if (randomize && random > 1 - height % 1) { height += 1; } BaseBlock baseBlock = erase ? null : editSession.getBlock(block).toBaseBlock(); for (int y = 0; y < height; y++) { if (erase) { editSession.setBlock(block.withY(block.getY() - y), BlockTypes.AIR.getDefaultState()); } else if ((!flatten || block.getY() - y > position.getY()) && block.getY() - y >= 0) { if (!flatten || block.getY() + y <= position.getY()) { editSession.setBlock(block.withY(block.getY() + y), baseBlock); } } } } } }