local function + formatting

This commit is contained in:
SmallJoker 2024-03-09 19:36:16 +01:00 committed by GitHub
parent 0301d9f1ca
commit 24d46c4c64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 16 deletions

View File

@ -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")