Guest User

Untitled

a guest
Jun 28th, 2013
998
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. minetest.register_on_mapgen_init(function(mgparams)
  2.     minetest.set_mapgen_params({mgname="singlenode", flags="nolight", flagmask="nolight"})
  3. end)
  4.  
  5. minetest.register_on_generated(function(minp, maxp, seed)
  6.     local t1 = os.clock()
  7.     local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
  8.     local a = VoxelArea:new{
  9.         MinEdge={x=emin.x, y=emin.y, z=emin.z},
  10.         MaxEdge={x=emax.x, y=emax.y, z=emax.z},
  11.     }
  12.  
  13.     local data = vm:get_data()
  14.  
  15.     local c_dirt  = minetest.get_content_id("default:dirt")
  16.     local c_grass = minetest.get_content_id("default:dirt_with_grass")
  17.     local c_water = minetest.get_content_id("default:water_source")
  18.  
  19.     local sidelen = maxp.x - minp.x + 1
  20.  
  21.     local noise = minetest.get_perlin_map(
  22.         {offset=0, scale=1, spread={x=200, y=125, z=200}, seed=5, octaves=5, persist=0.6},
  23.         {x=sidelen, y=sidelen, z=sidelen}
  24.     )
  25.     local nvals = noise:get3dMap_flat({x=minp.x, y=minp.y, z=minp.z})
  26.  
  27.     local ni = 1
  28.     for z = minp.z, maxp.z do
  29.     for y = minp.y, maxp.y do
  30.     for x = minp.x, maxp.x do
  31.         if nvals[ni] - (y - 25) / 55 > 0.5 then
  32.             local vi = a:index(x, y, z)
  33.             if y < 1 then
  34.                 data[vi] = c_dirt
  35.             else
  36.                 data[vi] = c_grass
  37.             end
  38.         elseif y < 1 then
  39.             local vi = a:index(x, y, z)
  40.             data[vi] = c_water
  41.         end
  42.         ni = ni + 1
  43.     end
  44.     end
  45.     end
  46.  
  47.     vm:set_data(data)
  48.    
  49.     vm:calc_lighting(
  50.         {x=minp.x-16, y=minp.y, z=minp.z-16},
  51.         {x=maxp.x+16, y=maxp.y, z=maxp.z+16}
  52.     )
  53.  
  54.     vm:write_to_map(data)
  55.  
  56.     print(string.format("elapsed time: %.2fms", (os.clock() - t1) * 1000))
  57. end)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×