Add a setting to disallow digging a tree if no tool would become worn out
This commit is contained in:
parent
b68948ef34
commit
fbffeff665
@ -26,4 +26,6 @@ TODO:
|
||||
* use range_up and range_down for other trees too for greater precision in neighbour detection
|
||||
* improve moretrees support (see issue #2)
|
||||
* moretrees acacia
|
||||
* more precise neighbour detection for moretrees (cedar), fix moretree jungletree ignoring default jungletrees' leaves
|
||||
* more precise neighbour detection for moretrees (cedar), fix moretree jungletree ignoring default jungletrees' leaves
|
||||
* technic chainsaw
|
||||
* proper documentation
|
58
api.lua
58
api.lua
@ -1,24 +1,9 @@
|
||||
-- the table containing the tree definitions
|
||||
treecapitator.trees = {}
|
||||
|
||||
-- test if trunk nodes were redefined
|
||||
local after_dig_nodes = {}
|
||||
minetest.after(2, function()
|
||||
for i = 1,#after_dig_nodes do
|
||||
local nodename = after_dig_nodes[i]
|
||||
if not minetest.registered_nodes[nodename].after_dig_node then
|
||||
error(nodename .. " didn't keep after_dig_node.")
|
||||
end
|
||||
end
|
||||
after_dig_nodes = nil
|
||||
end)
|
||||
|
||||
-- wrapping is necessary, someone may overwrite treecapitator.capitate_tree
|
||||
local function after_dig_wrap(pos, _,_, digger)
|
||||
treecapitator.capitate_tree(pos, digger)
|
||||
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
|
||||
@ -49,3 +34,42 @@ function treecapitator.register_tree(tr)
|
||||
after_dig_nodes[#after_dig_nodes+1] = nodename
|
||||
end
|
||||
end
|
||||
|
||||
-- Mods can set treecapitator.capitation_usually_disallowed to true and
|
||||
-- override this function, with params pos and digger, to make capitation
|
||||
-- transpire only under certain contitions.
|
||||
function treecapitator.capitation_allowed()
|
||||
return not treecapitator.capitation_usually_disallowed
|
||||
end
|
||||
|
||||
|
||||
-- Example of overriding this function
|
||||
if treecapitator.no_hand_capitation then
|
||||
-- disallow capitating trees if no proper tool is used
|
||||
treecapitator.capitation_usually_disallowed = true
|
||||
local allowed = treecapitator.capitation_allowed
|
||||
function treecapitator.capitation_allowed(pos, digger)
|
||||
local def = minetest.registered_nodes[
|
||||
minetest.get_node{x=pos.x, y=pos.y+1, z=pos.z}.name
|
||||
]
|
||||
return def and def.groups and minetest.get_dig_params(def.groups,
|
||||
digger:get_wielded_item():get_tool_capabilities()).wear > 0
|
||||
or allowed(pos, digger)
|
||||
end
|
||||
end
|
||||
|
||||
-- test if trunk nodes were redefined
|
||||
minetest.after(2, function()
|
||||
for i = 1,#after_dig_nodes do
|
||||
local nodename = after_dig_nodes[i]
|
||||
if not minetest.registered_nodes[nodename].after_dig_node then
|
||||
error(nodename .. " didn't keep after_dig_node.")
|
||||
end
|
||||
end
|
||||
after_dig_nodes = nil
|
||||
end)
|
||||
|
||||
-- wrapping is necessary, someone may overwrite treecapitator.capitate_tree
|
||||
function after_dig_wrap(pos, _,_, digger)
|
||||
treecapitator.capitate_tree(pos, digger)
|
||||
end
|
||||
|
4
init.lua
4
init.lua
@ -9,6 +9,7 @@ treecapitator = {
|
||||
drop_leaf = false,
|
||||
play_sound = true,
|
||||
moretrees_support = false,
|
||||
no_hand_capitation = false,
|
||||
delay = 0,
|
||||
stem_height_min = 3,
|
||||
default_tree = { --replaces not defined stuff (see below)
|
||||
@ -927,7 +928,8 @@ local capitating = false --necessary if minetest.node_dig is used
|
||||
function treecapitator.capitate_tree(pos, digger)
|
||||
if capitating
|
||||
or not digger
|
||||
or digger:get_player_control().sneak then
|
||||
or digger:get_player_control().sneak
|
||||
or not treecapitator.capitation_allowed(pos, digger) then
|
||||
return
|
||||
end
|
||||
local t1 = minetest.get_us_time()
|
||||
|
@ -13,6 +13,10 @@ treecapitator.moretrees_support (support moretrees) bool false
|
||||
# lets trees become capitated <delay> seconds later, only works if it's > 0
|
||||
treecapitator.delay (delay) float 0 0
|
||||
|
||||
# If set to true, capitating only works with tools with trunk digging
|
||||
# capabilities and not with the bare hand, so when a tool is worn.
|
||||
treecapitator.no_hand_capitation (Disallow bare hand capitation) bool false
|
||||
|
||||
# considers trunks as neighbour trees if there're >= stem_height_min trunks
|
||||
# if set too low, vertical trunk fruits may be recognized as neighbour tree
|
||||
# if set too high, short stemmed neighbour trees are not recognited
|
||||
|
Loading…
x
Reference in New Issue
Block a user