Skip to content

Commit a1389c3

Browse files
committedSep 16, 2017
Generate biomes: Recalculate biome at biome lower limit
Prevents biome nodes passing below the defined y_min of that biome.
1 parent 808ada1 commit a1389c3

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed
 

‎doc/lua_api.txt

-10
Original file line numberDiff line numberDiff line change
@@ -4630,9 +4630,6 @@ Definition tables
46304630

46314631
### Biome definition (`register_biome`)
46324632

4633-
**Note**
4634-
The Biome API is still in an experimental phase and subject to change.
4635-
46364633
{
46374634
name = "tundra",
46384635
node_dust = "default:snow",
@@ -4659,13 +4656,6 @@ The Biome API is still in an experimental phase and subject to change.
46594656
y_max = 31000,
46604657
-- ^ Lower and upper limits for biome.
46614658
-- ^ Limits are relative to y = water_level - 1.
4662-
-- ^ Because biome is not recalculated for every node in a node column
4663-
-- ^ some biome materials can exceed their limits, especially stone.
4664-
-- ^ For each node column in a mapchunk, biome is only recalculated at column
4665-
-- ^ top and at each of these surfaces:
4666-
-- ^ Ground below air, water below air, ground below water.
4667-
-- ^ The selected biome then stays in effect for all nodes below until
4668-
-- ^ column base or the next biome recalculation.
46694659
heat_point = 0,
46704660
humidity_point = 50,
46714661
-- ^ Characteristic average temperature and humidity for the biome.

‎src/mapgen.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ void MapgenBasic::generateBiomes(MgStoneType *mgstone_type,
633633
u16 base_filler = 0;
634634
u16 depth_water_top = 0;
635635
u16 depth_riverbed = 0;
636+
s16 biome_y_min = -MAX_MAP_GENERATION_LIMIT;
636637
u32 vi = vm->m_area.index(x, node_max.Y, z);
637638

638639
// Check node at base of mapchunk above, either a node of a previously
@@ -650,22 +651,20 @@ void MapgenBasic::generateBiomes(MgStoneType *mgstone_type,
650651

651652
for (s16 y = node_max.Y; y >= node_min.Y; y--) {
652653
content_t c = vm->m_data[vi].getContent();
653-
654-
// Biome is recalculated each time an upper surface is detected while
655-
// working down a column. The selected biome then remains in effect for
656-
// all nodes below until the next surface and biome recalculation.
657-
// Biome is recalculated:
654+
// Biome is (re)calculated:
658655
// 1. At the surface of stone below air or water.
659656
// 2. At the surface of water below air.
660657
// 3. When stone or water is detected but biome has not yet been calculated.
658+
// 4. When stone or water is detected just below a biome's lower limit.
661659
bool is_stone_surface = (c == c_stone) &&
662-
(air_above || water_above || !biome);
660+
(air_above || water_above || !biome || y < biome_y_min); // 1, 3, 4
663661

664662
bool is_water_surface =
665663
(c == c_water_source || c == c_river_water_source) &&
666-
(air_above || !biome);
664+
(air_above || !biome || y < biome_y_min); // 2, 3, 4
667665

668666
if (is_stone_surface || is_water_surface) {
667+
// (Re)calculate biome
669668
// Limit to +-MAX MAP GENERATION LIMIT to work with biome y_min / y_max.
670669
s32 relative_y = rangelim(y - biome_zero_level,
671670
-MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT);
@@ -677,9 +676,11 @@ void MapgenBasic::generateBiomes(MgStoneType *mgstone_type,
677676
depth_top = biome->depth_top;
678677
base_filler = MYMAX(depth_top +
679678
biome->depth_filler +
680-
noise_filler_depth->result[index], 0.f);
679+
noise_filler_depth->result[index], 0.0f);
681680
depth_water_top = biome->depth_water_top;
682681
depth_riverbed = biome->depth_riverbed;
682+
biome_y_min = rangelim(biome->y_min + biome_zero_level,
683+
-MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT);
683684

684685
// Detect stone type for dungeons during every biome calculation.
685686
// If none detected the last selected biome stone is chosen.

0 commit comments

Comments
 (0)