Module:Breaking time
Documentation for this module may be created at Module:Breaking time/doc
local p = {}
local displayItem = require( [[Module:Item]] ).item
local mcWikiLink = require( [[Module:Link]] ).mcWikiLink
local breakingTimeHeader;
local function getBreakingTimeHeader( f )
if breakingTimeHeader == nil then
breakingTimeHeader = '[[Breaking]] time' .. f:preprocess( '<ref group="FN" name="breakingtimenote">Times are for unenchanted tools as wielded by players with no status effects, measured in seconds. For more information, see [[Breaking#Speed|Breaking § Speed]].</ref>' )
end
return breakingTimeHeader
end
function ucfirst(s)
if s == nil then s = "" end
return s:gsub("(%w)([%w']*)", function(a,b) return string.upper(a)..b end)
end
function p.breaking( f )
local args = require( [[Module:ProcessArgs]] ).norm()
local materials = {
any = {grade=0,speed=1,display={nolink=true,item='Default',img='Blank'}},
wooden = {grade=1,speed=2,display={nolink=true,item='Wooden',img='Oak Planks'}},
stone = {grade=2,speed=4,display={nolink=true,item='Stone',img='Cobblestone'}},
iron = {grade=3,speed=6,display={nolink=true,item='Iron',img='Iron Ingot'}},
diamond = {grade=4,speed=8,display={nolink=true,item='Diamond'}},
netherite = {grade=5,speed=9,display={nolink=true,item='Netherite',img='Netherite Ingot'}},
golden = {grade=1,speed=12,display={nolink=true,item='Golden',img='Gold Ingot'}},
}
local tools = {
pickaxe=2,
axe=2,
sword=2,
shovel=2,
shears=1,
bucket=1,
}
local hardness = args[1] or args.hardness or args.h
local requiredGrade = args[2] or args.material or args.mat or args.grade
local tool1 = args[3] or args.tool or args.tool1 or args.t or args.t1
local tool2 = args[4] or args.tool2 or args.t2
if not hardness then return '<strong><font color="red">Missing argument #1 (hardness)</font></strong>' end
if (not requiredGrade or not materials[requiredGrade]) and tools[tool1] == 2 then return '<strong><font color="red">Missing argument #2 (required material)</font></strong>' end
if not tool1 then return '<strong><font color="red">Missing argument #3 (tool)</font></strong>' end
hardness = tonumber(hardness)
requiredGrade = requiredGrade:lower()
tool1 = tool1:lower()
if tool2 then tool2 = tool2:lower() end
local table = mw.html.create('table')
:tag('tr')
:tag('th'):wikitext('Hardness'):done()
:tag('td'):wikitext(hardness):attr{colspan=tool2 and 2 or 1}:done()
:done()
if tool2 then
table:tag('tr')
:tag('th'):wikitext('Tool'):done()
:tag('td'):wikitext(table.concat{
'[[File:', tools[tool1] == 2 and ucfirst(requiredGrade) or '', ' ', ucfirst(tool1), '.png|21px|link=w:c:minecraft:', ucfirst(tool1), ']]'
}):done()
:tag('td'):wikitext(table.concat{
'[[File:', tools[tool2] == 2 and ucfirst(requiredGrade) or '', ' ', ucfirst(tool2), '.png|21px|link=w:c:minecraft:', ucfirst(tool2), ']]'
}):done()
:done()
else
table:tag('tr')
:tag('th'):wikitext('Tool'):done()
:tag('td'):wikitext(table.concat{
'[[File:', tools[tool1] == 2 and ucfirst(requiredGrade) or '', ' ', ucfirst(tool1), '.png|21px|link=w:c:minecraft:', ucfirst(tool1), ']]'
}):done()
:done()
end
table:tag('tr')
:tag('th')
:wikitext(mcWikiLink('Breaking')..' time' .. f:preprocess( '<ref group="FN" name="breakingtimenote">Times are for unenchanted tools as wielded by players with no status effects, measured in seconds. For more information, see '..mcWikiLink('Breaking#Speed', 'Breaking § Speed')..'.</ref>' ))
:attr{colspan=tool2 and 3 or 2}
:done()
:done()
for k,v in pairs(materials) do
local reqGradeNum = materials[requiredGrade].grade
local calc = v.speed
calc = calc / hardness
local wasDividedBy30 = false
if v.grade >= reqGradeNum then
calc = calc / 30
wasDividedBy30 = true
else
calc = calc / 100
end
calc = 1 / calc
calc = math.ceil(calc)
calc = calc / 20
if tool2 then
table:tag('tr')
:tag('th'):wikitext(displayItem(v.display)):done()
:tag('td'):wikitext(calc):addClass((v.grade >= reqGradeNum) and 'green' or 'red'):done()
:tag('td'):wikitext(wasDividedBy30 and calc*0.3 or calc):addClass((v.grade >= reqGradeNum) and 'green' or 'red'):done()
:done()
else
table:tag('tr')
:tag('th'):wikitext(displayItem(v.display)):done()
:tag('td'):wikitext(calc):addClass((v.grade >= reqGradeNum) and 'green' or 'red'):done()
:done()
end
end
return tostring(table)
end
return p