1 minetest
.register_on_generated(function(minp
, maxp
, seed
)
2 if maxp
.y
>= 2 and minp
.y
<= 0 then
4 local perlin1
= minetest
.get_perlin(436, 3, 0.6, 100)
5 -- Assume X and Z lengths are equal
7 local divs
= (maxp
.x
-minp
.x
)/divlen
+1;
10 local x0
= minp
.x
+ math
.floor((divx
+0)*divlen
)
11 local z0
= minp
.z
+ math
.floor((divz
+0)*divlen
)
12 local x1
= minp
.x
+ math
.floor((divx
+1)*divlen
)
13 local z1
= minp
.z
+ math
.floor((divz
+1)*divlen
)
14 -- Determine flowers amount from perlin noise
15 local grass_amount
= math
.floor(perlin1
:get2d({x
=x0
, y
=z0
}) ^
3 * 9)
16 -- Find random positions for flowers based on this random
17 local pr
= PseudoRandom(seed
+456)
18 for i
=0,grass_amount
do
19 local x
= pr
:next(x0
, x1
)
20 local z
= pr
:next(z0
, z1
)
21 -- Find ground level (0...15)
24 if minetest
.get_node({x
=x
,y
=y
,z
=z
}).name
~= "air" then
31 local p
= {x
=x
,y
=ground_y
+1,z
=z
}
32 local nn
= minetest
.get_node(p
).name
33 -- Check if the node can be replaced
34 if minetest
.registered_nodes
[nn
] and
35 minetest
.registered_nodes
[nn
].buildable_to
then
36 nn
= minetest
.get_node({x
=x
,y
=ground_y
,z
=z
}).name
37 if nn
== "default:dirt_with_grass" then
38 local flower_choice
= pr
:next(1, 6)
40 if flower_choice
== 1 then
41 flower
= "flowers:tulip"
42 elseif flower_choice
== 2 then
43 flower
= "flowers:rose"
44 elseif flower_choice
== 3 then
45 flower
= "flowers:dandelion_yellow"
46 elseif flower_choice
== 4 then
47 flower
= "flowers:dandelion_white"
48 elseif flower_choice
== 5 then
49 flower
= "flowers:geranium"
50 elseif flower_choice
== 6 then
51 flower
= "flowers:viola"
53 minetest
.set_node(p
, {name
=flower
})