3 Copyright (C) 2010-2013 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "content_sao.h"
29 #include "voxelalgorithms.h"
31 #include "settings.h" // For g_settings
32 #include "main.h" // For g_profiler
34 #include "dungeongen.h"
38 #include "mapgen_v7.h"
41 FlagDesc flagdesc_mapgen_v7[] = {
42 {"v7_mountains", MGV7_MOUNTAINS},
43 {"v7_ridges", MGV7_RIDGES},
47 ///////////////////////////////////////////////////////////////////////////////
50 MapgenV7::MapgenV7(int mapgenid, MapgenParams *params, EmergeManager *emerge) {
51 this->generating = false;
53 this->emerge = emerge;
54 this->bmgr = emerge->biomedef;
56 this->seed = (int)params->seed;
57 this->water_level = params->water_level;
58 this->flags = params->flags | MGV7_MOUNTAINS | MGV7_RIDGES;
59 this->gennotify = emerge->gennotify;
61 this->csize = v3s16(1, 1, 1) * params->chunksize * MAP_BLOCKSIZE;
63 // amount of elements to skip for the next index
64 // for noise/height/biome maps (not vmanip)
65 this->ystride = csize.X;
66 this->zstride = csize.X * csize.Y;
68 this->biomemap = new u8[csize.X * csize.Z];
69 this->heightmap = new s16[csize.X * csize.Z];
70 this->ridge_heightmap = new s16[csize.X * csize.Z];
72 MapgenV7Params *sp = (MapgenV7Params *)params->sparams;
75 noise_terrain_base = new Noise(&sp->np_terrain_base, seed, csize.X, csize.Z);
76 noise_terrain_alt = new Noise(&sp->np_terrain_alt, seed, csize.X, csize.Z);
77 noise_terrain_persist = new Noise(&sp->np_terrain_persist, seed, csize.X, csize.Z);
78 noise_height_select = new Noise(&sp->np_height_select, seed, csize.X, csize.Z);
79 noise_filler_depth = new Noise(&sp->np_filler_depth, seed, csize.X, csize.Z);
80 noise_mount_height = new Noise(&sp->np_mount_height, seed, csize.X, csize.Z);
81 noise_ridge_uwater = new Noise(&sp->np_ridge_uwater, seed, csize.X, csize.Z);
84 noise_mountain = new Noise(&sp->np_mountain, seed, csize.X, csize.Y, csize.Z);
85 noise_ridge = new Noise(&sp->np_ridge, seed, csize.X, csize.Y, csize.Z);
88 noise_heat = new Noise(bmgr->np_heat, seed, csize.X, csize.Z);
89 noise_humidity = new Noise(bmgr->np_humidity, seed, csize.X, csize.Z);
93 MapgenV7::~MapgenV7() {
94 delete noise_terrain_base;
95 delete noise_terrain_persist;
96 delete noise_height_select;
97 delete noise_terrain_alt;
98 delete noise_filler_depth;
99 delete noise_mount_height;
100 delete noise_ridge_uwater;
101 delete noise_mountain;
105 delete noise_humidity;
107 delete[] ridge_heightmap;
113 MapgenV7Params::MapgenV7Params() {
114 spflags = MGV7_MOUNTAINS | MGV7_RIDGES;
116 np_terrain_base = NoiseParams(4, 70, v3f(300, 300, 300), 82341, 6, 0.7);
117 np_terrain_alt = NoiseParams(4, 25, v3f(600, 600, 600), 5934, 5, 0.6);
118 np_terrain_persist = NoiseParams(0.6, 0.1, v3f(500, 500, 500), 539, 3, 0.6);
119 np_height_select = NoiseParams(-0.5, 1, v3f(250, 250, 250), 4213, 5, 0.69);
120 np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261, 4, 0.7);
121 np_mount_height = NoiseParams(100, 30, v3f(500, 500, 500), 72449, 4, 0.6);
122 np_ridge_uwater = NoiseParams(0, 1, v3f(500, 500, 500), 85039, 4, 0.6);
123 np_mountain = NoiseParams(0, 1, v3f(250, 350, 250), 5333, 5, 0.68);
124 np_ridge = NoiseParams(0, 1, v3f(100, 100, 100), 6467, 4, 0.75);
128 void MapgenV7Params::readParams(Settings *settings) {
129 settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
131 settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base);
132 settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
133 settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
134 settings->getNoiseParams("mgv7_np_height_select", np_height_select);
135 settings->getNoiseParams("mgv7_np_filler_depth", np_filler_depth);
136 settings->getNoiseParams("mgv7_np_mount_height", np_mount_height);
137 settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
138 settings->getNoiseParams("mgv7_np_mountain", np_mountain);
139 settings->getNoiseParams("mgv7_np_ridge", np_ridge);
143 void MapgenV7Params::writeParams(Settings *settings) {
144 settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7);
146 settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base);
147 settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
148 settings->setNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
149 settings->setNoiseParams("mgv7_np_height_select", np_height_select);
150 settings->setNoiseParams("mgv7_np_filler_depth", np_filler_depth);
151 settings->setNoiseParams("mgv7_np_mount_height", np_mount_height);
152 settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
153 settings->setNoiseParams("mgv7_np_mountain", np_mountain);
154 settings->setNoiseParams("mgv7_np_ridge", np_ridge);
158 ///////////////////////////////////////
161 int MapgenV7::getGroundLevelAtPoint(v2s16 p) {
162 // Base terrain calculation
163 s16 y = baseTerrainLevelAtPoint(p.X, p.Y);
165 // Ridge/river terrain calculation
167 float uwatern = NoisePerlin2DNoTxfm(noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
168 // actually computing the depth of the ridge is much more expensive;
169 // if inside a river, simply guess
170 if (uwatern >= -width && uwatern <= width)
171 return water_level - 10;
173 // Mountain terrain calculation
174 int iters = 128; // don't even bother iterating more than 128 times..
176 //current point would have been air
177 if (!getMountainTerrainAtPoint(p.X, y, p.Y))
187 void MapgenV7::makeChunk(BlockMakeData *data) {
188 assert(data->vmanip);
189 assert(data->nodedef);
190 assert(data->blockpos_requested.X >= data->blockpos_min.X &&
191 data->blockpos_requested.Y >= data->blockpos_min.Y &&
192 data->blockpos_requested.Z >= data->blockpos_min.Z);
193 assert(data->blockpos_requested.X <= data->blockpos_max.X &&
194 data->blockpos_requested.Y <= data->blockpos_max.Y &&
195 data->blockpos_requested.Z <= data->blockpos_max.Z);
197 this->generating = true;
198 this->vm = data->vmanip;
199 this->ndef = data->nodedef;
200 //TimeTaker t("makeChunk");
202 v3s16 blockpos_min = data->blockpos_min;
203 v3s16 blockpos_max = data->blockpos_max;
204 node_min = blockpos_min * MAP_BLOCKSIZE;
205 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
206 full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
207 full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
209 blockseed = emerge->getBlockSeed(full_node_min); //////use getBlockSeed2()!
211 c_stone = ndef->getId("mapgen_stone");
212 c_dirt = ndef->getId("mapgen_dirt");
213 c_dirt_with_grass = ndef->getId("mapgen_dirt_with_grass");
214 c_sand = ndef->getId("mapgen_sand");
215 c_water_source = ndef->getId("mapgen_water_source");
216 c_lava_source = ndef->getId("mapgen_lava_source");
217 c_ice = ndef->getId("default:ice");
218 if (c_ice == CONTENT_IGNORE)
224 // Generate base terrain, mountains, and ridges with initial heightmaps
225 s16 stone_surface_max_y = generateTerrain();
227 updateHeightmap(node_min, node_max);
230 BiomeNoiseInput binput;
231 binput.mapsize = v2s16(csize.X, csize.Z);
232 binput.heat_map = noise_heat->result;
233 binput.humidity_map = noise_humidity->result;
234 binput.height_map = heightmap;
235 bmgr->calcBiomes(&binput, biomemap);
237 // Actually place the biome-specific nodes and what not
240 if (flags & MG_CAVES)
241 generateCaves(stone_surface_max_y);
243 if (flags & MG_DUNGEONS) {
244 DungeonGen dgen(this, NULL);
245 dgen.generate(blockseed, full_node_min, full_node_max);
248 for (size_t i = 0; i != emerge->decorations.size(); i++) {
249 Decoration *deco = emerge->decorations[i];
250 deco->placeDeco(this, blockseed + i, node_min, node_max);
253 for (size_t i = 0; i != emerge->ores.size(); i++) {
254 Ore *ore = emerge->ores[i];
255 ore->placeOre(this, blockseed + i, node_min, node_max);
258 // Sprinkle some dust on top after everything else was generated
261 //printf("makeChunk: %dms\n", t.stop());
263 updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
265 if (!(flags & MG_NOLIGHT))
266 calcLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
267 node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE);
268 //setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
269 // node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
271 this->generating = false;
275 void MapgenV7::calculateNoise() {
276 //TimeTaker t("calculateNoise", NULL, PRECISION_MICRO);
281 noise_height_select->perlinMap2D(x, z);
282 noise_height_select->transformNoiseMap();
284 noise_terrain_persist->perlinMap2D(x, z);
285 noise_terrain_persist->transformNoiseMap();
286 float *persistmap = noise_terrain_persist->result;
287 for (int i = 0; i != csize.X * csize.Z; i++)
288 persistmap[i] = rangelim(persistmap[i], 0.4, 0.9);
290 noise_terrain_base->perlinMap2DModulated(x, z, persistmap);
291 noise_terrain_base->transformNoiseMap();
293 noise_terrain_alt->perlinMap2DModulated(x, z, persistmap);
294 noise_terrain_alt->transformNoiseMap();
296 noise_filler_depth->perlinMap2D(x, z);
298 if (spflags & MGV7_MOUNTAINS) {
299 noise_mountain->perlinMap3D(x, y, z);
300 noise_mount_height->perlinMap2D(x, z);
301 noise_mount_height->transformNoiseMap();
304 if (spflags & MGV7_RIDGES) {
305 noise_ridge->perlinMap3D(x, y, z);
306 noise_ridge_uwater->perlinMap2D(x, z);
309 noise_heat->perlinMap2D(x, z);
310 noise_humidity->perlinMap2D(x, z);
312 //printf("calculateNoise: %dus\n", t.stop());
316 Biome *MapgenV7::getBiomeAtPoint(v3s16 p) {
317 float heat = NoisePerlin2D(bmgr->np_heat, p.X, p.Z, seed);
318 float humidity = NoisePerlin2D(bmgr->np_humidity, p.X, p.Z, seed);
319 s16 groundlevel = baseTerrainLevelAtPoint(p.X, p.Z);
321 return bmgr->getBiome(heat, humidity, groundlevel);
324 //needs to be updated
325 float MapgenV7::baseTerrainLevelAtPoint(int x, int z) {
326 float hselect = NoisePerlin2D(noise_height_select->np, x, z, seed);
327 hselect = rangelim(hselect, 0.0, 1.0);
329 float persist = NoisePerlin2D(noise_terrain_persist->np, x, z, seed);
330 persist = rangelim(persist, 0.4, 0.9);
332 noise_terrain_base->np->persist = persist;
333 float height_base = NoisePerlin2D(noise_terrain_base->np, x, z, seed);
335 noise_terrain_alt->np->persist = persist;
336 float height_alt = NoisePerlin2D(noise_terrain_alt->np, x, z, seed);
338 if (height_alt > height_base)
341 return (height_base * hselect) + (height_alt * (1.0 - hselect));
345 float MapgenV7::baseTerrainLevelFromMap(int index) {
346 float hselect = rangelim(noise_height_select->result[index], 0.0, 1.0);
347 float height_base = noise_terrain_base->result[index];
348 float height_alt = noise_terrain_alt->result[index];
350 if (height_alt > height_base)
353 return (height_base * hselect) + (height_alt * (1.0 - hselect));
357 bool MapgenV7::getMountainTerrainAtPoint(int x, int y, int z) {
358 float mnt_h_n = NoisePerlin2D(noise_mount_height->np, x, z, seed);
359 float height_modifier = -((float)y / rangelim(mnt_h_n, 80.0, 150.0));
360 float mnt_n = NoisePerlin3D(noise_mountain->np, x, y, z, seed);
362 return mnt_n + height_modifier >= 0.6;
366 bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, int y) {
367 float mounthn = noise_mount_height->result[idx_xz];
368 float height_modifier = -((float)y / rangelim(mounthn, 80.0, 150.0));
369 return (noise_mountain->result[idx_xyz] + height_modifier >= 0.6);
374 void MapgenV7::carveRivers() {
375 MapNode n_air(CONTENT_AIR), n_water_source(c_water_source);
376 MapNode n_stone(c_stone);
381 for (s16 z = node_min.Z; z <= node_max.Z; z++)
382 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
383 float terrain_mod = noise_terrain_mod->result[index];
384 NoiseParams *np = noise_terrain_river->np;
385 np->persist = noise_terrain_persist->result[index];
386 float terrain_river = NoisePerlin2DNoTxfm(np, x, z, seed);
387 float height = terrain_river * (1 - abs(terrain_mod)) *
388 noise_terrain_river->np->scale;
389 height = log(height * height); //log(h^3) is pretty interesting for terrain
391 s16 y = heightmap[index];
392 if (height < 1.0 && y > river_depth &&
393 y - river_depth >= node_min.Y && y <= node_max.Y) {
395 for (s16 ry = y; ry != y - river_depth; ry--) {
396 u32 vi = vm->m_area.index(x, ry, z);
397 vm->m_data[vi] = n_air;
400 u32 vi = vm->m_area.index(x, y - river_depth, z);
401 vm->m_data[vi] = n_water_source;
408 int MapgenV7::generateTerrain() {
409 int ymax = generateBaseTerrain();
411 if (spflags & MGV7_MOUNTAINS)
412 generateMountainTerrain();
414 if (spflags & MGV7_RIDGES)
415 generateRidgeTerrain();
421 int MapgenV7::generateBaseTerrain() {
422 MapNode n_air(CONTENT_AIR);
423 MapNode n_stone(c_stone);
424 MapNode n_water(c_water_source);
426 int stone_surface_max_y = -MAP_GENERATION_LIMIT;
427 v3s16 em = vm->m_area.getExtent();
430 for (s16 z = node_min.Z; z <= node_max.Z; z++)
431 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
432 float surface_height = baseTerrainLevelFromMap(index);
433 s16 surface_y = (s16)surface_height;
435 heightmap[index] = surface_y;
436 ridge_heightmap[index] = surface_y;
438 if (surface_y > stone_surface_max_y)
439 stone_surface_max_y = surface_y;
441 u32 i = vm->m_area.index(x, node_min.Y, z);
442 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
443 if (vm->m_data[i].getContent() == CONTENT_IGNORE) {
445 vm->m_data[i] = n_stone;
446 else if (y <= water_level)
447 vm->m_data[i] = n_water;
449 vm->m_data[i] = n_air;
451 vm->m_area.add_y(em, i, 1);
455 return stone_surface_max_y;
459 void MapgenV7::generateMountainTerrain() {
460 if (node_max.Y <= water_level)
463 MapNode n_stone(c_stone);
466 for (s16 z = node_min.Z; z <= node_max.Z; z++)
467 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
468 u32 vi = vm->m_area.index(node_min.X, y, z);
469 for (s16 x = node_min.X; x <= node_max.X; x++) {
470 int index = (z - node_min.Z) * csize.X + (x - node_min.X);
472 if (getMountainTerrainFromMap(j, index, y))
473 vm->m_data[vi] = n_stone;
482 void MapgenV7::generateRidgeTerrain() {
483 MapNode n_water(c_water_source);
484 MapNode n_air(CONTENT_AIR);
487 for (s16 z = node_min.Z; z <= node_max.Z; z++)
488 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
489 u32 vi = vm->m_area.index(node_min.X, y, z);
490 for (s16 x = node_min.X; x <= node_max.X; x++, index++, vi++) {
491 int j = (z - node_min.Z) * csize.X + (x - node_min.X);
493 if (heightmap[j] < water_level - 4)
496 float widthn = (noise_terrain_persist->result[j] - 0.6) / 0.1;
497 //widthn = rangelim(widthn, -0.05, 0.5);
499 float width = 0.3; // TODO: figure out acceptable perlin noise values
500 float uwatern = noise_ridge_uwater->result[j] * 2;
501 if (uwatern < -width || uwatern > width)
504 float height_mod = (float)(y + 17) / 2.5;
505 float width_mod = (width - fabs(uwatern));
506 float nridge = noise_ridge->result[index] * (float)y / 7.0;
509 nridge = -fabs(nridge) * 3.0 * widthn * 0.3;
511 if (nridge + width_mod * height_mod < 0.6)
514 if (y < ridge_heightmap[j])
515 ridge_heightmap[j] = y - 1;
517 vm->m_data[vi] = (y > water_level) ? n_air : n_water;
523 void MapgenV7::generateBiomes() {
524 if (node_max.Y < water_level)
527 MapNode n_air(CONTENT_AIR);
528 MapNode n_stone(c_stone);
529 MapNode n_water(c_water_source);
531 v3s16 em = vm->m_area.getExtent();
534 for (s16 z = node_min.Z; z <= node_max.Z; z++)
535 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
536 Biome *biome = bmgr->biomes[biomemap[index]];
537 s16 dfiller = biome->depth_filler + noise_filler_depth->result[index];
538 s16 y0_top = biome->depth_top;
539 s16 y0_filler = biome->depth_filler + biome->depth_top + dfiller;
542 u32 i = vm->m_area.index(x, node_max.Y, z);
544 content_t c_above = vm->m_data[i + em.X].getContent();
545 bool have_air = c_above == CONTENT_AIR;
547 for (s16 y = node_max.Y; y >= node_min.Y; y--) {
548 content_t c = vm->m_data[i].getContent();
550 // It could be the case that the elevation is equal to the chunk
551 // boundary, but the chunk above has not been generated yet
552 if (y == node_max.Y && c_above == CONTENT_IGNORE &&
553 y == heightmap[index] && c == c_stone) {
554 int j = (z - node_min.Z) * zstride +
555 (y - node_min.Y) * ystride +
557 have_air = !getMountainTerrainFromMap(j, index, y);
560 if (c == c_stone && have_air) {
561 content_t c_below = vm->m_data[i - em.X].getContent();
563 if (c_below != CONTENT_AIR) {
564 if (nplaced < y0_top) {
565 // A hack to prevent dirt_with_grass from being
566 // placed below water. TODO: fix later
567 content_t c_place = ((y < water_level) &&
568 (biome->c_top == c_dirt_with_grass)) ?
569 c_dirt : biome->c_top;
571 vm->m_data[i] = MapNode(c_place);
573 } else if (nplaced < y0_filler && nplaced >= y0_top) {
574 vm->m_data[i] = MapNode(biome->c_filler);
581 } else if (c == c_water_source) {
584 vm->m_data[i] = MapNode(biome->c_water);
585 } else if (c == CONTENT_AIR) {
590 vm->m_area.add_y(em, i, -1);
596 void MapgenV7::dustTopNodes() {
597 v3s16 em = vm->m_area.getExtent();
600 if (water_level > node_max.Y)
603 for (s16 z = node_min.Z; z <= node_max.Z; z++)
604 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
605 Biome *biome = bmgr->biomes[biomemap[index]];
607 if (biome->c_dust == CONTENT_IGNORE)
611 u32 vi = vm->m_area.index(x, y, z);
612 for (; y >= node_min.Y; y--) {
613 if (vm->m_data[vi].getContent() != CONTENT_AIR)
616 vm->m_area.add_y(em, vi, -1);
619 content_t c = vm->m_data[vi].getContent();
620 if (c == biome->c_water && biome->c_dust_water != CONTENT_IGNORE) {
624 vm->m_data[vi] = MapNode(biome->c_dust_water);
625 } else if (!ndef->get(c).buildable_to && c != CONTENT_IGNORE) {
629 vm->m_area.add_y(em, vi, 1);
630 vm->m_data[vi] = MapNode(biome->c_dust);
637 void MapgenV7::addTopNodes() {
638 v3s16 em = vm->m_area.getExtent();
642 for (s16 z = node_min.Z; z <= node_max.Z; z++)
643 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
644 Biome *biome = bmgr->biomes[biomemap[index]];
646 //////////////////// First, add top nodes below the ridge
647 s16 y = ridge_heightmap[index];
649 // This cutoff is good enough, but not perfect.
650 // It will cut off potentially placed top nodes at chunk boundaries
653 if (y > node_max.Y) {
654 y = node_max.Y; // Let's see if we can still go downward anyway
655 u32 vi = vm->m_area.index(x, y, z);
656 content_t c = vm->m_data[vi].getContent();
657 if (ndef->get(c).walkable)
661 // N.B. It is necessary to search downward since ridge_heightmap[i]
662 // might not be the actual height, just the lowest part in the chunk
663 // where a ridge had been carved
664 u32 i = vm->m_area.index(x, y, z);
665 for (; y >= node_min.Y; y--) {
666 content_t c = vm->m_data[i].getContent();
667 if (ndef->get(c).walkable)
669 vm->m_area.add_y(em, i, -1);
672 if (y != node_min.Y - 1 && y >= water_level) {
673 ridge_heightmap[index] = y; //update ridgeheight
674 ntopnodes = biome->top_depth;
675 for (; y <= node_max.Y && ntopnodes; y++) {
677 vm->m_data[i] = MapNode(biome->c_top);
678 vm->m_area.add_y(em, i, 1);
680 // If dirt, grow grass on it.
681 if (y > water_level - 10 &&
682 vm->m_data[i].getContent() == CONTENT_AIR) {
683 vm->m_area.add_y(em, i, -1);
684 if (vm->m_data[i].getContent() == c_dirt)
685 vm->m_data[i] = MapNode(c_dirt_with_grass);
689 //////////////////// Now, add top nodes on top of the ridge
690 y = heightmap[index];
691 if (y > node_max.Y) {
692 y = node_max.Y; // Let's see if we can still go downward anyway
693 u32 vi = vm->m_area.index(x, y, z);
694 content_t c = vm->m_data[vi].getContent();
695 if (ndef->get(c).walkable)
699 i = vm->m_area.index(x, y, z);
700 for (; y >= node_min.Y; y--) {
701 content_t c = vm->m_data[i].getContent();
702 if (ndef->get(c).walkable)
704 vm->m_area.add_y(em, i, -1);
707 if (y != node_min.Y - 1) {
708 ntopnodes = biome->top_depth;
709 // Let's see if we've already added it...
710 if (y == ridge_heightmap[index] + ntopnodes - 1)
713 for (; y <= node_max.Y && ntopnodes; y++) {
715 vm->m_data[i] = MapNode(biome->c_top);
716 vm->m_area.add_y(em, i, 1);
718 // If dirt, grow grass on it.
719 if (y > water_level - 10 &&
720 vm->m_data[i].getContent() == CONTENT_AIR) {
721 vm->m_area.add_y(em, i, -1);
722 if (vm->m_data[i].getContent() == c_dirt)
723 vm->m_data[i] = MapNode(c_dirt_with_grass);
731 NoiseParams nparams_v7_def_cave(6, 6.0, v3f(250.0, 250.0, 250.0), 34329, 3, 0.50);
733 void MapgenV7::generateCaves(int max_stone_y) {
734 PseudoRandom ps(blockseed + 21343);
736 int volume_nodes = (node_max.X - node_min.X + 1) *
737 (node_max.Y - node_min.Y + 1) *
738 (node_max.Z - node_min.Z + 1);
739 float cave_amount = NoisePerlin2D(&nparams_v7_def_cave,
740 node_min.X, node_min.Y, seed);
742 u32 caves_count = MYMAX(0.0, cave_amount) * volume_nodes / 250000;
743 for (u32 i = 0; i < caves_count; i++) {
744 CaveV7 cave(this, &ps, false);
745 cave.makeCave(node_min, node_max, max_stone_y);
748 u32 bruises_count = (ps.range(1, 8) == 1) ? ps.range(0, ps.range(0, 2)) : 1;
749 for (u32 i = 0; i < bruises_count; i++) {
750 CaveV7 cave(this, &ps, true);
751 cave.makeCave(node_min, node_max, max_stone_y);