mirror of
https://github.com/lisacvuk/minetest-toolranks.git
synced 2025-01-24 22:50: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
|
return newdesc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function toolranks.log2(value)
|
||||||
|
return math.log(value) / math.log(2)
|
||||||
|
end
|
||||||
|
|
||||||
function toolranks.get_level(uses)
|
function toolranks.get_level(uses)
|
||||||
if uses <= 100 then
|
level = math.ceil(toolranks.log2(uses / 100)) + 1
|
||||||
return 1
|
if level < 1 then
|
||||||
elseif uses < 200 then
|
level = 1
|
||||||
return 2
|
|
||||||
elseif uses < 400 then
|
|
||||||
return 3
|
|
||||||
elseif uses < 800 then
|
|
||||||
return 4
|
|
||||||
elseif uses < 1600 then
|
|
||||||
return 5
|
|
||||||
else
|
|
||||||
return 6
|
|
||||||
end
|
end
|
||||||
|
return level
|
||||||
end
|
end
|
||||||
|
|
||||||
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
function toolranks.new_afteruse(itemstack, user, node, digparams)
|
||||||
|
Loading…
Reference in New Issue
Block a user