summaryrefslogtreecommitdiff
path: root/flowers.lua
blob: cf9af0bc0bdbc9da261e4555d3db66fb967b75ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
-- Flowers spread over all types of soil
minetest.register_abm({
	nodenames = {"group:flora"},
	neighbors = {"group:soil"},
	interval = 25,
	chance = 15,
	catch_up = false,
	action = function(pos, node)

		local light = minetest.get_node_light(pos)

		if not light
		or light < 13 then
			return
		end

		local pos0 = {x = pos.x - 4, y = pos.y - 2, z = pos.z - 4}
		local pos1 = {x = pos.x + 4, y = pos.y + 2, z = pos.z + 4}
		local num = #minetest.find_nodes_in_area_under_air(
			pos0, pos1, "group:flora")

		if num > 3
		and node.name == "ethereal:crystalgrass" then

			local grass = minetest.find_nodes_in_area_under_air(
				pos0, pos1, {"ethereal:crystalgrass"})

			local crystal = minetest.find_nodes_in_area_under_air(
				pos0, pos1, {"ethereal:crystal_spike"})

			if #grass > 4
			and #crystal < 1 then

				grass = grass[math.random(#grass)]

				grass.y = grass.y - 1

				if minetest.get_node(grass).name == "ethereal:crystal_dirt" then

					grass.y = grass.y + 1

					minetest.swap_node(grass, {name = "ethereal:crystal_spike"})
				end
			end

			return

		elseif num > 3
		and node.name == "ethereal:dry_shrub" then

			local grass = minetest.find_nodes_in_area_under_air(
				pos0, pos1, {"ethereal:dry_shrub"})

			local fflower = minetest.find_nodes_in_area_under_air(
				pos0, pos1, {"ethereal:fire_flower"})

			if #grass > 6
			and #fflower < 1 then

				grass = grass[math.random(#grass)]

				grass.y = grass.y - 1

				if minetest.get_node(grass).name == "ethereal:fiery_dirt" then

					grass.y = grass.y + 1

					minetest.swap_node(grass, {name = "ethereal:fire_flower"})
				end
			end

			return

		elseif num > 3 then
			return
		end

		local seedling = minetest.find_nodes_in_area_under_air(
			pos0, pos1, {"group:soil"})

		if #seedling > 0 then

			seedling = seedling[math.random(#seedling)]
			seedling.y = seedling.y + 1

			light = minetest.get_node_light(seedling)

			if not light
			or light < 13 then
				return
			end

			if minetest.get_node(seedling).name == "air" then
				minetest.swap_node(seedling, {name = node.name})
			end
		end
	end,
})