Moduł:Breaking row: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
| [wersja przejrzana] | [wersja przejrzana] |
Moduł z angielskiej wiki. |
zmieniam tylko tekst w przypisie. |
||
| (Nie pokazano 1 wersji utworzonej przez jednego użytkownika) | |||
| Linia 1: | Linia 1: | ||
local p = {} | local p = {} | ||
local polish = mw.language.new('pl') | |||
local breakingTimeHeader; | local breakingTimeHeader; | ||
local function getBreakingTimeHeader( f ) | local function getBreakingTimeHeader( f ) | ||
if breakingTimeHeader == nil then | |||
breakingTimeHeader = 'Czas wydobycia (sekundy)' .. f:preprocess( '<ref group="FN" name="breakingtimenote">Czasy nie biorą pod uwagę [[Zaklinanie|zaklęć]], [[efekt]]ów i innych czynników, jak np. zanurzenie w wodzie.</ref>' ) | |||
end | |||
return breakingTimeHeader | |||
end | end | ||
p.row | |||
local args = require( [[ | function p.row( f ) | ||
local args = require( [[Moduł:ProcessArgs]] ).norm() | |||
local getDplVar | local function getDplVar( var ) | ||
local val = f:callParserFunction( '#dplvar', 'breaking ' .. var ) | local val = f:callParserFunction( '#dplvar', 'breaking ' .. var ) | ||
if val == '' then | if val == '' then | ||
| Linia 20: | Linia 22: | ||
end | end | ||
local dplVars = {} | local dplVars = {} | ||
local setDplVar | local function setDplVar( var, val ) | ||
table.insert( dplVars, 'breaking ' .. var ) | table.insert( dplVars, 'breaking ' .. var ) | ||
table.insert( dplVars, val or '1' ) | table.insert( dplVars, val or '1' ) | ||
| Linia 28: | Linia 30: | ||
local tableParts = {} | local tableParts = {} | ||
local categories = {} | local categories = {} | ||
local showOptions = false | |||
local horizontal | local horizontal | ||
if args | if args['horyzontalny'] or args[1]:match( ';' ) then | ||
horizontal = true | horizontal = true | ||
end | end | ||
| Linia 41: | Linia 44: | ||
showTool = false | showTool = false | ||
setDplVar( 'hidetool' ) | setDplVar( 'hidetool' ) | ||
breakingTimeHeader = '[[Breaking]] time (secs)' | |||
end | end | ||
if args.hideshears or horizontal and not args.shears then | if args.hideshears or horizontal and not args.shears then | ||
| Linia 64: | Linia 68: | ||
table.insert( tableClasses, 'sortable' ) | table.insert( tableClasses, 'sortable' ) | ||
end | end | ||
table.insert( rows, ' {| class="' .. table.concat( tableClasses, ' ' ) .. '" style="text-align:center"' ) | table.insert( rows, ' {| class="' .. table.concat( tableClasses, ' ' ) .. '" style="text-align: center; margin: 0;"' ) | ||
local sortType = '' | local sortType = '' | ||
| Linia 75: | Linia 79: | ||
end | end | ||
header = { | header = { | ||
'! ' .. rowspan .. ' | | '! ' .. rowspan .. ' | Blok' | ||
} | } | ||
if not simple then | if not simple then | ||
table.insert( header, '! ' .. rowspan .. sortType .. ' | | table.insert( header, '! ' .. rowspan .. sortType .. ' | Twardość' ) | ||
if showTool then | if showTool then | ||
table.insert( header, '! ' .. rowspan .. ' | | table.insert( header, '! ' .. rowspan .. ' | Narzędzie' ) | ||
end | end | ||
end | end | ||
| Linia 87: | Linia 91: | ||
local toolColumns = {} | local toolColumns = {} | ||
if showTool then | if showTool then | ||
toolColumns = { ' | toolColumns = { 'Drewniany', 'Kamienny', 'Miedzny', 'Żelazny', 'Diamentowy', 'Netherytowy', 'Złoty'} | ||
end | end | ||
table.insert( | table.insert( toolColumns, 1, 'Domyślne' ) | ||
if not simple then | if not simple then | ||
if showShears then | if showShears then | ||
table.insert( toolColumns, ' | table.insert( toolColumns, 'Nożyce' ) | ||
end | end | ||
if showSword then | if showSword then | ||
table.insert( toolColumns, ' | table.insert( toolColumns, 'Miecz' ) | ||
end | end | ||
end | end | ||
| Linia 107: | Linia 109: | ||
end | end | ||
local toolSprites = { | |||
['Drewniany'] = { 'Block', 'dębowe-deski' }, | |||
['Kamienny'] = { 'Block', 'bruk' }, | |||
['Miedzny'] = { 'Item', 'sztabka-miedzi' }, | |||
['Żelazny'] = { 'Item', 'sztabka-żelaza' }, | |||
['Diamentowy'] = { 'Item', 'diament' }, | |||
['Netherytowy'] = { 'Item', 'sztabka-netherytu' }, | |||
['Złoty'] = { 'Item', 'sztabka-złota' }, | |||
['Nożyce'] = { 'Item', 'nożyce' }, | |||
['Miecz'] = { 'Item', 'drewniany-miecz' } | |||
} | |||
for _, tool in ipairs( toolColumns ) do | for _, tool in ipairs( toolColumns ) do | ||
table.insert( header, '! ' .. sortType .. ' | ' .. tool ) | if toolSprites[tool] then | ||
local image = f:expandTemplate({title = toolSprites[tool][1]..'Sprite', args = {['1']=toolSprites[tool][2]}}).. ' ' .. tool | |||
table.insert( header, '! style="text-align:left" ' .. sortType .. ' | ' .. image ) | |||
table.insert( categories, spriteCat ) | |||
else | |||
table.insert( header, '! ' .. sortType .. ' | ' .. tool ) | |||
end | |||
end | end | ||
| Linia 124: | Linia 143: | ||
end | end | ||
local hardness = args['twardość'] | |||
local hardness = | |||
local fillCells | local function fillCells( cellsTable, text, num ) | ||
for i = 1, num do | for i = 1, num do | ||
table.insert( cellsTable, text ) | table.insert( cellsTable, text ) | ||
| Linia 137: | Linia 155: | ||
Golden = 1, | Golden = 1, | ||
Stone = 2, | Stone = 2, | ||
Copper = 2, | |||
Iron = 3, | Iron = 3, | ||
Diamond = 4, | Diamond = 4, | ||
None = 5 | Netherite = 5, | ||
None = 6, | |||
['Drewniany'] = 1, ['Drewno'] = 1, | |||
['Złoty'] = 1, | |||
['Kamienny'] = 2, | |||
['Miedziany'] = 2, | |||
['Żelazny'] = 3, | |||
['Diamentowy'] = 4, | |||
['Netherytowy'] = 5, | |||
['Brak'] = 6 | |||
} | } | ||
local materialSpeed = { | local materialSpeed = { | ||
| Linia 146: | Linia 174: | ||
Wooden = 2, Wood = 2, | Wooden = 2, Wood = 2, | ||
Stone = 4, | Stone = 4, | ||
Copper = 5, | |||
Iron = 6, | Iron = 6, | ||
Diamond = 8, | Diamond = 8, | ||
Golden = 12 | Netherite = 9, | ||
Golden = 12, | |||
['Drewniany'] = 2, ['Drewno'] = 2, | |||
['Złoty'] = 12, | |||
['Kamienny'] = 4, | |||
['Miedziany'] = 5, | |||
['Żelazny'] = 6, | |||
['Diamentowy'] = 8, | |||
['Netherytowy'] = 9, | |||
['Brak'] = 1 | |||
} | } | ||
local | local numberMaterials = 6 | ||
local function insertBlock( blockArgs ) | |||
local cells = {} | local cells = {} | ||
local blocks = mw.text.split( blockArgs[1], '%s*,%s*' ) | local blocks = mw.text.split( blockArgs[1], '%s*,%s*' ) | ||
local hardnessVal = | local hardnessVal = hardness | ||
if not hardnessVal then | if not hardnessVal then | ||
hardnessVal = '?' | hardnessVal = '?' | ||
local title = mw.title.getCurrentTitle() | |||
if title.namespace == 0 and not title.isSubpage then | |||
table.insert(categories, '[[Category:Missing hardness]]') | |||
end | |||
end | end | ||
local unbreakable | local unbreakable | ||
if hardnessVal == -1 or blockArgs.liquid then | if hardnessVal == -1 or blockArgs.liquid then | ||
unbreakable = true | unbreakable = true | ||
elseif hardnessVal ~= 0 then | |||
showOptions = true | |||
end | end | ||
| Linia 184: | Linia 230: | ||
else | else | ||
blockText = block | blockText = block | ||
end | end | ||
local image, | local image = f:expandTemplate({title='BlockLink', args = {['1']=block,text=blockText,link=link,id=id}}) | ||
table.insert( blockSprites, image ) | table.insert( blockSprites, image ) | ||
end | end | ||
table.insert( cells, | table.insert( cells, | ||
'! style="text-align:left" | ' .. table.concat( blockSprites, '<br>' ) .. ( blockArgs.note or '' ) | '!' .. (horizontal and '' or ' style="text-align:left" | ') .. table.concat( blockSprites, '<br>' ) .. ( blockArgs.note or '' ) | ||
) | ) | ||
| Linia 212: | Linia 247: | ||
local hardnessText = hardnessVal | local hardnessText = hardnessVal | ||
if hardnessVal == -1 then | if hardnessVal == -1 then | ||
hardnessText = ( sortable and 'data-sort-value=" | hardnessText = ( sortable and 'data-sort-value="9999" | ' or '' ) .. "-1 (infinite)" | ||
end | end | ||
table.insert( cells, '|' .. hardnessText ) | table.insert( cells, '|' .. hardnessText ) | ||
| Linia 222: | Linia 257: | ||
material = 'Wooden' | material = 'Wooden' | ||
end | end | ||
local | local isMaterialSpecified = (material ~= 'Any') and (material ~= 'None') | ||
local | local toolName = polish:lc(( isMaterialSpecified and material .. '-' or '' ) .. tool) | ||
local toolSpriteName = toolName .. ( (isMaterialSpecified) and '' or ' Required' ) | |||
local image = f:expandTemplate({title=isMaterialSpecified and 'ItemSprite' or 'SlotSprite', args = {['1']=toolSpriteName,title=toolName,link=tool,keepcase = not isMaterialSpecified}}) | |||
toolCell = ( sortable and 'data-sort-value="' .. toolName .. '" |' or '' ) .. image | toolCell = ( sortable and 'data-sort-value="' .. toolName .. '" |' or '' ) .. image | ||
table.insert( categories, spriteCat ) | table.insert( categories, spriteCat ) | ||
| Linia 237: | Linia 270: | ||
local choices = {} | local choices = {} | ||
local getChoice | local function getChoice( choice, text ) | ||
if not choices[choice] then | if not choices[choice] then | ||
choices[choice] = f:expandTemplate{ title = ' | choices[choice] = f:expandTemplate{ title = 'Tc', args = { choice, '' } } | ||
end | end | ||
return choices[choice] .. text | return choices[choice] .. text | ||
end | |||
local function processTime( actualHardness, baseSpeed, tool ) | |||
-- the number passed in has been multiplied by 100 | |||
local num = actualHardness / baseSpeed | |||
if num <= 5 then -- 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' and tool ~= 'Sword') and '+efficiencySpeed' or '') .. ')/hasteMultiplier))/20' | |||
.. '">' .. num .. '</span>' | |||
end | end | ||
if hardnessVal == '?' then | if hardnessVal == '?' then | ||
fillCells( cells, '|?', | fillCells( cells, '|?', numberMaterials + 1 ) | ||
else | else | ||
if unbreakable then | if unbreakable then | ||
table.insert( cells, '| ' .. ( sortable and 'data-sort-value=" | table.insert( cells, '| ' .. ( sortable and 'data-sort-value="9999" ' or '' ) .. getChoice( 'nie', '∞' ) ) | ||
if showTool then | if showTool then | ||
fillCells( cells, '|—', | fillCells( cells, '|—', numberMaterials ) | ||
end | end | ||
else | else | ||
local drop = ' | local drop = 'tak' | ||
local forceDrop = false | |||
if blockArgs.drop == '0' then | if blockArgs.drop == '0' then | ||
drop = ' | drop = 'częściowo' | ||
elseif blockArgs.drop == '1' then | |||
forceDrop = 'tak' | |||
end | end | ||
local requiredLevel = unbreakable and 999 or materialGrade[material] | local requiredLevel = unbreakable and 999 or materialGrade[material] | ||
local insertMaterialCell | local function insertMaterialCell( material ) | ||
local | local shouldDrop = drop | ||
if materialGrade[material] < requiredLevel then | if materialGrade[material] < requiredLevel then | ||
shouldDrop = 'nie' | |||
end | end | ||
local breakTime = processTime( hardnessVal | -- prevent float number precision loss, multiply by 100 and divide it in processTime function | ||
table.insert( cells, '|' .. getChoice( | local breakTime = processTime( hardnessVal * (shouldDrop == 'nie' and 500 or 150), materialSpeed[material], material ) | ||
table.insert( cells, '|' .. getChoice( forceDrop or shouldDrop, breakTime ) ) | |||
end | end | ||
| Linia 279: | Linia 320: | ||
insertMaterialCell( 'Any' ) | insertMaterialCell( 'Any' ) | ||
if showTool then | if showTool then | ||
fillCells( cells, '|—', | fillCells( cells, '|—', numberMaterials ) | ||
end | end | ||
else | else | ||
for _, material in ipairs{ 'Any', 'Wooden', 'Stone', 'Iron', 'Diamond', 'Golden' } do | for _, material in ipairs{ 'Any', 'Wooden', 'Stone', 'Copper', 'Iron', 'Diamond', 'Netherite', 'Golden' } do | ||
insertMaterialCell( material ) | insertMaterialCell( material ) | ||
end | end | ||
end | end | ||
end | end | ||
end | |||
if not simple and ( showShears or showSword ) then | |||
local tools = {} | |||
if showShears then | |||
table.insert( tools, 'Shears' ) | |||
end | |||
if showSword then | |||
table.insert( tools, 'Sword' ) | |||
end | |||
if hardnessVal == '?' then | |||
fillCells( cells, '|?', #tools ) | |||
else | |||
local toolSpeed = { | |||
Shears = 1, | |||
Sword = 1.5 | |||
} | |||
if blocks[1] == 'Wool' then | |||
toolSpeed.Shears = 5 | |||
elseif blocks[1] == 'Leaves' then | |||
toolSpeed.Shears = 15 | |||
elseif blocks[1] == 'Cobweb' then | |||
toolSpeed.Sword = 15 | |||
toolSpeed.Shears = 15 | |||
elseif blocks[1] == 'Bamboo' or blocks[1] == 'Bamboo Shoot' then | |||
toolSpeed.Sword = 5000 | |||
end | end | ||
for _, tool in ipairs( tools ) do | |||
local toolDrop = blockArgs[mw.ustring.lower( tool )] | |||
if not toolDrop then | |||
table.insert( cells, '|—' ) | |||
else | |||
local willDrop = 'tak' | |||
if toolDrop == '0' then | |||
willDrop = 'częściowo' | |||
end | end | ||
-- prevent float number precision loss, multiply by 100 and divide it in processTime function | |||
local breakTime = processTime( hardnessVal * 150, toolSpeed[tool], tool ) | |||
table.insert( cells, '|' .. getChoice( willDrop, breakTime ) ) | |||
end | end | ||
end | end | ||
| Linia 373: | Linia 416: | ||
table.insert( rows, row ) | table.insert( rows, row ) | ||
end | end | ||
table.insert( rows, '' ) | |||
end | end | ||
local note = '' | local note = '' | ||
if args.foot or horizontal then | if args.foot or horizontal then | ||
note = f:preprocess( '<references group=" | note = f:preprocess( '<references group="FN"/>' ) | ||
if args.foot == '2' then | if args.foot == '2' then | ||
| Linia 399: | Linia 442: | ||
end | end | ||
local result = table.concat( rows, '\n|-\n' ) | |||
return result .. note .. table.concat( categories ) | |||
end | end | ||
return p | return p | ||
Wersja z 10:28, 20 lip 2025
W tym module nie ma dokumentacji. Jeśli wiesz jak używać tego modułu, proszę, podaj odpowiednie informacje.
local p = {}
local polish = mw.language.new('pl')
local breakingTimeHeader;
local function getBreakingTimeHeader( f )
if breakingTimeHeader == nil then
breakingTimeHeader = 'Czas wydobycia (sekundy)' .. f:preprocess( '<ref group="FN" name="breakingtimenote">Czasy nie biorą pod uwagę [[Zaklinanie|zaklęć]], [[efekt]]ów i innych czynników, jak np. zanurzenie w wodzie.</ref>' )
end
return breakingTimeHeader
end
function p.row( f )
local args = require( [[Moduł:ProcessArgs]] ).norm()
local function getDplVar( var )
local val = f:callParserFunction( '#dplvar', 'breaking ' .. var )
if val == '' then
val = false
end
return val
end
local dplVars = {}
local function setDplVar( var, val )
table.insert( dplVars, 'breaking ' .. var )
table.insert( dplVars, val or '1' )
end
local rows = {}
local tableParts = {}
local categories = {}
local showOptions = false
local horizontal
if args['horyzontalny'] or args[1]:match( ';' ) then
horizontal = true
end
local showTool = true
local showShears = true
local showSword = true
local header, sortable, simple
if horizontal or not getDplVar( 'header' ) then
if args.hidetool or horizontal and ( not args[2] or args[2]:lower() == 'any' or args[2]:lower() == 'none' ) then
showTool = false
setDplVar( 'hidetool' )
breakingTimeHeader = '[[Breaking]] time (secs)'
end
if args.hideshears or horizontal and not args.shears then
showShears = false
setDplVar( 'hideshears' )
end
if args.hidesword or horizontal and not args.sword then
showSword = false
setDplVar( 'hidesword' )
end
sortable = not horizontal and args.sort
if sortable then
setDplVar( 'sortable' )
end
simple = args.simple
if simple and not horizontal then
setDplVar( 'simple' )
end
local tableClasses = { 'wikitable' }
if sortable then
table.insert( tableClasses, 'sortable' )
end
table.insert( rows, ' {| class="' .. table.concat( tableClasses, ' ' ) .. '" style="text-align: center; margin: 0;"' )
local sortType = ''
if sortable then
sortType = 'data-sort-type="number"'
end
local rowspan = ''
if not horizontal then
rowspan = 'rowspan="2" '
end
header = {
'! ' .. rowspan .. ' | Blok'
}
if not simple then
table.insert( header, '! ' .. rowspan .. sortType .. ' | Twardość' )
if showTool then
table.insert( header, '! ' .. rowspan .. ' | Narzędzie' )
end
end
local toolColumns = {}
if showTool then
toolColumns = { 'Drewniany', 'Kamienny', 'Miedzny', 'Żelazny', 'Diamentowy', 'Netherytowy', 'Złoty'}
end
table.insert( toolColumns, 1, 'Domyślne' )
if not simple then
if showShears then
table.insert( toolColumns, 'Nożyce' )
end
if showSword then
table.insert( toolColumns, 'Miecz' )
end
end
if not horizontal then
table.insert( header, '! colspan="' .. #toolColumns .. '" |' .. getBreakingTimeHeader( f ) )
table.insert( header, '|-' )
end
local toolSprites = {
['Drewniany'] = { 'Block', 'dębowe-deski' },
['Kamienny'] = { 'Block', 'bruk' },
['Miedzny'] = { 'Item', 'sztabka-miedzi' },
['Żelazny'] = { 'Item', 'sztabka-żelaza' },
['Diamentowy'] = { 'Item', 'diament' },
['Netherytowy'] = { 'Item', 'sztabka-netherytu' },
['Złoty'] = { 'Item', 'sztabka-złota' },
['Nożyce'] = { 'Item', 'nożyce' },
['Miecz'] = { 'Item', 'drewniany-miecz' }
}
for _, tool in ipairs( toolColumns ) do
if toolSprites[tool] then
local image = f:expandTemplate({title = toolSprites[tool][1]..'Sprite', args = {['1']=toolSprites[tool][2]}}).. ' ' .. tool
table.insert( header, '! style="text-align:left" ' .. sortType .. ' | ' .. image )
table.insert( categories, spriteCat )
else
table.insert( header, '! ' .. sortType .. ' | ' .. tool )
end
end
if not horizontal then
header = table.concat( header, '\n' )
setDplVar( 'header', header )
end
table.insert( tableParts, header )
else
showTool = not getDplVar( 'hidetool' )
showShears = not getDplVar( 'hideshears' )
showSword = not getDplVar( 'hidesword' )
sortable = getDplVar( 'sortable' )
simple = getDplVar( 'simple' )
end
local hardness = args['twardość']
local function fillCells( cellsTable, text, num )
for i = 1, num do
table.insert( cellsTable, text )
end
end
local materialGrade = {
Any = 0,
Wooden = 1, Wood = 1,
Golden = 1,
Stone = 2,
Copper = 2,
Iron = 3,
Diamond = 4,
Netherite = 5,
None = 6,
['Drewniany'] = 1, ['Drewno'] = 1,
['Złoty'] = 1,
['Kamienny'] = 2,
['Miedziany'] = 2,
['Żelazny'] = 3,
['Diamentowy'] = 4,
['Netherytowy'] = 5,
['Brak'] = 6
}
local materialSpeed = {
None = 1,
Any = 1,
Wooden = 2, Wood = 2,
Stone = 4,
Copper = 5,
Iron = 6,
Diamond = 8,
Netherite = 9,
Golden = 12,
['Drewniany'] = 2, ['Drewno'] = 2,
['Złoty'] = 12,
['Kamienny'] = 4,
['Miedziany'] = 5,
['Żelazny'] = 6,
['Diamentowy'] = 8,
['Netherytowy'] = 9,
['Brak'] = 1
}
local numberMaterials = 6
local function insertBlock( blockArgs )
local cells = {}
local blocks = mw.text.split( blockArgs[1], '%s*,%s*' )
local hardnessVal = hardness
if not hardnessVal then
hardnessVal = '?'
local title = mw.title.getCurrentTitle()
if title.namespace == 0 and not title.isSubpage then
table.insert(categories, '[[Category:Missing hardness]]')
end
end
local unbreakable
if hardnessVal == -1 or blockArgs.liquid then
unbreakable = true
elseif hardnessVal ~= 0 then
showOptions = true
end
local blockSprites = {}
local links = mw.text.split( blockArgs.link or '', '%s*,%s*' )
local ids = mw.text.split( blockArgs.sprite or '', '%s*,%s*' )
local items = mw.text.split( blockArgs.item or '', '%s*,%s*' )
for i, block in ipairs( blocks ) do
local link
if not links[i] and links[1] ~= '' then
link = links[1]
elseif links[i] ~= '' then
link = links[i]
end
local id
if not ids[i] and ids[1] ~= '' then
id = ids[1]
elseif ids[i] ~= '' then
id = ids[i]
end
local blockText
if args.textTrim then
blockText = block:gsub( args.textTrim .. '$', '' )
else
blockText = block
end
local image = f:expandTemplate({title='BlockLink', args = {['1']=block,text=blockText,link=link,id=id}})
table.insert( blockSprites, image )
end
table.insert( cells,
'!' .. (horizontal and '' or ' style="text-align:left" | ') .. table.concat( blockSprites, '<br>' ) .. ( blockArgs.note or '' )
)
local tool = mw.text.trim( simple and 'Tool' or blockArgs[2] or 'Any' ):gsub( '^%l', string.upper )
local material = mw.text.trim( simple and blockArgs[2] or blockArgs[3] or 'Any' ):gsub( '^%l', string.upper )
if tool == 'None' then
material = tool
end
if not simple then
local hardnessText = hardnessVal
if hardnessVal == -1 then
hardnessText = ( sortable and 'data-sort-value="9999" | ' or '' ) .. "-1 (infinite)"
end
table.insert( cells, '|' .. hardnessText )
if showTool then
local toolCell = '—'
if tool ~= 'Any' and tool ~= 'None' then
if material == 'Wood' then
material = 'Wooden'
end
local isMaterialSpecified = (material ~= 'Any') and (material ~= 'None')
local toolName = polish:lc(( isMaterialSpecified and material .. '-' or '' ) .. tool)
local toolSpriteName = toolName .. ( (isMaterialSpecified) and '' or ' Required' )
local image = f:expandTemplate({title=isMaterialSpecified and 'ItemSprite' or 'SlotSprite', args = {['1']=toolSpriteName,title=toolName,link=tool,keepcase = not isMaterialSpecified}})
toolCell = ( sortable and 'data-sort-value="' .. toolName .. '" |' or '' ) .. image
table.insert( categories, spriteCat )
end
table.insert( cells, '|' .. toolCell )
end
end
local choices = {}
local function getChoice( choice, text )
if not choices[choice] then
choices[choice] = f:expandTemplate{ title = 'Tc', args = { choice, '' } }
end
return choices[choice] .. text
end
local function processTime( actualHardness, baseSpeed, tool )
-- the number passed in has been multiplied by 100
local num = actualHardness / baseSpeed
if num <= 5 then -- 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' and tool ~= 'Sword') and '+efficiencySpeed' or '') .. ')/hasteMultiplier))/20'
.. '">' .. num .. '</span>'
end
if hardnessVal == '?' then
fillCells( cells, '|?', numberMaterials + 1 )
else
if unbreakable then
table.insert( cells, '| ' .. ( sortable and 'data-sort-value="9999" ' or '' ) .. getChoice( 'nie', '∞' ) )
if showTool then
fillCells( cells, '|—', numberMaterials )
end
else
local drop = 'tak'
local forceDrop = false
if blockArgs.drop == '0' then
drop = 'częściowo'
elseif blockArgs.drop == '1' then
forceDrop = 'tak'
end
local requiredLevel = unbreakable and 999 or materialGrade[material]
local function insertMaterialCell( material )
local shouldDrop = drop
if materialGrade[material] < requiredLevel then
shouldDrop = 'nie'
end
-- prevent float number precision loss, multiply by 100 and divide it in processTime function
local breakTime = processTime( hardnessVal * (shouldDrop == 'nie' and 500 or 150), materialSpeed[material], material )
table.insert( cells, '|' .. getChoice( forceDrop or shouldDrop, breakTime ) )
end
if not showTool or tool == 'Any' or tool == 'None' then
insertMaterialCell( 'Any' )
if showTool then
fillCells( cells, '|—', numberMaterials )
end
else
for _, material in ipairs{ 'Any', 'Wooden', 'Stone', 'Copper', 'Iron', 'Diamond', 'Netherite', 'Golden' } do
insertMaterialCell( material )
end
end
end
end
if not simple and ( showShears or showSword ) then
local tools = {}
if showShears then
table.insert( tools, 'Shears' )
end
if showSword then
table.insert( tools, 'Sword' )
end
if hardnessVal == '?' then
fillCells( cells, '|?', #tools )
else
local toolSpeed = {
Shears = 1,
Sword = 1.5
}
if blocks[1] == 'Wool' then
toolSpeed.Shears = 5
elseif blocks[1] == 'Leaves' then
toolSpeed.Shears = 15
elseif blocks[1] == 'Cobweb' then
toolSpeed.Sword = 15
toolSpeed.Shears = 15
elseif blocks[1] == 'Bamboo' or blocks[1] == 'Bamboo Shoot' then
toolSpeed.Sword = 5000
end
for _, tool in ipairs( tools ) do
local toolDrop = blockArgs[mw.ustring.lower( tool )]
if not toolDrop then
table.insert( cells, '|—' )
else
local willDrop = 'tak'
if toolDrop == '0' then
willDrop = 'częściowo'
end
-- prevent float number precision loss, multiply by 100 and divide it in processTime function
local breakTime = processTime( hardnessVal * 150, toolSpeed[tool], tool )
table.insert( cells, '|' .. getChoice( willDrop, breakTime ) )
end
end
end
end
if not horizontal then
cells = table.concat( cells, '\n' )
end
table.insert( tableParts, cells )
end
if horizontal then
local blocksArgs = {}
for _, arg in ipairs{ 1, 'note', 'sprite', 'link', 'item', 'drop', 2, 3, 'shears', 'sword' } do
if args[arg] then
local col = 0
for colVal in mw.text.gsplit( args[arg], '%s*;%s*' ) do
col = col + 1
if colVal ~= '' then
if not blocksArgs[col] then
blocksArgs[col] = {}
end
blocksArgs[col][arg] = colVal
end
end
end
end
for _, block in ipairs( blocksArgs ) do
insertBlock( block )
end
local columns = #tableParts
for row = 1, #tableParts[1] do
local cells = {}
for col = 1, columns do
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, simple and 3 or showTool and 5 or 4, '! colspan="' .. columns + 1 .. '" |' .. getBreakingTimeHeader( f ) )
else
insertBlock( args )
for _, row in ipairs( tableParts ) do
table.insert( rows, row )
end
table.insert( rows, '' )
end
local note = ''
if args.foot or horizontal then
note = f:preprocess( '<references group="FN"/>' )
if args.foot == '2' then
table.insert( rows, header or getDplVar( 'header' ) )
end
table.insert( rows, '|}' )
if not horizontal then
f:callParserFunction( '#dplvar:set',
'breaking header', '',
'breaking hidetool', '',
'breaking hideshears', '',
'breaking hidesword', '',
'breaking simple', '',
'breaking sortable', ''
)
end
elseif #dplVars > 0 then
f:callParserFunction( '#dplvar:set', dplVars )
end
local result = table.concat( rows, '\n|-\n' )
return result .. note .. table.concat( categories )
end
return p