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
|
-- the table containing the tree definitions
|
||||||
treecapitator.trees = {}
|
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.
|
-- For the usage of this function, see trees.lua.
|
||||||
local after_dig_wrap
|
local after_dig_wrap
|
||||||
local after_dig_nodes = {}
|
local after_dig_nodes = {}
|
||||||
function treecapitator.register_tree(tr)
|
function treecapitator.register_tree(tree_definition)
|
||||||
for name,value in pairs(treecapitator.default_tree) do
|
check_tree_definition(tree_definition)
|
||||||
if tr[name] == nil then
|
local tr = {}
|
||||||
tr[name] = value --replaces not defined stuff
|
for name, value in pairs(tree_definition) do
|
||||||
end
|
tr[name] = value
|
||||||
end
|
end
|
||||||
|
tr.fruits = tr.fruits or {}
|
||||||
|
tr.type = tr.type or "default"
|
||||||
treecapitator.trees[#treecapitator.trees+1] = tr
|
treecapitator.trees[#treecapitator.trees+1] = tr
|
||||||
if treecapitator.after_register[tr.type] then
|
if treecapitator.after_register[tr.type] then
|
||||||
treecapitator.after_register[tr.type](tr)
|
treecapitator.after_register[tr.type](tr)
|
||||||
|
7
init.lua
7
init.lua
@ -12,13 +12,6 @@ treecapitator = {
|
|||||||
no_hand_capitation = false,
|
no_hand_capitation = false,
|
||||||
delay = 0,
|
delay = 0,
|
||||||
stem_height_min = 3,
|
stem_height_min = 3,
|
||||||
default_tree = { --replaces not defined stuff (see below)
|
|
||||||
trees = {"default:tree"},
|
|
||||||
leaves = {"default:leaves"},
|
|
||||||
range = 2,
|
|
||||||
fruits = {},
|
|
||||||
type = "default",
|
|
||||||
},
|
|
||||||
after_register = {},
|
after_register = {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user