From a38ae12ea46edab0ad92b0bff464015e23fe573f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Brada?= Date: Sat, 2 May 2015 18:39:52 +0200 Subject: [PATCH] Experimental sdedimentary layer generator. --- rocks/gensed.lua | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ rocks/init.lua | 8 +++--- 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 rocks/gensed.lua diff --git a/rocks/gensed.lua b/rocks/gensed.lua new file mode 100644 index 0000000..8cfd2fd --- /dev/null +++ b/rocks/gensed.lua @@ -0,0 +1,70 @@ +-- experimental sedimentary layer generator + +local np_typ = { + offset = 0, octaves = 2, persist = 0.33, + scale = 1, + spread = {x=70, y=70, z=70}, + seed = -5500, +} +local np_vc = { + offset = 0, octaves = 2, persist = 0.33, + scale = 1, + spread = {x=100, y=100, z=100}, + seed = 749, +} +local np_sp = { + offset = 0, octaves = 2, persist = 0.33, + scale = 1, + spread = {x=220, y=220, z=220}, + seed = -1284, +} + +rocksl.gensed = function (minp, maxp, seed) + local t1 = os.clock() + local vm, emin, emax = minetest.get_mapgen_object("voxelmanip") + local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax} + local data = vm:get_data() + + local chunksize = maxp.x - minp.x + 1 + local pmapsize = {x = chunksize, y = chunksize, z = chunksize} + local pmapminpxz = {x = minp.x, y = minp.z} + local c_stone= minetest.get_content_id("rocks:mudstone") + local c_dwg= minetest.get_content_id("default:dirt_with_grass") + + local n_typ= minetest.get_perlin_map(np_typ, pmapsize) : get2dMap_flat(pmapminpxz) + local n_vc= minetest.get_perlin_map(np_vc, pmapsize) : get2dMap_flat(pmapminpxz) + local n_sp= minetest.get_perlin_map(np_sp, pmapsize) : get2dMap_flat(pmapminpxz) + + layers = { + { node="default:sand" }, + { node="default:dirt" }, + { node="default:wood" }, + { node="default:obsidian" }, + } + for k,v in pairs(layers) do + v.ctx=minetest.get_content_id(v.node) + end + + local nixz= 1 + for z=minp.z, maxp.z do for x=minp.x, maxp.x do + -- loop + local tpv= math.abs(n_typ[nixz]) + local vcv= math.abs(n_vc[nixz]) + local spv= math.abs(n_sp[nixz]) + local tp=1 + if tpv>0.45 then tp=2 end + if tpv>0.78 then tp=3 end + if tpv>0.94 then tp=4 end + li=tp + for y=minp.y, maxp.y do + local di=area:index(x,y,z) + if (data[di]==c_stone) or (data[di]==c_dwg) then + data[di]=layers[li].ctx + end + end + nixz= nixz+1 + end end + vm:set_data(data) + vm:write_to_map(data) + minetest.log("action", "rocks/gensed/ "..math.ceil((os.clock() - t1) * 1000).." ms ") +end diff --git a/rocks/init.lua b/rocks/init.lua index 6900773..04fad98 100644 --- a/rocks/init.lua +++ b/rocks/init.lua @@ -26,9 +26,11 @@ minetest.clear_registered_ores() local modpath=minetest.get_modpath(minetest.get_current_modname()) dofile(modpath.."/sed.lua") -dofile(modpath.."/ign.lua") -dofile(modpath.."/skarn.lua") -dofile(modpath.."/pegmatite.lua") +--dofile(modpath.."/ign.lua") +--dofile(modpath.."/skarn.lua") +--dofile(modpath.."/pegmatite.lua") +dofile(modpath.."/gensed.lua") +minetest.register_on_generated(rocksl.gensed) minetest.register_on_mapgen_init(function(mapgen_params) -- todo: disable caves and ores