fix toolranks support for Nether Pickaxe

combine the after_use() event of nethertools with toolranks
This commit is contained in:
Treer 2023-05-28 23:28:09 +10:00
parent add8d74323
commit 5b692cfeb0
2 changed files with 33 additions and 6 deletions

View File

@ -27,9 +27,12 @@ read_globals = {
"stairsplus",
"string.split",
table = { fields = { "copy", "getn" } },
"technic",
"toolranks",
"vector",
"VoxelArea",
"VoxelManip",
"walls",
xpanes = { fields = { "register_pane" } },
}

View File

@ -153,6 +153,36 @@ minetest.register_craft({
})
if minetest.get_modpath("toolranks") then
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
})
end
end
add_toolranks("nether:pick_nether")
add_toolranks("nether:shovel_nether")
add_toolranks("nether:axe_nether")
add_toolranks("nether:sword_nether")
end
--===========================--
@ -360,9 +390,3 @@ minetest.register_tool("nether:lightstaff_eternal", {
return itemstack
end
})
if minetest.get_modpath("toolranks") then
-- toolranks.add_tool("nether:pick_nether")
toolranks.add_tool("nether:shovel_nether")
toolranks.add_tool("nether:axe_nether")
toolranks.add_tool("nether:sword_nether")
end