No default values for trees
, leaves
and range
in treecapitator.register_tree
These default tree definition options are non-obvious, so although their use may slightly shorten code in a few situations, the code would be more difficult to understand. To check for backwards-compatibility problems, `treecapitator.register_tree` now checks if these three options are set when required. Furthermore, `treecapitator.register_tree` now no longer modifies the passed table in-place. This is a breaking change since there might exist mod which uses the default values.
This commit is contained in:
parent
d764f4174d
commit
4737e9cd04
32
api.lua
32
api.lua
@ -1,15 +1,37 @@
|
||||
-- the table containing the tree definitions
|
||||
treecapitator.trees = {}
|
||||
|
||||
-- Warn if a tree definition passed to treecapitator.register_tree contains
|
||||
-- invalid options, partly for backwards compatibility.
|
||||
-- Not all options are checked.
|
||||
local function check_tree_definition(tr)
|
||||
if type(tr.trees) ~= "table" then
|
||||
minetest.log("warning",
|
||||
"[treecapitator] Invalid tree definition (trees field)")
|
||||
end
|
||||
if tr.type ~= "acacia" then
|
||||
if type(tr.leaves) ~= "table" then
|
||||
minetest.log("warning",
|
||||
"[treecapitator] Invalid tree definition (leaves field)")
|
||||
end
|
||||
if type(tr.range) ~= "number" then
|
||||
minetest.log("warning",
|
||||
"[treecapitator] Invalid tree definition (range field)")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- For the usage of this function, see trees.lua.
|
||||
local after_dig_wrap
|
||||
local after_dig_nodes = {}
|
||||
function treecapitator.register_tree(tr)
|
||||
for name,value in pairs(treecapitator.default_tree) do
|
||||
if tr[name] == nil then
|
||||
tr[name] = value --replaces not defined stuff
|
||||
end
|
||||
function treecapitator.register_tree(tree_definition)
|
||||
check_tree_definition(tree_definition)
|
||||
local tr = {}
|
||||
for name, value in pairs(tree_definition) do
|
||||
tr[name] = value
|
||||
end
|
||||
tr.fruits = tr.fruits or {}
|
||||
tr.type = tr.type or "default"
|
||||
treecapitator.trees[#treecapitator.trees+1] = tr
|
||||
if treecapitator.after_register[tr.type] then
|
||||
treecapitator.after_register[tr.type](tr)
|
||||
|
Loading…
x
Reference in New Issue
Block a user