Mgvalleys: Make river depth variation and humidity drop optional (#7532)
[oweals/minetest.git] / src / mapgen / mapgen.cpp
index 360afd89719f4143ca3a7afbf29584209e0a0160..7de367a27e4ce1079c813138414e6ff757c47a5f 100644 (file)
@@ -655,6 +655,7 @@ void MapgenBasic::generateBiomes()
        for (s16 z = node_min.Z; z <= node_max.Z; z++)
        for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
                Biome *biome = NULL;
+               biome_t water_biome_index = 0;
                u16 depth_top = 0;
                u16 base_filler = 0;
                u16 depth_water_top = 0;
@@ -697,6 +698,11 @@ void MapgenBasic::generateBiomes()
                                if (biomemap[index] == BIOME_NONE && is_stone_surface)
                                        biomemap[index] = biome->index;
 
+                               // Store biome of first water surface detected, as a fallback
+                               // entry for the biomemap.
+                               if (water_biome_index == 0 && is_water_surface)
+                                       water_biome_index = biome->index;
+
                                depth_top = biome->depth_top;
                                base_filler = MYMAX(depth_top +
                                        biome->depth_filler +
@@ -763,16 +769,11 @@ void MapgenBasic::generateBiomes()
 
                        VoxelArea::add_y(em, vi, -1);
                }
-               // If no stone surface was detected in this mapchunk column the biomemap
-               // will be empty for this (x, z) position. Add the currently active
-               // biome to the biomemap, or if biome is NULL calculate it for this
-               // position and add it.
-               if (biomemap[index] == BIOME_NONE) {
-                       if (!biome)
-                               biome = biomegen->getBiomeAtIndex(
-                                       index, v3s16(x, node_min.Y, z));
-                       biomemap[index] = biome->index;
-               }
+               // If no stone surface detected in mapchunk column and a water surface
+               // biome fallback exists, add it to the biomemap. This avoids water
+               // surface decorations failing in deep water.
+               if (biomemap[index] == BIOME_NONE && water_biome_index != 0)
+                       biomemap[index] = water_biome_index;
        }
 }