summaryrefslogtreecommitdiff
path: root/trees.lua
blob: b308bc1d2312c8e4031c90153bb1e0adf0cd072b (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
local random = math.random

-- I don't remember if snow function is needed.
local function is_snow_nearby(pos)
	return minetest.find_node_near(pos, 1,
		{"default:snow", "default:snowblock", "default:dirt_with_snow"})
end


-- Sapling ABM

function maple.grow_sapling(pos)
	if not default.can_grow(pos) then
		-- Can't grow yet, try later.
		minetest.get_node_timer(pos):start(math.random(240, 600))
		return
	end

	local mg_name = minetest.get_mapgen_setting("mg_name")
	local node = minetest.get_node(pos)

	if node.name == "maple:maple_sapling" then
		minetest.log("action", "An maple sapling grows into a tree at "..
			minetest.pos_to_string(pos))
		minetest.remove_node(pos)
		maple.grow_new_maple_tree(pos)
	end
end

minetest.register_lbm({
	name = "maple:convert_saplings_to_node_timer",
	nodenames = {"maple:maple_sapling"},
	action = function(pos)
		minetest.get_node_timer(pos):start(math.random(1200, 2400))
	end
})

--
-- Tree generation
--

-- New maple tree

function maple.grow_new_maple_tree(pos)
	local path = minetest.get_modpath("maple") ..
		"/schematics/maple_tree.mts"
	minetest.place_schematic({x = pos.x - 3, y = pos.y, z = pos.z - 3},
		path, "0", nil, false)
end