public void process(GeneratingRegion region) {
Border3D borderForTreeFacet = region.getBorderForFacet(TreeFacet.class);
TreeFacet facet = new TreeFacet(region.getRegion(), borderForTreeFacet.extendBy(0, 15, 10));
SurfaceHeightFacet surface = region.getRegionFacet(SurfaceHeightFacet.class);
DensityFacet density = region.getRegionFacet(DensityFacet.class);
SeaLevelFacet seaLevel = region.getRegionFacet(SeaLevelFacet.class);
Rect2i worldRegion2D = Rect2i.createFromMinAndMax(facet.getWorldRegion().minX(),
facet.getWorldRegion().minZ(),
facet.getWorldRegion().maxX(),
facet.getWorldRegion().maxZ());
for (Vector2i pos : worldRegion2D) {
int x = pos.getX();
int z = pos.getY();
int height = TeraMath.floorToInt(surface.getWorld(x, z));
// if the surface is in range, and if we are above sea level
if (facet.getWorldRegion().encompasses(x, height, z) && facet.getWorldRegion().encompasses(x, height + 1, z) && height >= seaLevel.getSeaLevel()) {
// if the block on the surface is dense enough
if (density.getWorld(x, height, z) >= 0
&& density.getWorld(x, height + 1, z) < 0
// and if there is a level surface in adjacent directions