Biome Generator

Description

Biome Generator is a library reproducing closely the biome generator provided by Luanti's core, but in Lua. Also includes an optional elevation adjustment parameter (Lapse rate).

It allows to use the biome systems on Lua mapgens (that have no access to core biome system yet). Since it reads registered biomes and decorations, it should be compatible with all mods adding biomes/decos.

It now supports both server and mapgen environment.

Include it in your mapgen 🔗

biomegen should be triggered during mapgen function, after the loop, but before writing to the map.

Your mapgen should generate only these 4 nodes:

  • Stone (mapgen_stone)
  • Water (mapgen_water_source)
  • River water (mapgen_river_water_source)
  • air

It is recommended to use these mapgen aliases, instead of default:stone, default:water... Mapgen aliases are recognized by all games and thus are much better for game-wise compatibility.

All other nodes will be ignored, no biome will be placed ontop of them.

You should add biomegen as a dependancy of your mod (optional or mandatory).

API 🔗

Description of usual function parameters:

  • data: Data containing the generated mapchunk
  • area: VoxelArea helper object for data. area = VoxelArea:new({MinEdge = emin, MaxEdge = emax})
  • vm: VoxelManip object
  • minp: minimal coordinates of the chunk being generated, e.g. {x=48, y=-32, z=208}
  • maxp: maximal coordinates of the chunk being generated, e.g. {x=127, y=47, z=287}
  • seed: world-specific seed

All functions are available in both Server and Mapgen environments.

biomegen.generate_all(data, area, vm, minp, maxp, seed) 🔗

All-in-one function to generate biomes, decorations, ores and dust. Includes a call to vm:set_data so no need to do it again. Using core function core.generate_ores for ores, so does not support biome-specific ores.

biomegen.generate_biomes(data, area, minp, maxp) 🔗

Generates biomes in data, according to biomes that have been registered using core.register_biome.

biomegen.place_all_decos(data, area, vm, minp, maxp, seed) 🔗

Generates decorations directly in vm (but reads data to know where to place them), according to decorations that have been registered using core.register_decoration.

biomegen.dust_top_nodes(data, area, vm, minp, maxp) 🔗

Drops 'dust' (usually snow) on biomes that require it. Like above, generates directly in vm but reads from data. If you used place_all_decos to generate decorations, you should update data from the vm:

vm:get_data(data)

biomegen.gennotify(feature, pos) 🔗

