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.
master
Vanessa Ezekowitz 2013-02-19 21:50:56 -05:00
parent a86c52cfa8
commit 6bfb454178
2 changed files with 21 additions and 2 deletions

View File

@ -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)

View File

@ -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")