dev.luanti.org/content/mapgen/custom-lua-mapgen.md

2 KiB

title aliases
Custom Lua Mapgen
/custom-lua-mapgen

Custom Lua Mapgen

The Luanti engine provides several built-in map generators implemented in C++, where biomes and decorations can be registered by mods. In addition to this you can also write your own mapgen in Lua. This is done by hooking into the singlenode mapgen (by default consisting only of air) and generating your own terrain using the Lua API.

Performance

As of 5.9, it is possible to write Lua map generators that run in a separate environment for each mapgen thread (see Mapgen environment), improving the performance of the mapgen.

Previously custom Lua mapgen would be implemented with the on_generated callback which would run on the main Lua thread, which is not recommended anymore unless you cannot implement something due to the limitations of the isolated mapgen environment.

Even with the new mapgen environment you should still be wary of some pitfalls that can hinder the performance of your Lua mapgen. For a list of optimisation techniques you can use to write performant mapgens, see Mapgen Optimisations.

Examples

A good initial example of how to write a custom Lua mapgen is lvm_example. It incorporates most optimisations techniques to create a performant mapgen and uses Perlin noise to generate random looking terrain, but has not been updated yet to use the new async mapgen environment.

For more examples of custom Lua mapgens, see the Custom mapgen tag on ContentDB.

Libraries

  • Luamap is a library that seeks to take out some of the pain of making custom mapgens by abstracting it away.
  • Biomegen reimplements the biome system used in built-in C++ mapgens for use with custom Lua mapgens.