mirror of
https://github.com/lisacvuk/minetest-toolranks.git
synced 2025-01-09 15:30:17 +01:00
Add check for tool_capabilities
and fallback if not defined (#15)
* add check for `tool_capabilities` and fallback if not defined * fix whitespace
This commit is contained in:
parent
d000b4b20f
commit
12af618f9b
13
init.lua
13
init.lua
@ -110,7 +110,8 @@ function toolranks.new_afteruse(itemstack, user, node, digparams)
|
|||||||
to_player = user:get_player_name(),
|
to_player = user:get_player_name(),
|
||||||
gain = 2.0,
|
gain = 2.0,
|
||||||
})
|
})
|
||||||
|
-- Make tool better by modifying tool_capabilities (if defined)
|
||||||
|
if itemdef.tool_capabilities then
|
||||||
local speed_multiplier = 1 + (level * level_multiplier * (max_speed - 1))
|
local speed_multiplier = 1 + (level * level_multiplier * (max_speed - 1))
|
||||||
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
||||||
local caps = table.copy(itemdef.tool_capabilities)
|
local caps = table.copy(itemdef.tool_capabilities)
|
||||||
@ -126,10 +127,18 @@ function toolranks.new_afteruse(itemstack, user, node, digparams)
|
|||||||
end
|
end
|
||||||
itemmeta:set_tool_capabilities(caps)
|
itemmeta:set_tool_capabilities(caps)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Old method for compatibility with tools without tool_capabilities defined
|
||||||
|
local wear = digparams.wear
|
||||||
|
if level > 0 and not itemdef.tool_capabilities then
|
||||||
|
local use_multiplier = 1 + (level * level_multiplier * (max_use - 1))
|
||||||
|
wear = wear / use_multiplier
|
||||||
|
end
|
||||||
|
|
||||||
itemmeta:set_string("lastlevel", level)
|
itemmeta:set_string("lastlevel", level)
|
||||||
itemmeta:set_string("description", toolranks.create_description(itemdesc, dugnodes))
|
itemmeta:set_string("description", toolranks.create_description(itemdesc, dugnodes))
|
||||||
itemstack:add_wear(digparams.wear)
|
itemstack:add_wear(wear)
|
||||||
return itemstack
|
return itemstack
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user