Alternative fast-generating

master
SmallJoker 2014-01-16 18:53:12 +01:00
parent dee487caa7
commit 13d183df73
1 changed files with 27 additions and 26 deletions

View File

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