flowers/mapgen.lua: Register flower decorations for mgv6

This commit is contained in:
paramat 2015-03-24 20:48:59 +00:00
parent 9eb9502209
commit 8a8712e4a3

View File

@ -1,70 +1,35 @@
function flowers.mgv6ongen(minp, maxp, seed) local function register_flower(name)
if maxp.y >= 2 and minp.y <= 0 then minetest.register_decoration({
-- Generate flowers deco_type = "simple",
local perlin1 = minetest.get_perlin(436, 3, 0.6, 100) place_on = {"default:dirt_with_grass"},
-- Assume X and Z lengths are equal sidelen = 16,
local divlen = 16 noise_params = {
local divs = (maxp.x-minp.x)/divlen+1; offset = 0,
for divx=0,divs-1 do scale = 0.006,
for divz=0,divs-1 do spread = {x=100, y=100, z=100},
local x0 = minp.x + math.floor((divx+0)*divlen) seed = 436,
local z0 = minp.z + math.floor((divz+0)*divlen) octaves = 3,
local x1 = minp.x + math.floor((divx+1)*divlen) persist = 0.6
local z1 = minp.z + math.floor((divz+1)*divlen) },
-- Determine flowers amount from perlin noise y_min = 1,
local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 3 * 9) y_max = 30,
-- Find random positions for flowers based on this random decoration = "flowers:"..name.."",
local pr = PseudoRandom(seed+456) })
for i=0,grass_amount do end
local x = pr:next(x0, x1)
local z = pr:next(z0, z1)
-- Find ground level (0...15)
local ground_y = nil
for y=30,0,-1 do
if minetest.get_node({x=x,y=y,z=z}).name ~= "air" then
ground_y = y
break
end
end
if ground_y then function flowers.register_mgv6_decorations()
local p = {x=x,y=ground_y+1,z=z} register_flower("rose")
local nn = minetest.get_node(p).name register_flower("tulip")
-- Check if the node can be replaced register_flower("dandelion_yellow")
if minetest.registered_nodes[nn] and register_flower("geranium")
minetest.registered_nodes[nn].buildable_to then register_flower("viola")
nn = minetest.get_node({x=x,y=ground_y,z=z}).name register_flower("dandelion_white")
if nn == "default:dirt_with_grass" then
local flower_choice = pr:next(1, 6)
local flower
if flower_choice == 1 then
flower = "flowers:tulip"
elseif flower_choice == 2 then
flower = "flowers:rose"
elseif flower_choice == 3 then
flower = "flowers:dandelion_yellow"
elseif flower_choice == 4 then
flower = "flowers:dandelion_white"
elseif flower_choice == 5 then
flower = "flowers:geranium"
elseif flower_choice == 6 then
flower = "flowers:viola"
end
minetest.set_node(p, {name=flower})
end
end
end
end
end
end
end
end end
-- Enable in mapgen v6 only -- Enable in mapgen v6 only
minetest.register_on_mapgen_init(function(mg_params) local mg_params = minetest.get_mapgen_params()
if mg_params.mgname == "v6" then if mg_params.mgname == "v6" then
minetest.register_on_generated(flowers.mgv6ongen) flowers.register_mgv6_decorations()
end end
end)