G2A Many GEOs
SHARE
TWEET

Minetest mapgen example

krock186 Feb 11th, 2017 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- UNTESTED
  2.  
  3. minetest.register_on_generated(function(minp, maxp, seed)
  4.     local cube_size = vector.add(vector.subtract(maxp, minp), 1)
  5.    
  6.     local my_perlin = minetest.get_perlin_map({
  7.         scale = 1,
  8.         spread = {x = 512, y = 512, z = 512},
  9.         seed = <somewhat>,
  10.         <more params here>
  11.     }, cube_size)
  12.    
  13.     local my_map = my_perlin:get3dMap(minp)
  14.    
  15.     -- Getting vmanip variables
  16.     local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
  17.     -- Util that converts absolute positions to an 1D-array index
  18.     local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax}
  19.     -- Node data in a 1D-array
  20.     local data = vm:get_data()
  21.     local data_pos = 1 -- Also called vi sometimes
  22.    
  23.     -- Caching some calls:
  24.     local c_air  = minetest.get_content_id("air")
  25.     local c_dirt = minetest.get_content_id("default:dirt")
  26.    
  27.     for z = minp.z, maxp.z do
  28.     for y = minp.y, maxp.y do
  29.     for x = minp.x, maxp.x do
  30.         -- Going through each index
  31.         if my_map[z - minp.z + 1][y - minp.y + 1][x - minp.x + 1] > 0.6 then
  32.             data[data_pos] = c_dirt
  33.         else
  34.             data[data_pos] = c_air
  35.         end
  36.         data_pos = data_pos + 1
  37.     end
  38.     end
  39.     end
  40.    
  41.     -- Updating the map
  42.     vm:set_data(data)
  43.     vm:calc_lighting()
  44.     vm:write_to_map(data)
  45. end)
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top