diff options
author | Wuzzy <almikes@aol.com> | 2016-12-13 13:59:57 +0100 |
---|---|---|
committer | Wuzzy <almikes@aol.com> | 2016-12-13 13:59:57 +0100 |
commit | 98b8c7000f30c0f23659e029d4be215ad74e112e (patch) | |
tree | 0ef4ccb1ec7fd8a873797321b6e986d25c66fbf2 /init.lua | |
parent | 602046b935450f1bf08712b578219043fa3905e6 (diff) |
Add mining tool durability
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -145,6 +145,31 @@ local burntime_to_text = function(burntime) end end +local mining_durability_factoid = function(tool_capabilities) + local formstring = "" + if tool_capabilities ~= nil and tool_capabilities ~= {} then + local groupcaps = tool_capabilities.groupcaps + if groupcaps ~= nil then + local lines = 0 + for k,v in pairs(groupcaps) do + if v.maxlevel ~= nil and v.uses ~= nil and v.uses > 0 then + for level=0, v.maxlevel do + local uses = v.uses * math.pow(3, v.maxlevel - level) + formstring = formstring .. S("• @1, level @2: @3 uses", doc.sub.items.get_group_name(k), level, uses) + formstring = formstring .. "\n" + lines = lines + 1 + end + end + end + if lines >= 1 then + formstring = S("Mining durability:") .. "\n" .. formstring + formstring = newline2(formstring) + end + end + end + return formstring +end + local toolcaps_to_text = function(tool_capabilities) local formstring = "" if tool_capabilities ~= nil and tool_capabilities ~= {} then @@ -833,11 +858,17 @@ doc.new_category("tools", { datastring = datastring .. range_factoid(data.itemstring, data.def) datastring = newline(datastring) if type(data.def._doc_items_durability) == "number" then + -- Fixed number of uses datastring = datastring .. S("Durability: @1 uses", data.def._doc_items_durability) datastring = newline(datastring) elseif type(data.def._doc_items_durability) == "string" then + -- Manually described durability datastring = datastring .. S("Durability: @1", data.def._doc_items_durability) datastring = newline(datastring) + else + -- Automatically detect durability for mining tools + datastring = datastring .. mining_durability_factoid(data.def.tool_capabilities) + datastring = newline(datastring) end datastring = newline2(datastring) |