diff --git a/tools.lua b/tools.lua index fca8a03..740bf83 100644 --- a/tools.lua +++ b/tools.lua @@ -155,27 +155,29 @@ minetest.register_craft({ if minetest.get_modpath("toolranks") then - function add_toolranks(name) + local function add_toolranks(name) local nethertool_after_use = ItemStack(name):get_definition().after_use toolranks.add_tool(name) local toolranks_after_use = ItemStack(name):get_definition().after_use - if (nethertool_after_use ~= nil and nethertool_after_use ~= toolranks_after_use) then - minetest.override_item(name, { - after_use = function(itemstack, user, node, digparams) - -- combine nethertool_after_use and toolranks_after_use by allowing - -- nethertool_after_use() to calculate the wear... - local initialWear = itemstack:get_wear() - itemstack = nethertool_after_use(itemstack, user, node, digparams) - local wear = itemstack:get_wear() - initialWear - itemstack:set_wear(initialWear) -- restore/undo the wear - - -- ...and have toolranks_after_use() apply the wear. - digparams.wear = wear - return toolranks_after_use(itemstack, user, node, digparams) - end - }) + if nethertool_after_use == nil or nethertool_after_use == toolranks_after_use then + return end + + minetest.override_item(name, { + after_use = function(itemstack, user, node, digparams) + -- combine nethertool_after_use and toolranks_after_use by allowing + -- nethertool_after_use() to calculate the wear... + local initial_wear = itemstack:get_wear() + itemstack = nethertool_after_use(itemstack, user, node, digparams) + local wear = itemstack:get_wear() - initial_wear + itemstack:set_wear(initial_wear) -- restore/undo the wear + + -- ...and have toolranks_after_use() apply the wear. + digparams.wear = wear + return toolranks_after_use(itemstack, user, node, digparams) + end + }) end add_toolranks("nether:pick_nether")