]> git.lizzy.rs Git - minetest.git/blob - src/mapgen_flat.cpp
Fix inverted conditions in shader.cpp
[minetest.git] / src / mapgen_flat.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2015 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2010-2015 paramat, Matt Gregory
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21
22 #include "mapgen.h"
23 #include "voxel.h"
24 #include "noise.h"
25 #include "mapblock.h"
26 #include "mapnode.h"
27 #include "map.h"
28 #include "content_sao.h"
29 #include "nodedef.h"
30 #include "voxelalgorithms.h"
31 //#include "profiler.h" // For TimeTaker
32 #include "settings.h" // For g_settings
33 #include "emerge.h"
34 #include "dungeongen.h"
35 #include "cavegen.h"
36 #include "treegen.h"
37 #include "mg_biome.h"
38 #include "mg_ore.h"
39 #include "mg_decoration.h"
40 #include "mapgen_flat.h"
41
42
43 FlagDesc flagdesc_mapgen_flat[] = {
44         {"lakes", MGFLAT_LAKES},
45         {"hills", MGFLAT_HILLS},
46         {NULL,    0}
47 };
48
49 ///////////////////////////////////////////////////////////////////////////////////////
50
51
52 MapgenFlat::MapgenFlat(int mapgenid, MapgenParams *params, EmergeManager *emerge)
53         : Mapgen(mapgenid, params, emerge)
54 {
55         this->m_emerge = emerge;
56         this->bmgr     = emerge->biomemgr;
57
58         //// amount of elements to skip for the next index
59         //// for noise/height/biome maps (not vmanip)
60         this->ystride = csize.X;
61         this->zstride = csize.X * (csize.Y + 2);
62
63         this->biomemap        = new u8[csize.X * csize.Z];
64         this->heightmap       = new s16[csize.X * csize.Z];
65         this->heatmap         = NULL;
66         this->humidmap        = NULL;
67
68         MapgenFlatParams *sp = (MapgenFlatParams *)params->sparams;
69         this->spflags = sp->spflags;
70
71         this->ground_level = sp->ground_level;
72         this->large_cave_depth = sp->large_cave_depth;
73         this->lake_threshold = sp->lake_threshold;
74         this->lake_steepness = sp->lake_steepness;
75         this->hill_threshold = sp->hill_threshold;
76         this->hill_steepness = sp->hill_steepness;
77
78         //// 2D noise
79         noise_terrain      = new Noise(&sp->np_terrain,      seed, csize.X, csize.Z);
80         noise_filler_depth = new Noise(&sp->np_filler_depth, seed, csize.X, csize.Z);
81
82         //// 3D noise
83         noise_cave1 = new Noise(&sp->np_cave1, seed, csize.X, csize.Y + 2, csize.Z);
84         noise_cave2 = new Noise(&sp->np_cave2, seed, csize.X, csize.Y + 2, csize.Z);
85
86         //// Biome noise
87         noise_heat           = new Noise(&params->np_biome_heat,           seed, csize.X, csize.Z);
88         noise_humidity       = new Noise(&params->np_biome_humidity,       seed, csize.X, csize.Z);
89         noise_heat_blend     = new Noise(&params->np_biome_heat_blend,     seed, csize.X, csize.Z);
90         noise_humidity_blend = new Noise(&params->np_biome_humidity_blend, seed, csize.X, csize.Z);
91
92         //// Resolve nodes to be used
93         INodeDefManager *ndef = emerge->ndef;
94
95         c_stone                = ndef->getId("mapgen_stone");
96         c_water_source         = ndef->getId("mapgen_water_source");
97         c_lava_source          = ndef->getId("mapgen_lava_source");
98         c_desert_stone         = ndef->getId("mapgen_desert_stone");
99         c_ice                  = ndef->getId("mapgen_ice");
100         c_sandstone            = ndef->getId("mapgen_sandstone");
101
102         c_cobble               = ndef->getId("mapgen_cobble");
103         c_stair_cobble         = ndef->getId("mapgen_stair_cobble");
104         c_mossycobble          = ndef->getId("mapgen_mossycobble");
105         c_sandstonebrick       = ndef->getId("mapgen_sandstonebrick");
106         c_stair_sandstonebrick = ndef->getId("mapgen_stair_sandstonebrick");
107
108         if (c_ice == CONTENT_IGNORE)
109                 c_ice = CONTENT_AIR;
110         if (c_mossycobble == CONTENT_IGNORE)
111                 c_mossycobble = c_cobble;
112         if (c_stair_cobble == CONTENT_IGNORE)
113                 c_stair_cobble = c_cobble;
114         if (c_sandstonebrick == CONTENT_IGNORE)
115                 c_sandstonebrick = c_sandstone;
116         if (c_stair_sandstonebrick == CONTENT_IGNORE)
117                 c_stair_sandstonebrick = c_sandstone;
118 }
119
120
121 MapgenFlat::~MapgenFlat()
122 {
123         delete noise_terrain;
124         delete noise_filler_depth;
125         delete noise_cave1;
126         delete noise_cave2;
127
128         delete noise_heat;
129         delete noise_humidity;
130         delete noise_heat_blend;
131         delete noise_humidity_blend;
132
133         delete[] heightmap;
134         delete[] biomemap;
135 }
136
137
138 MapgenFlatParams::MapgenFlatParams()
139 {
140         spflags = 0;
141
142         ground_level = 8;
143         large_cave_depth = -33;
144         lake_threshold = -0.45;
145         lake_steepness = 48.0;
146         hill_threshold = 0.45;
147         hill_steepness = 64.0;
148
149         np_terrain      = NoiseParams(0, 1,   v3f(600, 600, 600), 7244,  5, 0.6, 2.0);
150         np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261,   3, 0.7, 2.0);
151         np_cave1        = NoiseParams(0, 12,  v3f(96,  96,  96),  52534, 4, 0.5, 2.0);
152         np_cave2        = NoiseParams(0, 12,  v3f(96,  96,  96),  10325, 4, 0.5, 2.0);
153 }
154
155
156 void MapgenFlatParams::readParams(const Settings *settings)
157 {
158         settings->getFlagStrNoEx("mgflat_spflags", spflags, flagdesc_mapgen_flat);
159
160         settings->getS16NoEx("mgflat_ground_level",     ground_level);
161         settings->getS16NoEx("mgflat_large_cave_depth", large_cave_depth);
162         settings->getFloatNoEx("mgflat_lake_threshold", lake_threshold);
163         settings->getFloatNoEx("mgflat_lake_steepness", lake_steepness);
164         settings->getFloatNoEx("mgflat_hill_threshold", hill_threshold);
165         settings->getFloatNoEx("mgflat_hill_steepness", hill_steepness);
166
167         settings->getNoiseParams("mgflat_np_terrain",      np_terrain);
168         settings->getNoiseParams("mgflat_np_filler_depth", np_filler_depth);
169         settings->getNoiseParams("mgflat_np_cave1",        np_cave1);
170         settings->getNoiseParams("mgflat_np_cave2",        np_cave2);
171 }
172
173
174 void MapgenFlatParams::writeParams(Settings *settings) const
175 {
176         settings->setFlagStr("mgflat_spflags", spflags, flagdesc_mapgen_flat, U32_MAX);
177
178         settings->setS16("mgflat_ground_level",     ground_level);
179         settings->setS16("mgflat_large_cave_depth", large_cave_depth);
180         settings->setFloat("mgflat_lake_threshold", lake_threshold);
181         settings->setFloat("mgflat_lake_steepness", lake_steepness);
182         settings->setFloat("mgflat_hill_threshold", hill_threshold);
183         settings->setFloat("mgflat_hill_steepness", hill_steepness);
184
185         settings->setNoiseParams("mgflat_np_terrain",      np_terrain);
186         settings->setNoiseParams("mgflat_np_filler_depth", np_filler_depth);
187         settings->setNoiseParams("mgflat_np_cave1",        np_cave1);
188         settings->setNoiseParams("mgflat_np_cave2",        np_cave2);
189 }
190
191
192 /////////////////////////////////////////////////////////////////
193
194
195 int MapgenFlat::getSpawnLevelAtPoint(v2s16 p)
196 {
197         s16 level_at_point = ground_level;
198         float n_terrain = NoisePerlin2D(&noise_terrain->np, p.X, p.Y, seed);
199
200         if ((spflags & MGFLAT_LAKES) && n_terrain < lake_threshold) {
201                 level_at_point = ground_level -
202                         (lake_threshold - n_terrain) * lake_steepness;
203         } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) {
204                 level_at_point = ground_level +
205                         (n_terrain - hill_threshold) * hill_steepness;
206         }
207
208         if (ground_level < water_level)  // Ocean world, allow spawn in water
209                 return MYMAX(level_at_point, water_level);
210         else if (level_at_point > water_level)
211                 return level_at_point;  // Spawn on land
212         else
213                 return MAX_MAP_GENERATION_LIMIT;  // Unsuitable spawn point
214 }
215
216
217 void MapgenFlat::makeChunk(BlockMakeData *data)
218 {
219         // Pre-conditions
220         assert(data->vmanip);
221         assert(data->nodedef);
222         assert(data->blockpos_requested.X >= data->blockpos_min.X &&
223                 data->blockpos_requested.Y >= data->blockpos_min.Y &&
224                 data->blockpos_requested.Z >= data->blockpos_min.Z);
225         assert(data->blockpos_requested.X <= data->blockpos_max.X &&
226                 data->blockpos_requested.Y <= data->blockpos_max.Y &&
227                 data->blockpos_requested.Z <= data->blockpos_max.Z);
228
229         this->generating = true;
230         this->vm   = data->vmanip;
231         this->ndef = data->nodedef;
232         //TimeTaker t("makeChunk");
233
234         v3s16 blockpos_min = data->blockpos_min;
235         v3s16 blockpos_max = data->blockpos_max;
236         node_min = blockpos_min * MAP_BLOCKSIZE;
237         node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
238         full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
239         full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
240
241         blockseed = getBlockSeed2(full_node_min, seed);
242
243         // Make some noise
244         calculateNoise();
245
246         // Generate base terrain, mountains, and ridges with initial heightmaps
247         s16 stone_surface_max_y = generateTerrain();
248
249         // Create heightmap
250         updateHeightmap(node_min, node_max);
251
252         // Create biomemap at heightmap surface
253         bmgr->calcBiomes(csize.X, csize.Z, noise_heat->result,
254                 noise_humidity->result, heightmap, biomemap);
255
256         // Actually place the biome-specific nodes
257         MgStoneType stone_type = generateBiomes(noise_heat->result, noise_humidity->result);
258
259         if (flags & MG_CAVES)
260                 generateCaves(stone_surface_max_y);
261
262         if ((flags & MG_DUNGEONS) && (stone_surface_max_y >= node_min.Y)) {
263                 DungeonParams dp;
264
265                 dp.np_rarity  = nparams_dungeon_rarity;
266                 dp.np_density = nparams_dungeon_density;
267                 dp.np_wetness = nparams_dungeon_wetness;
268                 dp.c_water    = c_water_source;
269                 if (stone_type == STONE) {
270                         dp.c_cobble = c_cobble;
271                         dp.c_moss   = c_mossycobble;
272                         dp.c_stair  = c_stair_cobble;
273
274                         dp.diagonal_dirs = false;
275                         dp.mossratio     = 3.0;
276                         dp.holesize      = v3s16(1, 2, 1);
277                         dp.roomsize      = v3s16(0, 0, 0);
278                         dp.notifytype    = GENNOTIFY_DUNGEON;
279                 } else if (stone_type == DESERT_STONE) {
280                         dp.c_cobble = c_desert_stone;
281                         dp.c_moss   = c_desert_stone;
282                         dp.c_stair  = c_desert_stone;
283
284                         dp.diagonal_dirs = true;
285                         dp.mossratio     = 0.0;
286                         dp.holesize      = v3s16(2, 3, 2);
287                         dp.roomsize      = v3s16(2, 5, 2);
288                         dp.notifytype    = GENNOTIFY_TEMPLE;
289                 } else if (stone_type == SANDSTONE) {
290                         dp.c_cobble = c_sandstonebrick;
291                         dp.c_moss   = c_sandstonebrick;
292                         dp.c_stair  = c_sandstonebrick;
293
294                         dp.diagonal_dirs = false;
295                         dp.mossratio     = 0.0;
296                         dp.holesize      = v3s16(2, 2, 2);
297                         dp.roomsize      = v3s16(2, 0, 2);
298                         dp.notifytype    = GENNOTIFY_DUNGEON;
299                 }
300
301                 DungeonGen dgen(this, &dp);
302                 dgen.generate(blockseed, full_node_min, full_node_max);
303         }
304
305         // Generate the registered decorations
306         if (flags & MG_DECORATIONS)
307                 m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
308
309         // Generate the registered ores
310         m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
311
312         // Sprinkle some dust on top after everything else was generated
313         dustTopNodes();
314
315         //printf("makeChunk: %dms\n", t.stop());
316
317         updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
318
319         if (flags & MG_LIGHT)
320                 calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
321                         full_node_min, full_node_max);
322
323         //setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
324         //                      node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
325
326         this->generating = false;
327 }
328
329
330 void MapgenFlat::calculateNoise()
331 {
332         //TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
333         s16 x = node_min.X;
334         s16 z = node_min.Z;
335
336         if ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS))
337                 noise_terrain->perlinMap2D(x, z);
338
339         // Cave noises are calculated in generateCaves()
340         // only if solid terrain is present in mapchunk
341
342         noise_filler_depth->perlinMap2D(x, z);
343         noise_heat->perlinMap2D(x, z);
344         noise_humidity->perlinMap2D(x, z);
345         noise_heat_blend->perlinMap2D(x, z);
346         noise_humidity_blend->perlinMap2D(x, z);
347
348         for (s32 i = 0; i < csize.X * csize.Z; i++) {
349                 noise_heat->result[i] += noise_heat_blend->result[i];
350                 noise_humidity->result[i] += noise_humidity_blend->result[i];
351         }
352
353         heatmap = noise_heat->result;
354         humidmap = noise_humidity->result;
355         //printf("calculateNoise: %dus\n", t.stop());
356 }
357
358
359 s16 MapgenFlat::generateTerrain()
360 {
361         MapNode n_air(CONTENT_AIR);
362         MapNode n_stone(c_stone);
363         MapNode n_water(c_water_source);
364
365         v3s16 em = vm->m_area.getExtent();
366         s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
367         u32 ni2d = 0;
368
369         for (s16 z = node_min.Z; z <= node_max.Z; z++)
370         for (s16 x = node_min.X; x <= node_max.X; x++, ni2d++) {
371                 s16 stone_level = ground_level;
372                 float n_terrain = 0.0f;
373
374                 if ((spflags & MGFLAT_LAKES) || (spflags & MGFLAT_HILLS))
375                         n_terrain = noise_terrain->result[ni2d];
376
377                 if ((spflags & MGFLAT_LAKES) && n_terrain < lake_threshold) {
378                         s16 depress = (lake_threshold - n_terrain) * lake_steepness;
379                         stone_level = ground_level - depress;
380                 } else if ((spflags & MGFLAT_HILLS) && n_terrain > hill_threshold) {
381                         s16 rise = (n_terrain - hill_threshold) * hill_steepness;
382                         stone_level = ground_level + rise;
383                 }
384
385                 u32 vi = vm->m_area.index(x, node_min.Y - 1, z);
386                 for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
387                         if (vm->m_data[vi].getContent() == CONTENT_IGNORE) {
388                                 if (y <= stone_level) {
389                                         vm->m_data[vi] = n_stone;
390                                         if (y > stone_surface_max_y)
391                                                 stone_surface_max_y = y;
392                                 } else if (y <= water_level) {
393                                         vm->m_data[vi] = n_water;
394                                 } else {
395                                         vm->m_data[vi] = n_air;
396                                 }
397                         }
398                         vm->m_area.add_y(em, vi, 1);
399                 }
400         }
401
402         return stone_surface_max_y;
403 }
404
405
406 MgStoneType MapgenFlat::generateBiomes(float *heat_map, float *humidity_map)
407 {
408         v3s16 em = vm->m_area.getExtent();
409         u32 index = 0;
410         MgStoneType stone_type = STONE;
411
412         for (s16 z = node_min.Z; z <= node_max.Z; z++)
413         for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
414                 Biome *biome = NULL;
415                 u16 depth_top = 0;
416                 u16 base_filler = 0;
417                 u16 depth_water_top = 0;
418                 u32 vi = vm->m_area.index(x, node_max.Y, z);
419
420                 // Check node at base of mapchunk above, either a node of a previously
421                 // generated mapchunk or if not, a node of overgenerated base terrain.
422                 content_t c_above = vm->m_data[vi + em.X].getContent();
423                 bool air_above = c_above == CONTENT_AIR;
424                 bool water_above = c_above == c_water_source;
425
426                 // If there is air or water above enable top/filler placement, otherwise force
427                 // nplaced to stone level by setting a number exceeding any possible filler depth.
428                 u16 nplaced = (air_above || water_above) ? 0 : U16_MAX;
429
430
431                 for (s16 y = node_max.Y; y >= node_min.Y; y--) {
432                         content_t c = vm->m_data[vi].getContent();
433
434                         // Biome is recalculated each time an upper surface is detected while
435                         // working down a column. The selected biome then remains in effect for
436                         // all nodes below until the next surface and biome recalculation.
437                         // Biome is recalculated:
438                         // 1. At the surface of stone below air or water.
439                         // 2. At the surface of water below air.
440                         // 3. When stone or water is detected but biome has not yet been calculated.
441                         if ((c == c_stone && (air_above || water_above || !biome)) ||
442                                         (c == c_water_source && (air_above || !biome))) {
443                                 biome = bmgr->getBiome(heat_map[index], humidity_map[index], y);
444                                 depth_top = biome->depth_top;
445                                 base_filler = MYMAX(depth_top + biome->depth_filler
446                                         + noise_filler_depth->result[index], 0);
447                                 depth_water_top = biome->depth_water_top;
448
449                                 // Detect stone type for dungeons during every biome calculation.
450                                 // This is more efficient than detecting per-node and will not
451                                 // miss any desert stone or sandstone biomes.
452                                 if (biome->c_stone == c_desert_stone)
453                                         stone_type = DESERT_STONE;
454                                 else if (biome->c_stone == c_sandstone)
455                                         stone_type = SANDSTONE;
456                         }
457
458                         if (c == c_stone) {
459                                 content_t c_below = vm->m_data[vi - em.X].getContent();
460
461                                 // If the node below isn't solid, make this node stone, so that
462                                 // any top/filler nodes above are structurally supported.
463                                 // This is done by aborting the cycle of top/filler placement
464                                 // immediately by forcing nplaced to stone level.
465                                 if (c_below == CONTENT_AIR || c_below == c_water_source)
466                                         nplaced = U16_MAX;
467
468                                 if (nplaced < depth_top) {
469                                         vm->m_data[vi] = MapNode(biome->c_top);
470                                         nplaced++;
471                                 } else if (nplaced < base_filler) {
472                                         vm->m_data[vi] = MapNode(biome->c_filler);
473                                         nplaced++;
474                                 } else {
475                                         vm->m_data[vi] = MapNode(biome->c_stone);
476                                 }
477
478                                 air_above = false;
479                                 water_above = false;
480                         } else if (c == c_water_source) {
481                                 vm->m_data[vi] = MapNode((y > (s32)(water_level - depth_water_top)) ?
482                                                 biome->c_water_top : biome->c_water);
483                                 nplaced = 0;  // Enable top/filler placement for next surface
484                                 air_above = false;
485                                 water_above = true;
486                         } else if (c == CONTENT_AIR) {
487                                 nplaced = 0;  // Enable top/filler placement for next surface
488                                 air_above = true;
489                                 water_above = false;
490                         } else {  // Possible various nodes overgenerated from neighbouring mapchunks
491                                 nplaced = U16_MAX;  // Disable top/filler placement
492                                 air_above = false;
493                                 water_above = false;
494                         }
495
496                         vm->m_area.add_y(em, vi, -1);
497                 }
498         }
499
500         return stone_type;
501 }
502
503
504 void MapgenFlat::dustTopNodes()
505 {
506         if (node_max.Y < water_level)
507                 return;
508
509         v3s16 em = vm->m_area.getExtent();
510         u32 index = 0;
511
512         for (s16 z = node_min.Z; z <= node_max.Z; z++)
513         for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
514                 Biome *biome = (Biome *)bmgr->getRaw(biomemap[index]);
515
516                 if (biome->c_dust == CONTENT_IGNORE)
517                         continue;
518
519                 u32 vi = vm->m_area.index(x, full_node_max.Y, z);
520                 content_t c_full_max = vm->m_data[vi].getContent();
521                 s16 y_start;
522
523                 if (c_full_max == CONTENT_AIR) {
524                         y_start = full_node_max.Y - 1;
525                 } else if (c_full_max == CONTENT_IGNORE) {
526                         vi = vm->m_area.index(x, node_max.Y + 1, z);
527                         content_t c_max = vm->m_data[vi].getContent();
528
529                         if (c_max == CONTENT_AIR)
530                                 y_start = node_max.Y;
531                         else
532                                 continue;
533                 } else {
534                         continue;
535                 }
536
537                 vi = vm->m_area.index(x, y_start, z);
538                 for (s16 y = y_start; y >= node_min.Y - 1; y--) {
539                         if (vm->m_data[vi].getContent() != CONTENT_AIR)
540                                 break;
541
542                         vm->m_area.add_y(em, vi, -1);
543                 }
544
545                 content_t c = vm->m_data[vi].getContent();
546                 if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE && c != biome->c_dust) {
547                         vm->m_area.add_y(em, vi, 1);
548                         vm->m_data[vi] = MapNode(biome->c_dust);
549                 }
550         }
551 }
552
553
554 void MapgenFlat::generateCaves(s16 max_stone_y)
555 {
556         if (max_stone_y < node_min.Y)
557                 return;
558
559         noise_cave1->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
560         noise_cave2->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
561
562         v3s16 em = vm->m_area.getExtent();
563         u32 index2d = 0;
564
565         for (s16 z = node_min.Z; z <= node_max.Z; z++)
566         for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
567                 bool column_is_open = false;  // Is column open to overground
568                 u32 vi = vm->m_area.index(x, node_max.Y + 1, z);
569                 u32 index3d = (z - node_min.Z) * zstride + (csize.Y + 1) * ystride +
570                         (x - node_min.X);
571                 // Biome of column
572                 Biome *biome = (Biome *)bmgr->getRaw(biomemap[index2d]);
573
574                 for (s16 y = node_max.Y + 1; y >= node_min.Y - 1;
575                                 y--, index3d -= ystride, vm->m_area.add_y(em, vi, -1)) {
576                         content_t c = vm->m_data[vi].getContent();
577                         if (c == CONTENT_AIR || c == biome->c_water_top ||
578                                         c == biome->c_water) {
579                                 column_is_open = true;
580                                 continue;
581                         }
582                         // Ground
583                         float d1 = contour(noise_cave1->result[index3d]);
584                         float d2 = contour(noise_cave2->result[index3d]);
585                         if (d1 * d2 > 0.3f && ndef->get(c).is_ground_content) {
586                                 // In tunnel and ground content, excavate
587                                 vm->m_data[vi] = MapNode(CONTENT_AIR);
588                         } else if (column_is_open &&
589                                         (c == biome->c_filler || c == biome->c_stone)) {
590                                 // Tunnel entrance floor
591                                 vm->m_data[vi] = MapNode(biome->c_top);
592                                 column_is_open = false;
593                         } else {
594                                 column_is_open = false;
595                         }
596                 }
597         }
598
599         if (node_max.Y > large_cave_depth)
600                 return;
601
602         PseudoRandom ps(blockseed + 21343);
603         u32 bruises_count = ps.range(0, 2);
604         for (u32 i = 0; i < bruises_count; i++) {
605                 CaveV5 cave(this, &ps);
606                 cave.makeCave(node_min, node_max, max_stone_y);
607         }
608 }