-- ^ In this example, there is a 3x3x3 cluster where 8 out of the 27 nodes are coal ore
y_min = -31000,
y_max = 64,
+ -- ^ Lower and upper limits for ore.
+ -- ^ Limits are relative to y = water_level - 1 for core mapgen, or
+ -- ^ relative to y = 0 for minetest.generate_ores().
flags = "",
-- ^ Attributes for this ore generation
noise_threshold = 0.5,
-- ^ Needed for sheet ore_type. Omit from scatter ore_type for a uniform ore distribution
random_factor = 1.0,
-- ^ Multiplier of the randomness contribution to the noise value at any
- -- given point to decide if ore should be placed. Set to 0 for solid veins.
+ -- ^ given point to decide if ore should be placed. Set to 0 for solid veins.
-- ^ This parameter is only valid for ore_type == "vein".
biomes = {"desert", "rainforest"}
-- ^ List of biomes in which this decoration occurs. Occurs in all biomes if this is omitted,
y_min = 1,
y_max = 31000,
-- ^ Lower and upper limits for biome.
+ -- ^ Limits are relative to y = water_level - 1.
-- ^ Because biome is not recalculated for every node in a node column
-- ^ some biome materials can exceed their limits, especially stone.
-- ^ For each node column in a mapchunk, biome is only recalculated at column
-- ^ Can be a list of (or a single) biome names, IDs, or definitions.
y_min = -31000
y_max = 31000
- -- ^ Minimum and maximum `y` positions these decorations can be generated at.
- -- ^ This parameter refers to the `y` position of the decoration base, so
- -- the actual maximum height would be `height_max + size.Y`.
+ -- ^ Lower and upper limits for decoration.
+ -- ^ Limits are relative to y = water_level - 1 for core mapgen, or
+ -- ^ relative to y = 0 for minetest.generate_decorations().
+ -- ^ This parameter refers to the `y` position of the decoration base, so
+ -- the actual maximum height would be `height_max + size.Y`.
spawn_by = "default:water",
-- ^ Node (or list of nodes) that the decoration only spawns next to.
-- ^ Checks two horizontal planes of neighbouring nodes (including diagonal neighbours),
}
-MgStoneType MapgenBasic::generateBiomes()
+MgStoneType MapgenBasic::generateBiomes(s16 biome_zero_level)
{
// can't generate biomes without a biome generator!
assert(biomegen);
(air_above || !biome);
if (is_stone_surface || is_water_surface) {
- biome = biomegen->getBiomeAtIndex(index, y);
+ // Limit to +-MAX MAP GENERATION LIMIT to work with biome y_min / y_max.
+ s32 relative_y = rangelim(y - biome_zero_level,
+ -MAX_MAP_GENERATION_LIMIT, MAX_MAP_GENERATION_LIMIT);
+ biome = biomegen->getBiomeAtIndex(index, relative_y);
if (biomemap[index] == BIOME_NONE && is_stone_surface)
biomemap[index] = biome->index;
virtual void generateCaves(s16 max_stone_y, s16 large_cave_depth);
virtual bool generateCaverns(s16 max_stone_y);
virtual void generateDungeons(s16 max_stone_y, MgStoneType stone_type);
- virtual MgStoneType generateBiomes();
+ virtual MgStoneType generateBiomes(s16 biome_zero_level = 0);
virtual void dustTopNodes();
protected:
// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
- MgStoneType stone_type = generateBiomes();
+ MgStoneType stone_type = generateBiomes(water_level - 1);
// Generate caverns, tunnels and classic caves
if (flags & MG_CAVES) {
// Generate the registered decorations
if (flags & MG_DECORATIONS)
- m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+ m_emerge->decomgr->placeAllDecos(this, blockseed,
+ node_min, node_max, water_level - 1);
// Generate the registered ores
- m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+ m_emerge->oremgr->placeAllOres(this, blockseed,
+ node_min, node_max, water_level - 1);
// Sprinkle some dust on top after everything else was generated
dustTopNodes();
}
return stone_surface_max_y;
-}
\ No newline at end of file
+}
// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
- MgStoneType stone_type = generateBiomes();
+ MgStoneType stone_type = generateBiomes(water_level - 1);
if (flags & MG_CAVES)
generateCaves(stone_surface_max_y, large_cave_depth);
// Generate the registered decorations
if (flags & MG_DECORATIONS)
- m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+ m_emerge->decomgr->placeAllDecos(this, blockseed,
+ node_min, node_max, water_level - 1);
// Generate the registered ores
- m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+ m_emerge->oremgr->placeAllOres(this, blockseed,
+ node_min, node_max, water_level - 1);
// Sprinkle some dust on top after everything else was generated
dustTopNodes();
// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
- MgStoneType stone_type = generateBiomes();
+ MgStoneType stone_type = generateBiomes(water_level - 1);
if (flags & MG_CAVES)
generateCaves(stone_surface_max_y, large_cave_depth);
// Generate the registered decorations
if (flags & MG_DECORATIONS)
- m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+ m_emerge->decomgr->placeAllDecos(this, blockseed,
+ node_min, node_max, water_level - 1);
// Generate the registered ores
- m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+ m_emerge->oremgr->placeAllOres(this, blockseed,
+ node_min, node_max, water_level - 1);
// Sprinkle some dust on top after everything else was generated
dustTopNodes();
// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
- MgStoneType stone_type = generateBiomes();
+ MgStoneType stone_type = generateBiomes(water_level - 1);
// Generate caverns, tunnels and classic caves
if (flags & MG_CAVES) {
// Generate the registered decorations
if (flags & MG_DECORATIONS)
- m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+ m_emerge->decomgr->placeAllDecos(this, blockseed,
+ node_min, node_max, water_level - 1);
// Generate the registered ores
- m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+ m_emerge->oremgr->placeAllOres(this, blockseed,
+ node_min, node_max, water_level - 1);
// Sprinkle some dust on top after everything else was generated
dustTopNodes();
// Generate the registered decorations
if (flags & MG_DECORATIONS)
- m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+ m_emerge->decomgr->placeAllDecos(this, blockseed,
+ node_min, node_max, water_level - 1);
// Generate the registered ores
- m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+ m_emerge->oremgr->placeAllOres(this, blockseed,
+ node_min, node_max, water_level - 1);
// Calculate lighting
if (flags & MG_LIGHT)
// Init biome generator, place biome-specific nodes, and build biomemap
biomegen->calcBiomeNoise(node_min);
- MgStoneType stone_type = generateBiomes();
+ MgStoneType stone_type = generateBiomes(water_level - 1);
// Generate caverns, tunnels and classic caves
if (flags & MG_CAVES) {
// Generate the registered decorations
if (flags & MG_DECORATIONS)
- m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+ m_emerge->decomgr->placeAllDecos(this, blockseed,
+ node_min, node_max, water_level - 1);
// Generate the registered ores
- m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+ m_emerge->oremgr->placeAllOres(this, blockseed,
+ node_min, node_max, water_level - 1);
// Sprinkle some dust on top after everything else was generated
dustTopNodes();
updateHeightmap(node_min, node_max);
// Place biome-specific nodes and build biomemap
- MgStoneType stone_type = generateBiomes();
+ MgStoneType stone_type = generateBiomes(water_level - 1);
// Cave creation.
if (flags & MG_CAVES)
// Generate the registered decorations
if (flags & MG_DECORATIONS)
- m_emerge->decomgr->placeAllDecos(this, blockseed, node_min, node_max);
+ m_emerge->decomgr->placeAllDecos(this, blockseed,
+ node_min, node_max, water_level - 1);
// Generate the registered ores
- m_emerge->oremgr->placeAllOres(this, blockseed, node_min, node_max);
+ m_emerge->oremgr->placeAllOres(this, blockseed,
+ node_min, node_max, water_level - 1);
// Sprinkle some dust on top after everything else was generated
dustTopNodes();
size_t DecorationManager::placeAllDecos(Mapgen *mg, u32 blockseed,
- v3s16 nmin, v3s16 nmax)
+ v3s16 nmin, v3s16 nmax, s16 deco_zero_level)
{
size_t nplaced = 0;
if (!deco)
continue;
- nplaced += deco->placeDeco(mg, blockseed, nmin, nmax);
+ nplaced += deco->placeDeco(mg, blockseed, nmin, nmax, deco_zero_level);
blockseed++;
}
}
-size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
+size_t Decoration::placeDeco(Mapgen *mg, u32 blockseed,
+ v3s16 nmin, v3s16 nmax, s16 deco_zero_level)
{
+ // Decoration y_min / y_max is displaced by deco_zero_level or remains
+ // unchanged. Any decoration with a limit at +-MAX_MAP_GENERATION_LIMIT is
+ // considered to have that limit at +-infinity, so we do not alter that limit.
+ s32 y_min_disp = (y_min <= -MAX_MAP_GENERATION_LIMIT) ?
+ -MAX_MAP_GENERATION_LIMIT : y_min + deco_zero_level;
+
+ s32 y_max_disp = (y_max >= MAX_MAP_GENERATION_LIMIT) ?
+ MAX_MAP_GENERATION_LIMIT : y_max + deco_zero_level;
+
PcgRandom ps(blockseed + 53);
int carea_size = nmax.X - nmin.X + 1;
else
y = mg->findGroundLevel(v2s16(x, z), nmin.Y, nmax.Y);
- if (y < nmin.Y || y > nmax.Y ||
- y < y_min || y > y_max)
+ if (y < y_min_disp || y > y_max_disp || y < nmin.Y || y > nmax.Y)
continue;
if (y + getHeight() > mg->vm->m_area.MaxEdge.Y) {
virtual void resolveNodeNames();
bool canPlaceDecoration(MMVManip *vm, v3s16 p);
- size_t placeDeco(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+ size_t placeDeco(Mapgen *mg, u32 blockseed,
+ v3s16 nmin, v3s16 nmax, s16 deco_zero_level);
//size_t placeCutoffs(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
virtual size_t generate(MMVManip *vm, PcgRandom *pr, v3s16 p) = 0;
}
}
- size_t placeAllDecos(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+ size_t placeAllDecos(Mapgen *mg, u32 blockseed,
+ v3s16 nmin, v3s16 nmax, s16 deco_zero_level = 0);
};
#endif
}
-size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
+size_t OreManager::placeAllOres(Mapgen *mg, u32 blockseed,
+ v3s16 nmin, v3s16 nmax, s16 ore_zero_level)
{
size_t nplaced = 0;
if (!ore)
continue;
- nplaced += ore->placeOre(mg, blockseed, nmin, nmax);
+ nplaced += ore->placeOre(mg, blockseed, nmin, nmax, ore_zero_level);
blockseed++;
}
}
-size_t Ore::placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax)
+size_t Ore::placeOre(Mapgen *mg, u32 blockseed,
+ v3s16 nmin, v3s16 nmax, s16 ore_zero_level)
{
- if (!(nmin.Y <= y_max && nmax.Y >= y_min))
+ // Ore y_min / y_max is displaced by ore_zero_level or remains unchanged.
+ // Any ore with a limit at +-MAX_MAP_GENERATION_LIMIT is considered to have
+ // that limit at +-infinity, so we do not alter that limit.
+ s32 y_min_disp = (y_min <= -MAX_MAP_GENERATION_LIMIT) ?
+ -MAX_MAP_GENERATION_LIMIT : y_min + ore_zero_level;
+
+ s32 y_max_disp = (y_max >= MAX_MAP_GENERATION_LIMIT) ?
+ MAX_MAP_GENERATION_LIMIT : y_max + ore_zero_level;
+
+ if (nmin.Y > y_max_disp || nmax.Y < y_min_disp)
return 0;
- int actual_ymin = MYMAX(nmin.Y, y_min);
- int actual_ymax = MYMIN(nmax.Y, y_max);
+ int actual_ymin = MYMAX(nmin.Y, y_min_disp);
+ int actual_ymax = MYMIN(nmax.Y, y_max_disp);
if (clust_size >= actual_ymax - actual_ymin + 1)
return 0;
virtual void resolveNodeNames();
- size_t placeOre(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+ size_t placeOre(Mapgen *mg, u32 blockseed,
+ v3s16 nmin, v3s16 nmax, s16 ore_zero_level);
virtual void generate(MMVManip *vm, int mapseed, u32 blockseed,
v3s16 nmin, v3s16 nmax, u8 *biomemap) = 0;
};
void clear();
- size_t placeAllOres(Mapgen *mg, u32 blockseed, v3s16 nmin, v3s16 nmax);
+ size_t placeAllOres(Mapgen *mg, u32 blockseed,
+ v3s16 nmin, v3s16 nmax, s16 ore_zero_level = 0);
};
#endif