diff options
author | h-v-smacker <hans-von-smacker+github@gmail.com> | 2018-04-29 23:14:13 +0300 |
---|---|---|
committer | h-v-smacker <hans-von-smacker+github@gmail.com> | 2018-04-29 23:14:13 +0300 |
commit | fe0984b698e6465a0ecf2454d04bba629aeaaca0 (patch) | |
tree | 567411b517d291b62a91c55774e3c5d5b5a78dec /trees.lua | |
parent | 570960e24b217711979d5d29d08a9eb075de9950 (diff) |
initial commit
Diffstat (limited to 'trees.lua')
-rw-r--r-- | trees.lua | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/trees.lua b/trees.lua new file mode 100644 index 0000000..b308bc1 --- /dev/null +++ b/trees.lua @@ -0,0 +1,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 + + + |