Add tool callback

This commit is contained in:
Novatux 2013-05-06 18:53:15 +02:00 committed by proller
parent 4e5760a541
commit 34e0a0ca0f
2 changed files with 21 additions and 7 deletions

@ -384,13 +384,18 @@ function minetest.node_dig(pos, node, digger)
local wielded = digger:get_wielded_item()
local drops = minetest.get_node_drops(node.name, wielded:get_name())
-- Wear out tool
if not minetest.setting_getbool("creative_mode") then
local wdef = wielded:get_definition()
local tp = wielded:get_tool_capabilities()
local dp = minetest.get_dig_params(def.groups, tp)
if wdef and wdef.after_use then
wielded = wdef.after_use(wielded, digger, node, dp) or wielded
else
-- Wear out tool
if not minetest.setting_getbool("creative_mode") then
wielded:add_wear(dp.wear)
digger:set_wielded_item(wielded)
end
end
digger:set_wielded_item(wielded)
-- Handle drops
minetest.handle_node_drops(pos, drops, digger)

@ -1980,6 +1980,15 @@ Item definition (register_node, register_craftitem, register_tool)
eg. itemstack:take_item(); return itemstack
^ Otherwise, the function is free to do what it wants.
^ The default functions handle regular use cases.
after_use = func(itemstack, user, node, digparams),
^ default: nil
^ If defined, should return an itemstack and will be called instead of
wearing out the tool. If returns nil, does nothing.
If after_use doesn't exist, it is the same as:
function(itemstack, user, node, digparams)
itemstack:add_wear(digparams.wear)
return itemstack
end
}
Tile definition: