public static int getSurfaceBlockY(World world, int x, int z) {
int y = world.getChunkFromBlockCoords(x, z).getTopFilledSegment() + 16;
Block block;
do {
if (--y <= 0) {
break;
}
block = world.getBlock(x, y, z);
} while (block.isAir(world, x, y, z) || block.isReplaceable(world, x, y, z) || block.isLeaves(world, x, y, z)
|| block.isFoliage(world, x, y, z) || block.canBeReplacedByLeaves(world, x, y, z));
return y;
}