From 5b692cfeb09b6103ea8606e91bfd042e3b7a0f6f Mon Sep 17 00:00:00 2001 From: Treer Date: Sun, 28 May 2023 23:28:09 +1000 Subject: [PATCH] fix toolranks support for Nether Pickaxe combine the after_use() event of nethertools with toolranks --- .luacheckrc | 3 +++ tools.lua | 36 ++++++++++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.luacheckrc b/.luacheckrc index 319eba3..6946337 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -27,9 +27,12 @@ read_globals = { "stairsplus", "string.split", table = { fields = { "copy", "getn" } }, + "technic", + "toolranks", "vector", "VoxelArea", "VoxelManip", + "walls", xpanes = { fields = { "register_pane" } }, } diff --git a/tools.lua b/tools.lua index fa4de94..fca8a03 100644 --- a/tools.lua +++ b/tools.lua @@ -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