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
34
tools.lua
34
tools.lua
|
@ -155,27 +155,29 @@ 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
|
||||||
minetest.override_item(name, {
|
return
|
||||||
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
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
add_toolranks("nether:pick_nether")
|
add_toolranks("nether:pick_nether")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user