mirror of
https://github.com/minetest-mods/nether.git
synced 2024-11-15 23:10:37 +01:00
local function + formatting
This commit is contained in:
parent
0301d9f1ca
commit
24d46c4c64
34
tools.lua
34
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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user