Alternative fast-generating

This commit is contained in:
SmallJoker 2014-01-16 18:53:12 +01:00
parent dee487caa7
commit 13d183df73

View File

@ -2,41 +2,42 @@ function make_bamboo(pos, size)
for y=0,size-1 do for y=0,size-1 do
local p = {x=pos.x, y=pos.y+y, z=pos.z} local p = {x=pos.x, y=pos.y+y, z=pos.z}
local nn = minetest.get_node(p).name local nn = minetest.get_node(p).name
if minetest.registered_nodes[nn] and if nn == "air" then
minetest.registered_nodes[nn].buildable_to then
minetest.set_node(p, {name="bamboo:bamboo"}) minetest.set_node(p, {name="bamboo:bamboo"})
else elseif (nn == "default:dirt" or nn == "default:dirt_with_grass") then
return return
else
break
end end
end end
end end
minetest.register_on_generated(function(minp, maxp, seed) minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y >= 2 and minp.y <= 0 then if(minp.y < -35 or maxp.y > 50) then
-- Generate Bamboo return
local perlin1 = minetest.get_perlin(354, 3, 0.7, 100) end
-- Assume X and Z lengths are equal if(math.random(1,8) ~= 2) then
local divlen = 8 -- Making rare...
local divs = (maxp.x-minp.x)/divlen+1; return
for divx=0,divs-1 do end
for divz=0,divs-1 do local stop = false
local x0 = minp.x + math.floor((divx+0)*divlen) for px=2,maxp.x-minp.x-2 do
local z0 = minp.z + math.floor((divz+0)*divlen) for pz=2,maxp.z-minp.z-2 do
local x1 = minp.x + math.floor((divx+1)*divlen) local cpos = {x=minp.x+px,y=1,z=minp.z+pz}
local z1 = minp.z + math.floor((divz+1)*divlen) local cname = minetest.get_node(cpos).name
-- Determine bamboo amount from perlin noise if(cname == "default:desert_sand") then
local bamboo_amount = math.floor(perlin1:get2d({x=x0, y=z0}) * 45 - 20) -- AAH! Too hot!
-- Find random positions for Bamboo based on this random stop = true
local pr = PseudoRandom(seed+1) break
for i=0,bamboo_amount do end
local x = pr:next(x0, x1) if(cname == "default:dirt_with_grass" and math.random(1,15) == 2) then
local z = pr:next(z0, z1) if minetest.find_node_near(cpos, 2, "default:water_source") then
if minetest.get_node({x=x,y=1,z=z}).name == "default:dirt_with_grass" and make_bamboo({x=minp.x+px,y=2,z=minp.z+pz}, math.random(3, 6))
minetest.find_node_near({x=x,y=1,z=z}, 1, "default:water_source") then
make_bamboo({x=x,y=2,z=z}, pr:next(2, 4))
end
end end
end end
end
if(stop) then
break
end end
end end
end) end)