From 6bfb454178b3ce9544333ab952dd8f69d9841666 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Tue, 19 Feb 2013 21:50:56 -0500 Subject: [PATCH] routed spawn_tree() through a wrapper function so that other mods can hook into plants_lib's calls to do something extra when a tree is generated at mapgen time or spawned via the growing code. --- API.txt | 6 ++++++ plants_lib/init.lua | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/API.txt b/API.txt index b6c4173..f0ac4fb 100644 --- a/API.txt +++ b/API.txt @@ -22,6 +22,12 @@ All functions in plants lib are declared locally to avoid namespace collisions with other mods. They are accessible via the "plantslib" method, e.g. plantslib:spawn_on_surfaces() and so forth. +In the case of the growing code and the mapgen-based tree generator code, the +usual spawn_tree() calls used therein are routed through +plantslib:generate_tree() and plantslib:grow_tree(), which just directly call +the spawn_tree() function anyway. This way other mods can wedge into these +two calls by name, to execute something extra whenever a tree is spawned via +this library. ===== spawn_on_surfaces(biome) diff --git a/plants_lib/init.lua b/plants_lib/init.lua index 870c084..f3d0856 100644 --- a/plants_lib/init.lua +++ b/plants_lib/init.lua @@ -133,7 +133,7 @@ function plantslib:search_for_surfaces(minp, maxp, biomedef, node_or_function_or end ]]-- - minetest.env:spawn_tree(pos, node_or_function_or_model) + plantslib:generate_tree(pos, node_or_function_or_model) elseif type(node_or_function_or_model) == "string" then if minetest.registered_nodes[node_or_function_or_model] == nil then @@ -353,7 +353,7 @@ function plantslib:replace_object(pos, replacement, grow_function, walldir, seed if growtype == "table" then plantslib:dbg("Grow: spawn tree at "..dump(pos)) minetest.env:remove_node(pos) - minetest.env:spawn_tree(pos, grow_function) + plantslib:grow_tree(pos, grow_function) return elseif growtype == "string" then local perlin1 = minetest.env:get_perlin(seeddiff, perlin_octaves, perlin_persistence, perlin_scale) @@ -418,4 +418,17 @@ function plantslib:find_open_side(pos) return nil end +-- spawn_tree() on generate is routed through here so that other mods can hook +-- into it. + +function plantslib:generate_tree(pos, node_or_function_or_model) + minetest.env:spawn_tree(pos, node_or_function_or_model) +end + +-- and this one's for the call used in the growing code + +function plantslib:grow_tree(pos, node_or_function_or_model) + minetest.env:spawn_tree(pos, node_or_function_or_model) +end + print("[Plantlife Library] Loaded")