From 29ae8b8cc8dfe50195ad0ef8f5cca6b70a67403b Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Wed, 9 Aug 2017 10:38:02 +0200 Subject: [PATCH] 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 --- init.lua | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/init.lua b/init.lua index 626b70a..b24dbf7 100644 --- a/init.lua +++ b/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)