Adds an entry in gen notify in the field feature (dungeon, cave_begin, ..., also decoration#id). No effect if the feature is not requested in core.set_gen_notify.

biomegen.set_lapse_rate(lr) 🔗

Sets lapse rate parameter, that is, how much temperature decreases with elevation for every node. 0 is default value and means temperature does not depend on elevation (behaviour of core's biomegen). Usual values 0-0.5. Should be called only at init time!

biomegen.get_lapse_rate() 🔗

Returns lapse rate parameter.

biomegen.skip_chunk(minp, maxp) 🔗

Does not generate biomes but updates mapgen objects (biomemap, heatmap, humiditymap, heightmap and gennotify) so that other mods can use them without crashing. Use this function in the mapgen loop when skipping an empty chunk.

core.get_mapgen_object(objname) 🔗

The following objects are updated to take into account what Biomegen generates:

  • biomemap
  • heatmap
  • humiditymap
  • heightmap
  • gennotify

The behaviour of the function is otherwise unchanged.

core.get_biome_data(pos) 🔗

Takes into account elevation if lapse rate is non-zero. The behaviour of the function is otherwise unchanged.

Examples 🔗

These examples would run under the mapgen environment.

Using biomegen.generate_all 🔗

local data = {}

core.register_on_generated(function(vm, minp, maxp, seed)
	local emin, emax = vm:get_emerged_area()
	local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
	vm:get_data(data)

	local c_stone = core.get_content_id("mapgen_stone")
	local c_water = core.get_content_id("mapgen_water_source")

	------------------------
	-- [MAPGEN LOOP HERE] --
	------------------------

	-- Generate biomes, decorations, ores and dust
	biomegen.generate_all(data, area, vm, minp, maxp, seed)

	-- Calculate lighting for what has been created.
	vm:calc_lighting()
	-- Liquid nodes were placed so set them flowing.
	vm:update_liquids()
end)

Equivalent with all functions 🔗

local data = {}

core.register_on_generated(function(vm, minp, maxp, seed)
	local emin, emax = vm:get_emerged_area()
	local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
	vm:get_data(data)

	local c_stone = core.get_content_id("mapgen_stone")
	local c_water = core.get_content_id("mapgen_water_source")

	------------------------
	-- [MAPGEN LOOP HERE] --
	------------------------

	-- Generate biomes in 'data', using biomegen mod
	biomegen.generate_biomes(data, area, minp, maxp)

	-- Write content ID data back to the voxelmanip.
	vm:set_data(data)
	-- Generate ores using core's function
	core.generate_ores(vm, minp, maxp)
	-- Generate decorations in VM (needs 'data' for reading)
	biomegen.place_all_decos(data, area, vm, minp, maxp, seed)
	-- Update data array to have ores/decorations
	vm:get_data(data)
	-- Add biome dust in VM (needs 'data' for reading)
	biomegen.dust_top_nodes(data, area, vm, minp, maxp)

	-- Calculate lighting for what has been created.
	vm:calc_lighting()
	-- Liquid nodes were placed so set them flowing.
	vm:update_liquids()
end)

Mapgen example 🔗

lvm_example provides a minimal working example of a mapgen using biomegen. Try it!

Reviews

Review

Do you recommend this mod?

  • English

    Works so well you won't notice that you are using it

    Provides pretty much all ore and decoration types the engine supports to Lua mapgens, allowing them to concentrate on generating the map. And provides a base to go beyond standardengine mapgen facilities.

    Great work!

    0 comments

Releases

v2.3.0

Download

Luanti 5.12+

2026-03-25 20:18 UTC

v2.3.0 🔗

  • Optimize biome initialization
  • Log number of registered biomes and decorations
  • Added support for L-system decorations
  • Added support for "check_offset" decoration parameter
  • Fix schematic decorations on ceilings
  • Memoize schematic height
  • Rename elevation_chill parameter to lapse_rate
  • Update README and bump version 2.3.0

v2.2.1

Download

Luanti 5.12+

2026-03-11 19:58 UTC

v2.2.1 🔗

  • typo in readme
  • Optimize calc_biome_from_noise using lookup table
  • Use math.random for performance reasons (untested)
  • Small fix on schematic size (to be tested)
  • Optimized decoration generation
  • More optimizations: skip place_deco if required biomes don't match
  • Added version requirement, updated description and bump version 2.2.1
2026-03-09 17:43 UTC

v2.2 🔗

  • Fix heat not being consistent in get_biome_data and similar
  • Use core.log for logging and remove debug print
  • Added biome weight feature
  • Do not use register_on_generated to reset gennotify after mapgen
  • Gen notify: convert positions to Vector class
  • Added .cdb.json, .gitattributes, and updated mod.conf
  • Fixed bug. Prevent crash when elevation_chill not used.
  • Updated README and .cdb.json
  • Fixes: convert numbers to string if necessary, and add default biome
  • Save gen notify only once, after mapgen
  • Fix .cdb.json and bump version 2.2
2026-02-27 02:17 UTC

v2.1 🔗

  • Allow usage in mapgen environment
  • Use core namespace instead of minetest, and update README
All releases

Information

Provides

biomegen

Dependencies

Required
No required dependencies

Information

Type
Mod
Technical Name
biomegen
Languages
English
License
LGPL-3.0-only
Maintenance State
Actively Developed
Added
2021-08-01 08:35 UTC
Maintainers
Gaël de Sailly

Used By