3 Copyright (C) 2010-2015 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
4 Copyright (C) 2010-2015 paramat, Matt Gregory
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.
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.
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.
28 #include "content_sao.h"
30 #include "voxelalgorithms.h"
31 //#include "profiler.h" // For TimeTaker
32 #include "settings.h" // For g_settings
34 #include "dungeongen.h"
39 #include "mg_decoration.h"
40 #include "mapgen_v7.h"
43 FlagDesc flagdesc_mapgen_v7[] = {
44 {"mountains", MGV7_MOUNTAINS},
45 {"ridges", MGV7_RIDGES},
46 {"floatlands", MGV7_FLOATLANDS},
51 ///////////////////////////////////////////////////////////////////////////////
54 MapgenV7::MapgenV7(int mapgenid, MapgenV7Params *params, EmergeManager *emerge)
55 : MapgenBasic(mapgenid, params, emerge)
57 this->spflags = params->spflags;
58 this->cave_width = params->cave_width;
59 this->float_mount_density = params->float_mount_density;
60 this->float_mount_height = params->float_mount_height;
61 this->floatland_level = params->floatland_level;
62 this->shadow_limit = params->shadow_limit;
65 noise_terrain_base = new Noise(¶ms->np_terrain_base, seed, csize.X, csize.Z);
66 noise_terrain_alt = new Noise(¶ms->np_terrain_alt, seed, csize.X, csize.Z);
67 noise_terrain_persist = new Noise(¶ms->np_terrain_persist, seed, csize.X, csize.Z);
68 noise_height_select = new Noise(¶ms->np_height_select, seed, csize.X, csize.Z);
69 noise_filler_depth = new Noise(¶ms->np_filler_depth, seed, csize.X, csize.Z);
70 noise_mount_height = new Noise(¶ms->np_mount_height, seed, csize.X, csize.Z);
71 noise_ridge_uwater = new Noise(¶ms->np_ridge_uwater, seed, csize.X, csize.Z);
72 noise_floatland_base = new Noise(¶ms->np_floatland_base, seed, csize.X, csize.Z);
73 noise_float_base_height = new Noise(¶ms->np_float_base_height, seed, csize.X, csize.Z);
76 // 1-up 1-down overgeneration
77 noise_mountain = new Noise(¶ms->np_mountain, seed, csize.X, csize.Y + 2, csize.Z);
78 noise_ridge = new Noise(¶ms->np_ridge, seed, csize.X, csize.Y + 2, csize.Z);
80 MapgenBasic::np_cave1 = params->np_cave1;
81 MapgenBasic::np_cave2 = params->np_cave2;
87 delete noise_terrain_base;
88 delete noise_terrain_persist;
89 delete noise_height_select;
90 delete noise_terrain_alt;
91 delete noise_filler_depth;
92 delete noise_mount_height;
93 delete noise_ridge_uwater;
94 delete noise_floatland_base;
95 delete noise_float_base_height;
96 delete noise_mountain;
101 MapgenV7Params::MapgenV7Params()
103 spflags = MGV7_MOUNTAINS | MGV7_RIDGES;
105 float_mount_density = 0.6;
106 float_mount_height = 128.0;
107 floatland_level = 1280;
110 np_terrain_base = NoiseParams(4, 70, v3f(600, 600, 600), 82341, 5, 0.6, 2.0);
111 np_terrain_alt = NoiseParams(4, 25, v3f(600, 600, 600), 5934, 5, 0.6, 2.0);
112 np_terrain_persist = NoiseParams(0.6, 0.1, v3f(2000, 2000, 2000), 539, 3, 0.6, 2.0);
113 np_height_select = NoiseParams(-8, 16, v3f(500, 500, 500), 4213, 6, 0.7, 2.0);
114 np_filler_depth = NoiseParams(0, 1.2, v3f(150, 150, 150), 261, 3, 0.7, 2.0);
115 np_mount_height = NoiseParams(256, 112, v3f(1000, 1000, 1000), 72449, 3, 0.6, 2.0);
116 np_ridge_uwater = NoiseParams(0, 1, v3f(1000, 1000, 1000), 85039, 5, 0.6, 2.0);
117 np_floatland_base = NoiseParams(-0.6, 1.5, v3f(600, 600, 600), 114, 5, 0.6, 2.0);
118 np_float_base_height = NoiseParams(48, 24, v3f(300, 300, 300), 907, 4, 0.7, 2.0);
119 np_mountain = NoiseParams(-0.6, 1, v3f(250, 350, 250), 5333, 5, 0.63, 2.0);
120 np_ridge = NoiseParams(0, 1, v3f(100, 100, 100), 6467, 4, 0.75, 2.0);
121 np_cave1 = NoiseParams(0, 12, v3f(61, 61, 61), 52534, 3, 0.5, 2.0);
122 np_cave2 = NoiseParams(0, 12, v3f(67, 67, 67), 10325, 3, 0.5, 2.0);
126 void MapgenV7Params::readParams(const Settings *settings)
128 settings->getFlagStrNoEx("mgv7_spflags", spflags, flagdesc_mapgen_v7);
129 settings->getFloatNoEx("mgv7_cave_width", cave_width);
130 settings->getFloatNoEx("mgv7_float_mount_density", float_mount_density);
131 settings->getFloatNoEx("mgv7_float_mount_height", float_mount_height);
132 settings->getS16NoEx("mgv7_floatland_level", floatland_level);
133 settings->getS16NoEx("mgv7_shadow_limit", shadow_limit);
135 settings->getNoiseParams("mgv7_np_terrain_base", np_terrain_base);
136 settings->getNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
137 settings->getNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
138 settings->getNoiseParams("mgv7_np_height_select", np_height_select);
139 settings->getNoiseParams("mgv7_np_filler_depth", np_filler_depth);
140 settings->getNoiseParams("mgv7_np_mount_height", np_mount_height);
141 settings->getNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
142 settings->getNoiseParams("mgv7_np_floatland_base", np_floatland_base);
143 settings->getNoiseParams("mgv7_np_float_base_height", np_float_base_height);
144 settings->getNoiseParams("mgv7_np_mountain", np_mountain);
145 settings->getNoiseParams("mgv7_np_ridge", np_ridge);
146 settings->getNoiseParams("mgv7_np_cave1", np_cave1);
147 settings->getNoiseParams("mgv7_np_cave2", np_cave2);
151 void MapgenV7Params::writeParams(Settings *settings) const
153 settings->setFlagStr("mgv7_spflags", spflags, flagdesc_mapgen_v7, U32_MAX);
154 settings->setFloat("mgv7_cave_width", cave_width);
155 settings->setFloat("mgv7_float_mount_density", float_mount_density);
156 settings->setFloat("mgv7_float_mount_height", float_mount_height);
157 settings->setS16("mgv7_floatland_level", floatland_level);
158 settings->setS16("mgv7_shadow_limit", shadow_limit);
160 settings->setNoiseParams("mgv7_np_terrain_base", np_terrain_base);
161 settings->setNoiseParams("mgv7_np_terrain_alt", np_terrain_alt);
162 settings->setNoiseParams("mgv7_np_terrain_persist", np_terrain_persist);
163 settings->setNoiseParams("mgv7_np_height_select", np_height_select);
164 settings->setNoiseParams("mgv7_np_filler_depth", np_filler_depth);
165 settings->setNoiseParams("mgv7_np_mount_height", np_mount_height);
166 settings->setNoiseParams("mgv7_np_ridge_uwater", np_ridge_uwater);
167 settings->setNoiseParams("mgv7_np_floatland_base", np_floatland_base);
168 settings->setNoiseParams("mgv7_np_float_base_height", np_float_base_height);
169 settings->setNoiseParams("mgv7_np_mountain", np_mountain);
170 settings->setNoiseParams("mgv7_np_ridge", np_ridge);
171 settings->setNoiseParams("mgv7_np_cave1", np_cave1);
172 settings->setNoiseParams("mgv7_np_cave2", np_cave2);
176 ///////////////////////////////////////////////////////////////////////////////
179 int MapgenV7::getSpawnLevelAtPoint(v2s16 p)
181 // Base terrain calculation
182 s16 y = baseTerrainLevelAtPoint(p.X, p.Y);
184 // If enabled, check if inside a river
185 if (spflags & MGV7_RIDGES) {
187 float uwatern = NoisePerlin2D(&noise_ridge_uwater->np, p.X, p.Y, seed) * 2;
188 if (fabs(uwatern) <= width)
189 return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
192 // If mountains are disabled, terrain level is base terrain level
193 // Avoids spawn on non-existant mountain terrain
194 if (!(spflags & MGV7_MOUNTAINS)) {
195 if (y <= water_level || y > water_level + 16)
196 return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
201 // Mountain terrain calculation
204 if (!getMountainTerrainAtPoint(p.X, y + 1, p.Y)) { // If air above
205 if (y <= water_level || y > water_level + 16)
206 return MAX_MAP_GENERATION_LIMIT; // Unsuitable spawn point
213 // Unsuitable spawn point, no mountain surface found
214 return MAX_MAP_GENERATION_LIMIT;
218 void MapgenV7::makeChunk(BlockMakeData *data)
221 assert(data->vmanip);
222 assert(data->nodedef);
223 assert(data->blockpos_requested.X >= data->blockpos_min.X &&
224 data->blockpos_requested.Y >= data->blockpos_min.Y &&
225 data->blockpos_requested.Z >= data->blockpos_min.Z);
226 assert(data->blockpos_requested.X <= data->blockpos_max.X &&
227 data->blockpos_requested.Y <= data->blockpos_max.Y &&
228 data->blockpos_requested.Z <= data->blockpos_max.Z);
230 this->generating = true;
231 this->vm = data->vmanip;
232 this->ndef = data->nodedef;
233 //TimeTaker t("makeChunk");
235 v3s16 blockpos_min = data->blockpos_min;
236 v3s16 blockpos_max = data->blockpos_max;
237 node_min = blockpos_min * MAP_BLOCKSIZE;
238 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
239 full_node_min = (blockpos_min - 1) * MAP_BLOCKSIZE;
240 full_node_max = (blockpos_max + 2) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
242 blockseed = getBlockSeed2(full_node_min, seed);
244 // Generate base and mountain terrain
245 // An initial heightmap is no longer created here for use in generateRidgeTerrain()
246 s16 stone_surface_max_y = generateTerrain();
249 if (spflags & MGV7_RIDGES)
250 generateRidgeTerrain();
253 updateHeightmap(node_min, node_max);
255 // Init biome generator, place biome-specific nodes, and build biomemap
256 biomegen->calcBiomeNoise(node_min);
257 MgStoneType stone_type = generateBiomes();
259 if (flags & MG_CAVES)
260 generateCaves(stone_surface_max_y, water_level);
262 if (flags & MG_DUNGEONS)
263 generateDungeons(stone_surface_max_y, stone_type);
265 // Generate the registered decorations
266 if (flags & MG_DECORATIONS)
267 m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
269 // Generate the registered ores
270 m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
272 // Sprinkle some dust on top after everything else was generated
275 //printf("makeChunk: %dms\n", t.stop());
277 updateLiquid(&data->transforming_liquid, full_node_min, full_node_max);
279 // Limit floatland shadow
280 bool propagate_shadow = !((spflags & MGV7_FLOATLANDS) &&
281 node_min.Y <= shadow_limit && node_max.Y >= shadow_limit);
283 if (flags & MG_LIGHT)
284 calcLighting(node_min - v3s16(0, 1, 0), node_max + v3s16(0, 1, 0),
285 full_node_min, full_node_max, propagate_shadow);
287 //setLighting(node_min - v3s16(1, 0, 1) * MAP_BLOCKSIZE,
288 // node_max + v3s16(1, 0, 1) * MAP_BLOCKSIZE, 0xFF);
290 this->generating = false;
294 float MapgenV7::baseTerrainLevelAtPoint(s16 x, s16 z)
296 float hselect = NoisePerlin2D(&noise_height_select->np, x, z, seed);
297 hselect = rangelim(hselect, 0.0, 1.0);
299 float persist = NoisePerlin2D(&noise_terrain_persist->np, x, z, seed);
301 noise_terrain_base->np.persist = persist;
302 float height_base = NoisePerlin2D(&noise_terrain_base->np, x, z, seed);
304 noise_terrain_alt->np.persist = persist;
305 float height_alt = NoisePerlin2D(&noise_terrain_alt->np, x, z, seed);
307 if (height_alt > height_base)
310 return (height_base * hselect) + (height_alt * (1.0 - hselect));
314 float MapgenV7::baseTerrainLevelFromMap(int index)
316 float hselect = rangelim(noise_height_select->result[index], 0.0, 1.0);
317 float height_base = noise_terrain_base->result[index];
318 float height_alt = noise_terrain_alt->result[index];
320 if (height_alt > height_base)
323 return (height_base * hselect) + (height_alt * (1.0 - hselect));
327 bool MapgenV7::getMountainTerrainAtPoint(s16 x, s16 y, s16 z)
329 float mnt_h_n = NoisePerlin2D(&noise_mount_height->np, x, z, seed);
330 float density_gradient = -((float)y / mnt_h_n);
331 float mnt_n = NoisePerlin3D(&noise_mountain->np, x, y, z, seed);
333 return mnt_n + density_gradient >= 0.0;
337 bool MapgenV7::getMountainTerrainFromMap(int idx_xyz, int idx_xz, s16 y)
339 float mounthn = noise_mount_height->result[idx_xz];
340 float density_gradient = -((float)y / mounthn);
341 float mountn = noise_mountain->result[idx_xyz];
343 return mountn + density_gradient >= 0.0;
347 bool MapgenV7::getFloatlandMountainFromMap(int idx_xyz, int idx_xz, s16 y)
349 // Make rim 2 nodes thick to match floatland base terrain
350 float density_gradient = (y >= floatland_level) ?
351 -pow((float)(y - floatland_level) / float_mount_height, 0.75f) :
352 -pow((float)(floatland_level - 1 - y) / float_mount_height, 0.75f);
354 float floatn = noise_mountain->result[idx_xyz] + float_mount_density;
356 return floatn + density_gradient >= 0.0f;
360 void MapgenV7::floatBaseExtentFromMap(s16 *float_base_min, s16 *float_base_max, int idx_xz)
362 // '+1' to avoid a layer of stone at y = MAX_MAP_GENERATION_LIMIT
363 s16 base_min = MAX_MAP_GENERATION_LIMIT + 1;
364 s16 base_max = MAX_MAP_GENERATION_LIMIT;
366 float n_base = noise_floatland_base->result[idx_xz];
368 float n_base_height = noise_float_base_height->result[idx_xz];
369 float amp = n_base * n_base_height;
370 float ridge = n_base_height / 3.0f;
371 base_min = floatland_level - amp / 1.5f;
373 if (amp > ridge * 2.0f) {
375 base_max = floatland_level - (amp - ridge * 2.0f) / 2.0f;
378 float diff = fabs(amp - ridge) / ridge;
379 // Smooth ridges using the 'smoothstep function'
380 float smooth_diff = diff * diff * (3.0f - 2.0f * diff);
381 base_max = floatland_level + ridge - smooth_diff * ridge;
385 *float_base_min = base_min;
386 *float_base_max = base_max;
390 int MapgenV7::generateTerrain()
392 MapNode n_air(CONTENT_AIR);
393 MapNode n_stone(c_stone);
394 MapNode n_water(c_water_source);
396 //// Calculate noise for terrain generation
397 noise_terrain_persist->perlinMap2D(node_min.X, node_min.Z);
398 float *persistmap = noise_terrain_persist->result;
400 noise_terrain_base->perlinMap2D(node_min.X, node_min.Z, persistmap);
401 noise_terrain_alt->perlinMap2D(node_min.X, node_min.Z, persistmap);
402 noise_height_select->perlinMap2D(node_min.X, node_min.Z);
404 if ((spflags & MGV7_MOUNTAINS) || (spflags & MGV7_FLOATLANDS)) {
405 noise_mountain->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
408 if (spflags & MGV7_MOUNTAINS) {
409 noise_mount_height->perlinMap2D(node_min.X, node_min.Z);
412 if (spflags & MGV7_FLOATLANDS) {
413 noise_floatland_base->perlinMap2D(node_min.X, node_min.Z);
414 noise_float_base_height->perlinMap2D(node_min.X, node_min.Z);
418 v3s16 em = vm->m_area.getExtent();
419 s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
422 for (s16 z = node_min.Z; z <= node_max.Z; z++)
423 for (s16 x = node_min.X; x <= node_max.X; x++, index2d++) {
424 s16 surface_y = baseTerrainLevelFromMap(index2d);
425 if (surface_y > stone_surface_max_y)
426 stone_surface_max_y = surface_y;
428 // Get extent of floatland base terrain
429 // '+1' to avoid a layer of stone at y = MAX_MAP_GENERATION_LIMIT
430 s16 float_base_min = MAX_MAP_GENERATION_LIMIT + 1;
431 s16 float_base_max = MAX_MAP_GENERATION_LIMIT;
432 if (spflags & MGV7_FLOATLANDS)
433 floatBaseExtentFromMap(&float_base_min, &float_base_max, index2d);
435 u32 vi = vm->m_area.index(x, node_min.Y - 1, z);
436 u32 index3d = (z - node_min.Z) * zstride_1u1d + (x - node_min.X);
438 for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
439 if (vm->m_data[vi].getContent() == CONTENT_IGNORE) {
440 if (y <= surface_y) {
441 vm->m_data[vi] = n_stone; // Base terrain
442 } else if ((spflags & MGV7_MOUNTAINS) &&
443 getMountainTerrainFromMap(index3d, index2d, y)) {
444 vm->m_data[vi] = n_stone; // Mountain terrain
445 if (y > stone_surface_max_y)
446 stone_surface_max_y = y;
447 } else if ((spflags & MGV7_FLOATLANDS) &&
448 ((y >= float_base_min && y <= float_base_max) ||
449 getFloatlandMountainFromMap(index3d, index2d, y))) {
450 vm->m_data[vi] = n_stone; // Floatland terrain
451 stone_surface_max_y = node_max.Y;
452 } else if (y <= water_level) {
453 vm->m_data[vi] = n_water; // Ground level water
454 } else if ((spflags & MGV7_FLOATLANDS) &&
455 (y >= float_base_max && y <= floatland_level)) {
456 vm->m_data[vi] = n_water; // Floatland water
458 vm->m_data[vi] = n_air;
461 vm->m_area.add_y(em, vi, 1);
466 return stone_surface_max_y;
470 void MapgenV7::generateRidgeTerrain()
472 if ((node_max.Y < water_level - 16) || (node_max.Y > shadow_limit))
475 noise_ridge->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);
476 noise_ridge_uwater->perlinMap2D(node_min.X, node_min.Z);
478 MapNode n_water(c_water_source);
479 MapNode n_air(CONTENT_AIR);
483 for (s16 z = node_min.Z; z <= node_max.Z; z++)
484 for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
485 u32 vi = vm->m_area.index(node_min.X, y, z);
486 for (s16 x = node_min.X; x <= node_max.X; x++, index++, vi++) {
487 int j = (z - node_min.Z) * csize.X + (x - node_min.X);
489 float uwatern = noise_ridge_uwater->result[j] * 2;
490 if (fabs(uwatern) > width)
493 float altitude = y - water_level;
494 float height_mod = (altitude + 17) / 2.5;
495 float width_mod = width - fabs(uwatern);
496 float nridge = noise_ridge->result[index] * MYMAX(altitude, 0) / 7.0;
498 if (nridge + width_mod * height_mod < 0.6)
501 vm->m_data[vi] = (y > water_level) ? n_air : n_water;
507 ////////////////////////////////////////////////////////////////////////////////
510 //// Much of the stuff here has potential to become useful again at some point
511 //// in the future, but we don't want it to get lost or forgotten in version
516 int MapgenV7::generateMountainTerrain(s16 ymax)
518 MapNode n_stone(c_stone);
521 for (s16 z = node_min.Z; z <= node_max.Z; z++)
522 for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
523 u32 vi = vm->m_area.index(node_min.X, y, z);
524 for (s16 x = node_min.X; x <= node_max.X; x++) {
525 int index = (z - node_min.Z) * csize.X + (x - node_min.X);
526 content_t c = vm->m_data[vi].getContent();
528 if (getMountainTerrainFromMap(j, index, y)
529 && (c == CONTENT_AIR || c == c_water_source)) {
530 vm->m_data[vi] = n_stone;
546 void MapgenV7::carveRivers() {
547 MapNode n_air(CONTENT_AIR), n_water_source(c_water_source);
548 MapNode n_stone(c_stone);
553 for (s16 z = node_min.Z; z <= node_max.Z; z++)
554 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
555 float terrain_mod = noise_terrain_mod->result[index];
556 NoiseParams *np = noise_terrain_river->np;
557 np.persist = noise_terrain_persist->result[index];
558 float terrain_river = NoisePerlin2DNoTxfm(np, x, z, seed);
559 float height = terrain_river * (1 - abs(terrain_mod)) *
560 noise_terrain_river->np.scale;
561 height = log(height * height); //log(h^3) is pretty interesting for terrain
563 s16 y = heightmap[index];
564 if (height < 1.0 && y > river_depth &&
565 y - river_depth >= node_min.Y && y <= node_max.Y) {
567 for (s16 ry = y; ry != y - river_depth; ry--) {
568 u32 vi = vm->m_area.index(x, ry, z);
569 vm->m_data[vi] = n_air;
572 u32 vi = vm->m_area.index(x, y - river_depth, z);
573 vm->m_data[vi] = n_water_source;
581 void MapgenV7::addTopNodes()
583 v3s16 em = vm->m_area.getExtent();
587 for (s16 z = node_min.Z; z <= node_max.Z; z++)
588 for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
589 Biome *biome = bmgr->biomes[biomemap[index]];
591 //////////////////// First, add top nodes below the ridge
592 s16 y = ridge_heightmap[index];
594 // This cutoff is good enough, but not perfect.
595 // It will cut off potentially placed top nodes at chunk boundaries
598 if (y > node_max.Y) {
599 y = node_max.Y; // Let's see if we can still go downward anyway
600 u32 vi = vm->m_area.index(x, y, z);
601 content_t c = vm->m_data[vi].getContent();
602 if (ndef->get(c).walkable)
606 // N.B. It is necessary to search downward since ridge_heightmap[i]
607 // might not be the actual height, just the lowest part in the chunk
608 // where a ridge had been carved
609 u32 i = vm->m_area.index(x, y, z);
610 for (; y >= node_min.Y; y--) {
611 content_t c = vm->m_data[i].getContent();
612 if (ndef->get(c).walkable)
614 vm->m_area.add_y(em, i, -1);
617 if (y != node_min.Y - 1 && y >= water_level) {
618 ridge_heightmap[index] = y; //update ridgeheight
619 ntopnodes = biome->top_depth;
620 for (; y <= node_max.Y && ntopnodes; y++) {
622 vm->m_data[i] = MapNode(biome->c_top);
623 vm->m_area.add_y(em, i, 1);
625 // If dirt, grow grass on it.
626 if (y > water_level - 10 &&
627 vm->m_data[i].getContent() == CONTENT_AIR) {
628 vm->m_area.add_y(em, i, -1);
629 if (vm->m_data[i].getContent() == c_dirt)
630 vm->m_data[i] = MapNode(c_dirt_with_grass);
634 //////////////////// Now, add top nodes on top of the ridge
635 y = heightmap[index];
636 if (y > node_max.Y) {
637 y = node_max.Y; // Let's see if we can still go downward anyway
638 u32 vi = vm->m_area.index(x, y, z);
639 content_t c = vm->m_data[vi].getContent();
640 if (ndef->get(c).walkable)
644 i = vm->m_area.index(x, y, z);
645 for (; y >= node_min.Y; y--) {
646 content_t c = vm->m_data[i].getContent();
647 if (ndef->get(c).walkable)
649 vm->m_area.add_y(em, i, -1);
652 if (y != node_min.Y - 1) {
653 ntopnodes = biome->top_depth;
654 // Let's see if we've already added it...
655 if (y == ridge_heightmap[index] + ntopnodes - 1)
658 for (; y <= node_max.Y && ntopnodes; y++) {
660 vm->m_data[i] = MapNode(biome->c_top);
661 vm->m_area.add_y(em, i, 1);
663 // If dirt, grow grass on it.
664 if (y > water_level - 10 &&
665 vm->m_data[i].getContent() == CONTENT_AIR) {
666 vm->m_area.add_y(em, i, -1);
667 if (vm->m_data[i].getContent() == c_dirt)
668 vm->m_data[i] = MapNode(c_dirt_with_grass);