mirror of
https://github.com/minetest-mods/nether.git
synced 2024-09-27 14:50:38 +02:00
local function + formatting
This commit is contained in:
parent
0301d9f1ca
commit
24d46c4c64
14
tools.lua
14
tools.lua
|
@ -155,20 +155,23 @@ minetest.register_craft({
|
||||||
|
|
||||||
if minetest.get_modpath("toolranks") then
|
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
|
local nethertool_after_use = ItemStack(name):get_definition().after_use
|
||||||
toolranks.add_tool(name)
|
toolranks.add_tool(name)
|
||||||
local toolranks_after_use = ItemStack(name):get_definition().after_use
|
local toolranks_after_use = ItemStack(name):get_definition().after_use
|
||||||
|
|
||||||
if (nethertool_after_use ~= nil and nethertool_after_use ~= toolranks_after_use) then
|
if nethertool_after_use == nil or nethertool_after_use == toolranks_after_use then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
minetest.override_item(name, {
|
minetest.override_item(name, {
|
||||||
after_use = function(itemstack, user, node, digparams)
|
after_use = function(itemstack, user, node, digparams)
|
||||||
-- combine nethertool_after_use and toolranks_after_use by allowing
|
-- combine nethertool_after_use and toolranks_after_use by allowing
|
||||||
-- nethertool_after_use() to calculate the wear...
|
-- nethertool_after_use() to calculate the wear...
|
||||||
local initialWear = itemstack:get_wear()
|
local initial_wear = itemstack:get_wear()
|
||||||
itemstack = nethertool_after_use(itemstack, user, node, digparams)
|
itemstack = nethertool_after_use(itemstack, user, node, digparams)
|
||||||
local wear = itemstack:get_wear() - initialWear
|
local wear = itemstack:get_wear() - initial_wear
|
||||||
itemstack:set_wear(initialWear) -- restore/undo the wear
|
itemstack:set_wear(initial_wear) -- restore/undo the wear
|
||||||
|
|
||||||
-- ...and have toolranks_after_use() apply the wear.
|
-- ...and have toolranks_after_use() apply the wear.
|
||||||
digparams.wear = wear
|
digparams.wear = wear
|
||||||
|
@ -176,7 +179,6 @@ if minetest.get_modpath("toolranks") then
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
add_toolranks("nether:pick_nether")
|
add_toolranks("nether:pick_nether")
|
||||||
add_toolranks("nether:shovel_nether")
|
add_toolranks("nether:shovel_nether")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user