1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2025-06-28 06:11:47 +02:00

Merged fire and flowers

- Flowers (including dry shrub, and lilipads) use decorations now
This commit is contained in:
LeMagnesium
2015-06-09 21:25:39 +02:00
parent 1456906a5b
commit d44a5b5a79
2 changed files with 97 additions and 75 deletions

View File

@ -1,68 +1,87 @@
minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y >= 2 and minp.y <= 0 then
-- Generate flowers
local perlin1 = minetest.get_perlin(436, 3, 0.6, 100)
-- Assume X and Z lengths are equal
local divlen = 16
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 flowers amount from perlin noise
local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 3 * 9)
-- Find random positions for flowers based on this random
local pr = PseudoRandom(seed+456)
for i=0,grass_amount do
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
local function register_flower(name)
minetest.register_decoration({
deco_type = "simple",
place_on = {"default:dirt_with_grass"},
sidelen = 16,
noise_params = {
offset = 0,
scale = 0.006,
spread = {x=100, y=100, z=100},
seed = 436,
octaves = 3,
persist = 0.6
},
y_min = 1,
y_max = 30,
decoration = "flowers:"..name,
})
end
if ground_y then
local p = {x = x, y = ground_y + 1, z = z}
local nn = minetest.get_node(p).name
-- Check if the node can be replaced
if minetest.registered_nodes[nn] and
minetest.registered_nodes[nn].buildable_to then
nn = minetest.get_node({x = x, y = ground_y, z = z}).name
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})
elseif nn == "default:water_source" then
minetest.set_node(p, {name = "flowers:lily_pad"})
elseif nn == "default:sand" then
minetest.set_node(p, {name = "default:dry_shrub"})
elseif nn == "default:dirt_with_snow" then
minetest.set_node(p, {name = "default:snow"})
end
end
end
function flowers.register_mgv6_decorations()
register_flower("rose")
register_flower("tulip")
register_flower("dandelion_yellow")
register_flower("geranium")
register_flower("viola")
register_flower("dandelion_white")
end
minetest.register_decoration({
deco_type = "simple",
place_on = {"default:water_source"},
sidelen = 16,
noise_params = {
offset = 0,
scale = 0.006,
spread = {x=100, y=100, z=100},
seed = 436,
octaves = 3,
persist = 0.6
},
y_min = -10,
y_max = 30,
decoration = "flowers:lily_pad",
})
minetest.register_decoration({
deco_type = "simple",
place_on = {"default:sand"},
sidelen = 16,
noise_params = {
offset = 0,
scale = 0.006,
spread = {x=100, y=100, z=100},
seed = 436,
octaves = 3,
persist = 0.6
},
y_min = -400,
y_max = 400,
decoration = "default:dry_shrub",
})
minetest.register_decoration({
deco_type = "simple",
place_on = {"default:snow"},
sidelen = 16,
noise_params = {
offset = 0,
scale = 0.006,
spread = {x=100, y=100, z=100},
seed = 436,
octaves = 3,
persist = 0.6
},
y_min = -400,
y_max = 400,
decoration = "default:snow",
})
-- Enable in mapgen v6 only
local mg_params = minetest.get_mapgen_params()
if mg_params.mgname == "v6" then
flowers.register_mgv6_decorations()
end
end
end
end
end
end)