![]() |
VOOZH | about |
This module implements {{breaking row}}.
localp={} localbreakingTimeHeader; localfunctiongetBreakingTimeHeader(f) ifbreakingTimeHeader==nilthen breakingTimeHeader='[[Breaking]] time (sec)'..f:preprocess('<ref group="FN" name="breakingtimenote">These durations ignore any other influential factors (e.g., [[Mining Fatigue]]) and are measured in seconds. For more information, see [[Breaking#Speed|Breaking § Speed]].</ref>') end returnbreakingTimeHeader end localfunctiongetBreakingTimeOptionsRows(f,colums,showEfficiency) localheader=mw.html.create('tr') :css('display','none') :addClass('calculatorgadget-enabled') :tag('th') :attr('colspan',colums+1) :wikitext('Options') :done() localefficiency='' ifshowEfficiencythen efficiency=mw.html.create('tr') :css('display','none') :addClass('calculatorgadget-enabled') :tag('th') :wikitext(f:expandTemplate{title='Simplecalc label',args={ label='[[Efficiency]]', ['for']='efficiencyLevel' }}) :done() :tag('td') :attr('colspan',colums) :tag('div') :css('display','flex') :css('gap','3px') :wikitext( f:expandTemplate{title='Simplecalc',args={ style='font-variant-numeric: tabular-nums; width: 1ch', type='plain', formula='efficiencyLevel', default=0 }}, f:expandTemplate{title='Simplecalc',args={ id='efficiencyLevel', style='width: 85px', type='range', datalist='0;1;2;3;4;5', min=0, max=5, step=1, default=0 }}, f:expandTemplate{title='Simplecalc',args={ id='efficiencySpeed', type='hidden', formula='ifzero(efficiencyLevel, 0, 1 +efficiencyLevel *efficiencyLevel)', default=0 }} ) :done() :done() end localhaste=mw.html.create('tr') :css('display','none') :addClass('calculatorgadget-enabled') :tag('th') :wikitext(f:expandTemplate{title='Simplecalc label',args={ label='[[Haste]]', ['for']='hasteLevel' }}) :done() :tag('td') :css('display','none') :addClass('calculatorgadget-enabled') :attr('colspan',colums) :tag('div') :css('display','flex') :css('gap','3px') :wikitext( f:expandTemplate{title='Simplecalc',args={ style='font-variant-numeric: tabular-nums; width: 1ch', type='plain', formula='hasteLevel', default=0 }}, f:expandTemplate{title='Simplecalc',args={ id='hasteLevel', style='width: 50px', type='range', datalist='0;1;2', min=0, max=2, step=1, default=0 }}, f:expandTemplate{title='Simplecalc',args={ id='hasteMultiplier', type='hidden', formula='(1+0.2*hasteLevel)*ifzero(hasteBE, 1, pow(1.2, hasteLevel))', default=1 }} ) :tag('div') :css('display','flex') :css('gap','inherit') :css('filter','grayscale(calc(1 - min(1,var(--calculator-hasteLevel)))) opacity(calc(0.5 + 0.5 * min(1,var(--calculator-hasteLevel))))') :attr('role','radiogroup') :attr('aria-label','Haste Edition') :attr('id','hasteEdition') :wikitext( f:expandTemplate{title='Simplecalc',args={ id='hasteJE', type='radio', name='hasteEdition', default='1' }}, f:expandTemplate{title='Simplecalc label',args={ label='JE', ['for']='hasteJE' }}, f:expandTemplate{title='Simplecalc',args={ id='hasteBE', type='radio', name='hasteEdition' }}, f:expandTemplate{title='Simplecalc label',args={ label='BE', ['for']='hasteBE' }} ) :done() :done() :done() returntostring(header)..tostring(efficiency)..tostring(haste) end functionp.row(f) localargs=require([[Module:ProcessArgs]]).norm() localsprite=require([[Module:SpriteFile]]) localfunctiongetDplVar(var) localval=f:callParserFunction('#dplvar','breaking '..var) ifval==''then val=false end returnval end localdplVars={} localfunctionsetDplVar(var,val) table.insert(dplVars,'breaking '..var) table.insert(dplVars,valor'1') end localrows={} localtableParts={} localcategories={} localshowOptions=false localhorizontal ifargs.horizontalorargs[1]:match(';')then horizontal=true end localshowTool=true localshowShears=true localshowSword=true localheader,sortable,simple ifhorizontalornotgetDplVar('header')then ifargs.hidetoolorhorizontaland(notargs[2]orargs[2]:lower()=='any'orargs[2]:lower()=='none')then showTool=false setDplVar('hidetool') breakingTimeHeader='[[Breaking]] time (secs)' end ifargs.hideshearsorhorizontalandnotargs.shearsthen showShears=false setDplVar('hideshears') end ifargs.hideswordorhorizontalandnotargs.swordthen showSword=false setDplVar('hidesword') end sortable=nothorizontalandargs.sort ifsortablethen setDplVar('sortable') end simple=args.simple ifsimpleandnothorizontalthen setDplVar('simple') end localtableClasses={'wikitable'} ifsortablethen table.insert(tableClasses,'sortable') end table.insert(rows,' {| class="'..table.concat(tableClasses,' ')..'" style="text-align: center; margin: 0;"') localsortType='' ifsortablethen sortType='data-sort-type="number"' end localrowspan='' ifnothorizontalthen rowspan='rowspan="2" ' end header={ '! '..rowspan..' | Block' } ifnotsimplethen table.insert(header,'! '..rowspan..sortType..' | Hardness') ifshowToolthen table.insert(header,'! '..rowspan..' | Tool') end end localtoolColumns={} ifshowToolthen toolColumns={'Wooden','Stone','Copper','Iron','Diamond','Netherite','Golden'} ifargs.hidenetheritethen table.remove(toolColumns,6) end ifargs.hidecopperorargs.hidenetheritethen table.remove(toolColumns,3) end end table.insert(toolColumns,1,'Default') ifnotsimplethen ifshowShearsthen table.insert(toolColumns,'Shears') end ifshowSwordthen table.insert(toolColumns,'Sword') end end ifnothorizontalthen table.insert(header,'! colspan="'..#toolColumns..'" |'..getBreakingTimeHeader(f)) table.insert(header,'|-') end localtoolType=(args[2]or''):lower() localtoolSprites={ Wooden={}, Stone={}, Copper={}, Iron={}, Diamond={}, Netherite={}, Golden={}, Shears={'shears'}, Sword={'wooden-sword'} } for_,toolinipairs(toolColumns)do iftoolSprites[tool]then localitemName if#toolSprites[tool]==0then iftoolType=='axe'ortoolType=='hoe'ortoolType=='pickaxe'ortoolType=='shovel'ortoolType=='sword'then itemName=tool:lower()..'-'..toolType end else itemName=toolSprites[tool][1] end localimage,spriteCat=sprite.sprite{ name='ItemSprite', itemName, text=tool } ifitemNamethen table.insert(header,'! style="text-align:left" '..sortType..' | '..image) else table.insert(header,'! '..sortType..' | '..tool) end else table.insert(header,'! '..sortType..' | '..tool) end end ifnothorizontalthen header=table.concat(header,'\n') setDplVar('header',header) end table.insert(tableParts,header) else showTool=notgetDplVar('hidetool') showShears=notgetDplVar('hideshears') showSword=notgetDplVar('hidesword') sortable=getDplVar('sortable') simple=getDplVar('simple') end localhardness=require([[Module:Block value]]).value localfunctionfillCells(cellsTable,text,num) fori=1,numdo table.insert(cellsTable,text) end end localmaterialGrade={ Any=0, Wooden=1,Wood=1, Golden=1, Stone=2, Copper=2, Iron=3, Diamond=4, Netherite=5, None=6 } localmaterialSpeed={ None=1, Any=1, Wooden=2,Wood=2, Stone=4, Copper=5, Iron=6, Diamond=8, Netherite=9, Golden=12 } localnumberMaterials=7 localfunctioninsertBlock(blockArgs) localcells={} localblocks=mw.text.split(blockArgs[1],'%s*,%s*') localhardnessVal=tonumber(hardness{blocks[1],type='hardness'}) ifnothardnessValthen hardnessVal='?' localtitle=mw.title.getCurrentTitle() iftitle.namespace==0andnottitle.isSubpagethen table.insert(categories,'[[Category:Missing hardness]]') end end localunbreakable ifhardnessVal==-1orblockArgs.liquidthen unbreakable=true elseifhardnessVal~=0then showOptions=true end localblockSprites={} locallinks=mw.text.split(blockArgs.linkor'','%s*,%s*') localids=mw.text.split(blockArgs.spriteor'','%s*,%s*') localitems=mw.text.split(blockArgs.itemor'','%s*,%s*') fori,blockinipairs(blocks)do locallink ifnotlinks[i]andlinks[1]~=''then link=links[1] elseiflinks[i]~=''then link=links[i] end localid ifnotids[i]andids[1]~=''then id=ids[1] elseifids[i]~=''then id=ids[i] end localblockText ifargs.textTrimthen blockText=block:gsub(args.textTrim..'$','') else blockText=block end localblockSpriteArgs={ name='BlockSprite', block, text=blockText, link=link, id=id } ifitems[i]=='1'ornotitems[i]anditems[1]=='1'then blockSpriteArgs.data='ItemSprite' end localimage,spriteCat=sprite.link(blockSpriteArgs) table.insert(blockSprites,image) table.insert(categories,spriteCat) end table.insert(cells, '!'..(horizontaland''or' style="text-align:left" | ')..table.concat(blockSprites,'<br>')..(blockArgs.noteor'') ) localtool=mw.text.trim(simpleand'Tool'orblockArgs[2]or'Any'):gsub('^%l',string.upper) localmaterial=mw.text.trim(simpleandblockArgs[2]orblockArgs[3]or'Any'):gsub('^%l',string.upper) iftool=='None'then material=tool end ifnotsimplethen localhardnessText=hardnessVal ifhardnessVal==-1then hardnessText=(sortableand'data-sort-value="9999" | 'or'').."-1 (infinite)" end table.insert(cells,'|'..hardnessText) ifshowToolthen localtoolCell='—' iftool~='Any'andtool~='None'then ifmaterial=='Wood'then material='Wooden' end localisMaterialSpecified=(material~='Any')and(material~='None') localtoolName=(isMaterialSpecifiedandmaterial..' 'or'')..tool localtoolSpriteName=toolName..((isMaterialSpecified)and''or' Required') localimage,spriteCat=sprite.sprite{ name=isMaterialSpecifiedand'ItemSprite'or'SlotSprite', toolSpriteName, title=toolName, link=tool, keepcase=notisMaterialSpecified-- SlotSprite has case sensitive names } toolCell=(sortableand'data-sort-value="'..toolName..'" |'or'')..image table.insert(categories,spriteCat) end table.insert(cells,'|'..toolCell) end end localchoices={} localfunctiongetChoice(choice,text) ifnotchoices[choice]then choices[choice]=f:expandTemplate{title='Table Choice',args={choice,''}} end returnchoices[choice]..text end localfunctionprocessTime(actualHardness,baseSpeed,tool) -- the number passed in has been multiplied by 100 localnum=actualHardness/baseSpeed ifnum<=5then-- Blocks with a breaking time <= 1 game tick (0.05 seconds) are instant mined (no delay after each block broken) num="''0.05''"-- Blocks have a minimum breaking time of 1 game tick else-- And they must be broken in multiples of 1 game tick num=math.ceil(num/5)/20 end return'<span class="calculator-field breakingrow-breakingtime-value" data-calculator-type="plain" data-calculator-formula="' ..'max(1,ceil('..(actualHardness/5)..'/('..baseSpeed..((tool~='Any'andtool~='Sword')and'+efficiencySpeed'or'')..')/hasteMultiplier))/20' ..'">'..num..'</span>' end ifhardnessVal=='?'then fillCells(cells,'|?',numberMaterials+1) else ifunbreakablethen table.insert(cells,'| '..(sortableand'data-sort-value="9999" 'or'')..getChoice('no','∞')) ifshowToolthen fillCells(cells,'|—',numberMaterials) end else localdrop='yes' localforceDrop=false ifblockArgs.drop=='0'then drop='partial' elseifblockArgs.drop=='1'then forceDrop='yes' end localrequiredLevel=unbreakableand999ormaterialGrade[material] localfunctioninsertMaterialCell(material) localshouldDrop=drop ifmaterialGrade[material]<requiredLevelthen shouldDrop='no' end -- prevent float number precision loss, multiply by 100 and divide it in processTime function localbreakTime=processTime(hardnessVal*(shouldDrop=='no'and500or150),materialSpeed[material],material) table.insert(cells,'|'..getChoice(forceDroporshouldDrop,breakTime)) end ifnotshowToolortool=='Any'ortool=='None'then insertMaterialCell('Any') ifshowToolthen fillCells(cells,'|—',numberMaterials) end else ifargs.hidenetheritethen for_,materialinipairs{'Any','Wooden','Stone','Iron','Diamond','Golden'}do insertMaterialCell(material) end else ifargs.hidecopperthen for_,materialinipairs{'Any','Wooden','Stone','Iron','Diamond','Netherite','Golden'}do insertMaterialCell(material) end else for_,materialinipairs{'Any','Wooden','Stone','Copper','Iron','Diamond','Netherite','Golden'}do insertMaterialCell(material) end end end end end end ifnotsimpleand(showShearsorshowSword)then localtools={} ifshowShearsthen table.insert(tools,'Shears') end ifshowSwordthen table.insert(tools,'Sword') end ifhardnessVal=='?'then fillCells(cells,'|?',#tools) else localtoolSpeed={ Shears=1, Sword=1.5 } ifblocks[1]=='Wool'orblocks[1]=='Wool Slab'orblocks[1]=='Wool Stairs'then toolSpeed.Shears=5 elseifblocks[1]=='Leaves'then toolSpeed.Shears=15 elseifblocks[1]=='Cobweb'then toolSpeed.Sword=15 toolSpeed.Shears=15 elseifblocks[1]=='Bamboo'orblocks[1]=='Bamboo Shoot'then toolSpeed.Sword=5000 end for_,toolinipairs(tools)do localtoolDrop=blockArgs[mw.ustring.lower(tool)] ifnottoolDropthen table.insert(cells,'|—') else localwillDrop='yes' iftoolDrop=='0'then willDrop='partial' end -- prevent float number precision loss, multiply by 100 and divide it in processTime function localbreakTime=processTime(hardnessVal*150,toolSpeed[tool],tool) table.insert(cells,'|'..getChoice(willDrop,breakTime)) end end end end ifnothorizontalthen cells=table.concat(cells,'\n') end table.insert(tableParts,cells) end ifhorizontalthen localblocksArgs={} for_,arginipairs{1,'note','sprite','link','item','drop',2,3,'shears','sword'}do ifargs[arg]then localcol=0 forcolValinmw.text.gsplit(args[arg],'%s*;%s*')do col=col+1 ifcolVal~=''then ifnotblocksArgs[col]then blocksArgs[col]={} end blocksArgs[col][arg]=colVal end end end end for_,blockinipairs(blocksArgs)do insertBlock(block) end localcolumns=#tableParts forrow=1,#tableParts[1]do localcells={} forcol=1,columnsdo table.insert(cells,tableParts[col][row]) end table.insert(rows,table.concat(cells,'\n')) end -- Insert breaking time header after block row when simple, or after tool or hardness row when not table.insert(rows,simpleand3orshowTooland5or4,'! colspan="'..columns+1..'" |'..getBreakingTimeHeader(f)) ifshowOptionsandnotargs.hideoptionsthen table.insert(rows,getBreakingTimeOptionsRows(f,columns,(showToolorargs.shears))) end else insertBlock(args) for_,rowinipairs(tableParts)do table.insert(rows,row) end table.insert(rows,'') end localnote='' ifargs.footorhorizontalthen note=f:preprocess('<references group="FN"/>') ifargs.foot=='2'then table.insert(rows,headerorgetDplVar('header')) end table.insert(rows,'|}') ifnothorizontalthen f:callParserFunction('#dplvar:set', 'breaking header','', 'breaking hidetool','', 'breaking hideshears','', 'breaking hidesword','', 'breaking simple','', 'breaking sortable','' ) end elseif#dplVars>0then f:callParserFunction('#dplvar:set',dplVars) end localresult=table.concat(rows,'\n|-\n') ifhorizontalthen localstyles=require([[Module:TSLoader]]).call('Template:Breaking row/styles.css')..'\n' returnstyles.. '<div style="--calculator-hasteLevel: 0;" class="calculator-container breakingrow-container">'.. '<div>\n'..result..'\n</div>'.. '<div>'.. "'''Legend'''".. '\n*'..f:expandTemplate{title='legend',args={'',class='tc-no','incorrect tool, drops nothing'}}.. '\n*'..f:expandTemplate{title='legend',args={'',class='tc-partial','correct tool, drops nothing or something other than the block itself'}}.. '\n*'..f:expandTemplate{title='legend',args={'',class='tc-yes','correct tool, drops the block itself'}}.. "\n* ''italicized'' can be [[Instant mining|instant mined]]".. '\n'.. '</div>'.. '</div>'.. note..table.concat(categories) end returnresult..note..table.concat(categories) end returnp