mirror of
https://github.com/lisacvuk/minetest-toolranks.git
synced 2025-01-24 14:40:18 +01:00
Support an infinite number of levels
Rationale: It is possible to craft a tool with less wear by combining two tools of the same type. This allows to use tools longer than level 6 which was a hard limit in the previous implementation
This commit is contained in:
parent
5bfb603bf4
commit
29ae8b8cc8
20
init.lua
20
init.lua
@ -32,20 +32,16 @@ function toolranks.create_description(name, uses, level)
|
||||
return newdesc
|
||||
end
|
||||
|
||||
function toolranks.log2(value)
|
||||
return math.log(value) / math.log(2)
|
||||
end
|
||||
|
||||
function toolranks.get_level(uses)
|
||||
if uses <= 100 then
|
||||
return 1
|
||||
elseif uses < 200 then
|
||||
return 2
|
||||
elseif uses < 400 then
|
||||
return 3
|
||||
elseif uses < 800 then
|
||||
return 4
|
||||
elseif uses < 1600 then
|
||||
return 5
|
||||
else
|
||||
return 6
|
||||
level = math.ceil(toolranks.log2(uses / 100)) + 1
|
||||
if level < 1 then
|
||||
level = 1
|
||||
end
|
||||
return level
|
||||
end
|
||||
|
||||
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
||||
|
Loading…
Reference in New Issue
Block a user