From Minetest Developer Wiki
Jump to navigation Jump to search
Mbox warning.png This page contains unofficial Lua API documentation and is likely to be outdated or wrong.
For the official and up-to-date documentation, refer to lua_api.txt found in your Minetest installation directory under doc.
Mbox warning.png This page has been proposed for deletion for the following reason: "Contains unofficial and potentially outdated, redundant and inconsistent Lua API information"
If you don't think that this page should be deleted, please explain why on the talk page.

A fast, bulk perlin noise generator Can be created via

  • <source enclose="none">PerlinNoiseMap(noiseparams, size)</source>
  • <source enclose="none">minetest.get_perlin_map(noiseparams, size)</source>

The latter function must not be called until after the world is finished initializing, so it must be called during some kind of callback rather than at the top level mod initialization code. The first constructor, on the other hand, may be called at any time since it does not depend on the world's seed.


<source enclose="none">get2dMap(pos)</source> <source enclose="none">size.x</source> x <source enclose="none">size.y</source> 2d array of 2d noise values starting at <source enclose="none">pos={x=,y=}</source>
<source enclose="none">get3dMap(pos)</source> <source enclose="none">size.x</source> x <source enclose="none">size.y</source> x <source enclose="none">size.z</source> 3d array of 3d noise values starting at <source enclose="none">pos={x=,y=,z=}</source>
<source enclose="none">get2dMap_flat(pos)</source> Flat <source enclose="none">size.x</source> * <source enclose="none">size.y</source> element array of 2d noise values starting at <source enclose="none">pos={x=,y=}</source>
<source enclose="none">get3dMap_flat(pos)</source> Same as get2dMap_flat, but 3d noise

Noise Params

Here's an example of the noiseparams: <source>local testparam = {

  offset = 0,
  scale = 1,
  spread = {x=2048, y=2048, z=2048},
  seed = 1337,
  octaves = 6,
  persist = 0.6


  • spread: defines how fast the (ex.) terrain high changes (frequency)
  • seed: every seed generates a different perlin map
  • octaves: higher value, higher details


<source>minetest.register_on_generated(function(minp, maxp, seed)

  local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
  local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
  local data = vm:get_data()
  --get side length of the current mapgen block
  local side_length = maxp.x - minp.x + 1
  local map_lengths_xyz = {x=side_length, y=side_length, z=side_length}
  local perlin_map = minetest.get_perlin_map(testparam, map_lengths_xyz):get2dMap_flat(minp)
  local perlin_index = 1
  for z = minp.z, maxp.z do
     for y = minp.y, maxp.y do
        local vi = area:index(minp.x, y, z)
        for x = minp.x, maxp.x do
            print("Some spam value: "..tostring(perlin_map[vi])
            --more efficient coding - x++
            perlin_index = perlin_index + 1
            vi = vi + 1
        --go back, one side_length
        perlin_index = perlin_index - side_length
     --go forward, one side_length
     perlin_index = perlin_index + side_length


See also

External Links

Minetest forum thread: "minetest.get_perlin() and minetest.get_perlin_map() Return nil"

Mbox important.png This article is incomplete.
Please help expand this article to include more useful information.