summaryrefslogtreecommitdiff
path: root/leafdecay.lua
blob: 1870cb6b6db0a22c5f45e442dcc615cb0c1f68b0 (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
-- leaf decay

if moretrees.enable_leafdecay then
	for i in ipairs(moretrees.treelist) do
		local treename = moretrees.treelist[i][1]
		if treename ~= "jungletree" and treename ~= "fir" then
			minetest.register_abm({
				nodenames = "moretrees:"..treename.."_leaves",
				interval = moretrees.leafdecay_delay,
				chance = moretrees.leafdecay_chance,
				action = function(pos, node, active_object_count, active_object_count_wider)
					if not minetest.env:find_node_near(pos, moretrees.leafdecay_radius, "moretrees:"..treename.."_trunk") then
						minetest.env:remove_node(pos)
						minetest.env:dig_node(pos)
					end
				end
			})
		end
	end

	minetest.register_abm({
		nodenames = {"moretrees:jungletree_leaves_red","moretrees:jungletree_leaves_green","moretrees:jungletree_leaves_yellow"},
		interval = moretrees.leafdecay_delay,
		chance = moretrees.leafdecay_chance,
		action = function(pos, node, active_object_count, active_object_count_wider)
			if not minetest.env:find_node_near(pos, moretrees.leafdecay_radius, {"default:jungletree", "moretrees:jungletree_trunk"}) then
				minetest.env:remove_node(pos)
				minetest.env:dig_node(pos)
			end
		end
	})

	minetest.register_abm({
		nodenames = {"moretrees:fir_leaves", "moretrees:fir_leaves_bright"},
		interval = moretrees.leafdecay_delay,
		chance = moretrees.leafdecay_chance,
		action = function(pos, node, active_object_count, active_object_count_wider)
			if not minetest.env:find_node_near(pos, moretrees.leafdecay_radius, "moretrees:fir_trunk") then
				minetest.env:remove_node(pos)
				minetest.env:dig_node(pos)
			end
		end
	})

	minetest.register_abm({
		nodenames = "moretrees:palm_leaves",
		interval = moretrees.leafdecay_delay,
		chance = moretrees.leafdecay_chance,
		action = function(pos, node, active_object_count, active_object_count_wider)
			if not minetest.env:find_node_near(pos, moretrees.palm_leafdecay_radius, "moretrees:palm_trunk") then
				minetest.env:remove_node(pos)
				minetest.env:dig_node(pos)
			end
		end
	})
end

if moretrees.enable_replace_default_trees then
	minetest.register_alias("mapgen_tree", "air")
	minetest.register_alias("mapgen_leaves", "air")
	plantslib:register_generate_plant(moretrees.beech_biome, moretrees.beech_model)

elseif moretrees.enable_default_leafdecay then
	minetest.register_abm({
		nodenames = "default:leaves",
		interval = moretrees.default_leafdecay_delay,
		chance = moretrees.default_leafdecay_chance,
		action = function(pos, node, active_object_count, active_object_count_wider)
			if not minetest.env:find_node_near(pos, moretrees.default_leafdecay_radius, {"default:tree"}) then
				minetest.env:remove_node(pos)
				minetest.env:dig_node(pos)
			end
		end
	})	
end