From: Paramat Date: Thu, 5 Apr 2018 16:21:41 +0000 (+0100) Subject: Biome API / cavegen: Add definable cave liquid for a biome (#7192) X-Git-Tag: 5.0.0~460 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=32d456bd2d4dda50f77c01c702d1b5a5ff26134b;p=oweals%2Fminetest.git Biome API / cavegen: Add definable cave liquid for a biome (#7192) Add 'node_cave_liquid' as a new field in biome registration. If field is absent cave liquids fall back to classic behaviour. --- diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 0c995b54e..ea8e8b254 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -5662,6 +5662,10 @@ Definition tables node_riverbed = "default:gravel", depth_riverbed = 2, -- ^ Node placed under river water and thickness of this layer. + node_cave_liquid = "default:water_source", + -- ^ Nodes placed as a blob of liquid in 50% of large caves. + -- ^ If absent, cave liquids fall back to classic behaviour of lava or + -- ^ water distributed according to a hardcoded 3D noise. y_max = 31000, y_min = 1, -- ^ Upper and lower limits for biome. diff --git a/src/mapgen/cavegen.cpp b/src/mapgen/cavegen.cpp index 6f571ba1f..a54d5139d 100644 --- a/src/mapgen/cavegen.cpp +++ b/src/mapgen/cavegen.cpp @@ -279,7 +279,8 @@ CavesRandomWalk::CavesRandomWalk( int water_level, content_t water_source, content_t lava_source, - int lava_depth) + int lava_depth, + BiomeGen *biomegen) { assert(ndef); @@ -289,6 +290,7 @@ CavesRandomWalk::CavesRandomWalk( this->water_level = water_level; this->np_caveliquids = &nparams_caveliquids; this->lava_depth = lava_depth; + this->bmgn = biomegen; c_water_source = water_source; if (c_water_source == CONTENT_IGNORE) @@ -495,10 +497,22 @@ void CavesRandomWalk::carveRoute(v3f vec, float f, bool randomize_xz) v3s16 startp(orp.X, orp.Y, orp.Z); startp += of; - float nval = NoisePerlin3D(np_caveliquids, startp.X, - startp.Y, startp.Z, seed); - MapNode liquidnode = (nval < 0.40f && node_max.Y < lava_depth) ? - lavanode : waternode; + // Get biome at 'startp', use 'node_cave_liquid' if stated, otherwise + // fallback to classic behaviour. + MapNode liquidnode = CONTENT_IGNORE; + + if (bmgn) { + Biome *biome = (Biome *)bmgn->calcBiomeAtPoint(startp); + if (biome->c_cave_liquid != CONTENT_IGNORE) + liquidnode = biome->c_cave_liquid; + } + + if (liquidnode == CONTENT_IGNORE) { + float nval = NoisePerlin3D(np_caveliquids, startp.X, + startp.Y, startp.Z, seed); + liquidnode = (nval < 0.40f && node_max.Y < lava_depth) ? + lavanode : waternode; + } v3f fp = orp + vec * f; fp.X += 0.1f * ps->range(-10, 10); diff --git a/src/mapgen/cavegen.h b/src/mapgen/cavegen.h index 871ef3bcf..ff2923dc4 100644 --- a/src/mapgen/cavegen.h +++ b/src/mapgen/cavegen.h @@ -114,6 +114,7 @@ public: const NodeDefManager *ndef; GenerateNotifier *gennotify; s16 *heightmap; + BiomeGen *bmgn; // configurable parameters s32 seed; @@ -153,10 +154,11 @@ public: // ndef is a mandatory parameter. // If gennotify is NULL, generation events are not logged. + // If biomegen is NULL, cave liquids have classic behaviour. CavesRandomWalk(const NodeDefManager *ndef, GenerateNotifier *gennotify = NULL, s32 seed = 0, int water_level = 1, content_t water_source = CONTENT_IGNORE, content_t lava_source = CONTENT_IGNORE, - int lava_depth = -256); + int lava_depth = -256, BiomeGen *biomegen = NULL); // vm and ps are mandatory parameters. // If heightmap is NULL, the surface level at all points is assumed to diff --git a/src/mapgen/mapgen.cpp b/src/mapgen/mapgen.cpp index 078d6c486..67dbee3f5 100644 --- a/src/mapgen/mapgen.cpp +++ b/src/mapgen/mapgen.cpp @@ -858,9 +858,10 @@ void MapgenBasic::generateCaves(s16 max_stone_y, s16 large_cave_depth) u32 bruises_count = ps.range(0, 2); for (u32 i = 0; i < bruises_count; i++) { CavesRandomWalk cave(ndef, &gennotify, seed, water_level, - c_water_source, CONTENT_IGNORE, lava_depth); + c_water_source, c_lava_source, lava_depth, biomegen); - cave.makeCave(vm, node_min, node_max, &ps, true, max_stone_y, heightmap); + cave.makeCave(vm, node_min, node_max, &ps, true, max_stone_y, + heightmap); } } diff --git a/src/mapgen/mapgen_valleys.cpp b/src/mapgen/mapgen_valleys.cpp index bef4629a8..f4c3c7b79 100644 --- a/src/mapgen/mapgen_valleys.cpp +++ b/src/mapgen/mapgen_valleys.cpp @@ -744,9 +744,10 @@ void MapgenValleys::generateCaves(s16 max_stone_y, s16 large_cave_depth) u32 bruises_count = ps.range(0, 2); for (u32 i = 0; i < bruises_count; i++) { CavesRandomWalk cave(ndef, &gennotify, seed, water_level, - c_water_source, c_lava_source, lava_max_height); + c_water_source, c_lava_source, lava_max_height, biomegen); - cave.makeCave(vm, node_min, node_max, &ps, true, max_stone_y, heightmap); + cave.makeCave(vm, node_min, node_max, &ps, true, max_stone_y, + heightmap); } } } diff --git a/src/mapgen/mg_biome.cpp b/src/mapgen/mg_biome.cpp index 7f091f313..584dea9c4 100644 --- a/src/mapgen/mg_biome.cpp +++ b/src/mapgen/mg_biome.cpp @@ -62,6 +62,7 @@ BiomeManager::BiomeManager(Server *server) : b->m_nodenames.emplace_back("mapgen_river_water_source"); b->m_nodenames.emplace_back("mapgen_stone"); b->m_nodenames.emplace_back("ignore"); + b->m_nodenames.emplace_back("ignore"); m_ndef->pendNodeResolve(b); add(b); @@ -321,4 +322,5 @@ void Biome::resolveNodeNames() getIdFromNrBacklog(&c_river_water, "mapgen_river_water_source", CONTENT_AIR); getIdFromNrBacklog(&c_riverbed, "mapgen_stone", CONTENT_AIR); getIdFromNrBacklog(&c_dust, "ignore", CONTENT_IGNORE); + getIdFromNrBacklog(&c_cave_liquid, "ignore", CONTENT_IGNORE); } diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h index 086cf56fe..27b6ebf95 100644 --- a/src/mapgen/mg_biome.h +++ b/src/mapgen/mg_biome.h @@ -52,6 +52,7 @@ public: content_t c_river_water; content_t c_riverbed; content_t c_dust; + content_t c_cave_liquid; s16 depth_top; s16 depth_filler; diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index d7bb96086..03a2b3eea 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -389,9 +389,11 @@ Biome *read_biome_def(lua_State *L, int index, const NodeDefManager *ndef) b->vertical_blend = getintfield_default(L, index, "vertical_blend", 0); b->flags = 0; // reserved - b->min_pos = getv3s16field_default(L, index, "min_pos", v3s16(-31000, -31000, -31000)); + b->min_pos = getv3s16field_default( + L, index, "min_pos", v3s16(-31000, -31000, -31000)); getintfield(L, index, "y_min", b->min_pos.Y); - b->max_pos = getv3s16field_default(L, index, "max_pos", v3s16(31000, 31000, 31000)); + b->max_pos = getv3s16field_default( + L, index, "max_pos", v3s16(31000, 31000, 31000)); getintfield(L, index, "y_max", b->max_pos.Y); std::vector &nn = b->m_nodenames; @@ -403,6 +405,7 @@ Biome *read_biome_def(lua_State *L, int index, const NodeDefManager *ndef) nn.push_back(getstringfield_default(L, index, "node_river_water", "")); nn.push_back(getstringfield_default(L, index, "node_riverbed", "")); nn.push_back(getstringfield_default(L, index, "node_dust", "")); + nn.push_back(getstringfield_default(L, index, "node_cave_liquid", "")); ndef->pendNodeResolve(b); return b;