From: Perttu Ahola Date: Sat, 7 Apr 2012 11:09:07 +0000 (+0300) Subject: papyrus generation X-Git-Tag: 0.4.dev-20120408~9 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5f6039bc3c820d823a13e9f4925efc96b645337a;p=oweals%2Fminetest_game.git papyrus generation --- diff --git a/mods/default/mapgen.lua b/mods/default/mapgen.lua index af94505a..c6e7d24e 100644 --- a/mods/default/mapgen.lua +++ b/mods/default/mapgen.lua @@ -68,13 +68,20 @@ local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, --print("generate_ore done") end +local function make_papyrus(pos, size) + for y=0,size-1 do + local p = {x=pos.x, y=pos.y+y, z=pos.z} + minetest.env:set_node(p, {name="default:papyrus"}) + end +end + minetest.register_on_generated(function(minp, maxp, seed) generate_ore("default:stone_with_coal", "default:stone", minp, maxp, seed, 1/8/8/8, 5, -31000, 64) generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+1, 1/16/16/16, 5, -5, 7) generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+2, 1/12/12/12, 5, -16, -5) generate_ore("default:stone_with_iron", "default:stone", minp, maxp, seed+3, 1/9/9/9, 5, -31000, -17) - -- Generate clay if maxp.y >= 2 and minp.y <= 0 then + -- Generate clay -- Assume X and Z lengths are equal local divlen = 4 local divs = (maxp.x-minp.x)/divlen+1; @@ -109,6 +116,31 @@ minetest.register_on_generated(function(minp, maxp, seed) end end end + -- Generate papyrus + local perlin1 = minetest.env:get_perlin(354, 3, 0.7, 100) + -- Assume X and Z lengths are equal + local divlen = 8 + local divs = (maxp.x-minp.x)/divlen+1; + for divx=0,divs-1 do + for divz=0,divs-1 do + local x0 = minp.x + math.floor((divx+0)*divlen) + local z0 = minp.z + math.floor((divz+0)*divlen) + local x1 = minp.x + math.floor((divx+1)*divlen) + local z1 = minp.z + math.floor((divz+1)*divlen) + -- Determine papyrus amount from perlin noise + local papyrus_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 45 - 20) + -- Find random positions for papyrus based on this random + local pr = PseudoRandom(seed+1) + for i=0,papyrus_amount do + local x = pr:next(x0, x1) + local z = pr:next(z0, z1) + if minetest.env:get_node({x=x,y=1,z=z}).name == "default:dirt_with_grass" and + minetest.env:find_node_near({x=x,y=1,z=z}, 1, "default:water_source") then + make_papyrus({x=x,y=2,z=z}, pr:next(2, 4)) + end + end + end + end end end)