From 5b692cfeb09b6103ea8606e91bfd042e3b7a0f6f Mon Sep 17 00:00:00 2001 From: Treer Date: Sun, 28 May 2023 23:28:09 +1000 Subject: [PATCH 1/2] 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 From d84cc4ba7e76784c4cd1adf22805d83f74032452 Mon Sep 17 00:00:00 2001 From: Treer Date: Sun, 28 May 2023 23:34:12 +1000 Subject: [PATCH 2/2] treat technic variable as read-only fix luacheck warning: nether-compressor-recipe.lua:5:10: setting read-only field 'register_compressor_recipe' of global 'technic' since a local function is all we need --- nether-compressor-recipe.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nether-compressor-recipe.lua b/nether-compressor-recipe.lua index 53b90eb..5400161 100644 --- a/nether-compressor-recipe.lua +++ b/nether-compressor-recipe.lua @@ -2,7 +2,7 @@ local S = minetest.get_translator("nether") technic.register_recipe_type("compressing", { description = S("Compressing") }) -function technic.register_compressor_recipe(data) +function register_compressor_recipe(data) data.time = data.time or 4 technic.register_recipe("compressing", data) end @@ -46,7 +46,7 @@ minetest.clear_craft({ }) for _, data in pairs(recipes) do - technic.register_compressor_recipe({input = {data[1]}, output = data[2], time = data[3]}) + register_compressor_recipe({input = {data[1]}, output = data[2], time = data[3]}) end