Moduł:MetroKopUA test: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
| [wersja nieprzejrzana] | [wersja nieprzejrzana] |
MetroKopUA (dyskusja | edycje) Utworzono nową stronę "local p = {} local formatnum = require( Модуль:Formatnum ) local ukrainian = mw.language.new('uk') local breakingTimeHeader; local function getBreakingTimeHeader( f ) if breakingTimeHeader == nil then breakingTimeHeader = 'Час руйнування (в секундах)' .. f:preprocess( '<ref group="note" name="breakingtimenote">Час не враховує інші фактори впливу (наприклад, «Утома») і вим…" |
MetroKopUA (dyskusja | edycje) Nie podano opisu zmian |
||
| Linia 1: | Linia 1: | ||
local p = {} | local p = {} | ||
local breakingTimeHeader; | local breakingTimeHeader; | ||
local function getBreakingTimeHeader( f ) | local function getBreakingTimeHeader( f ) | ||
if breakingTimeHeader == nil then | if breakingTimeHeader == nil then | ||
breakingTimeHeader = ' | breakingTimeHeader = '[[Breaking]] time (sec)' .. f:preprocess( '<ref group="FN" name="breakingtimenote">These durations ignore other influential factors (e.g. [[Mining Fatigue]]), and are measured in seconds. For more information, see [[Breaking#Speed|Breaking § Speed]].</ref>' ) | ||
end | end | ||
return breakingTimeHeader | return breakingTimeHeader | ||
end | end | ||
p.row | function p.row( f ) | ||
local args = require( [[ | local args = require( [[Module:ProcessArgs]] ).norm() | ||
local sprite = require( [[ | local sprite = require( [[Module:Sprite]] ) | ||
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 153: | 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 164: | Linia 33: | ||
local horizontal | local horizontal | ||
if args[ | if args['horizontalny'] or args[1]:match( ';' ) then | ||
horizontal = true | horizontal = true | ||
end | end | ||
| Linia 172: | Linia 41: | ||
local header, sortable, simple | local header, sortable, simple | ||
if horizontal or not getDplVar( 'header' ) then | if horizontal or not getDplVar( 'header' ) then | ||
if args | if args.hidetool or horizontal and ( not args[2] or args[2]:lower() == 'any' or args[2]:lower() == 'none' ) then | ||
showTool = false | showTool = false | ||
setDplVar( 'hidetool' ) | setDplVar( 'hidetool' ) | ||
breakingTimeHeader = '[[Breaking]] time (secs)' | |||
end | end | ||
if args | if args.hideshears or horizontal and not args.shears then | ||
showShears = false | showShears = false | ||
setDplVar( 'hideshears' ) | setDplVar( 'hideshears' ) | ||
end | end | ||
if args | if args.hidesword or horizontal and not args.sword then | ||
showSword = false | showSword = false | ||
setDplVar( 'hidesword' ) | setDplVar( 'hidesword' ) | ||
end | end | ||
sortable = not horizontal and args | sortable = not horizontal and args.sort | ||
if sortable then | if sortable then | ||
setDplVar( 'sortable' ) | setDplVar( 'sortable' ) | ||
| Linia 210: | Linia 79: | ||
end | end | ||
header = { | header = { | ||
'! ' .. rowspan .. ' | | '! ' .. rowspan .. ' | Block' | ||
} | } | ||
if not simple then | if not simple then | ||
table.insert( header, '! ' .. rowspan .. sortType .. ' | | table.insert( header, '! ' .. rowspan .. sortType .. ' | Hardness' ) | ||
if showTool then | if showTool then | ||
table.insert( header, '! ' .. rowspan .. ' | | table.insert( header, '! ' .. rowspan .. ' | Tool' ) | ||
end | end | ||
end | end | ||
| Linia 222: | Linia 91: | ||
local toolColumns = {} | local toolColumns = {} | ||
if showTool then | if showTool then | ||
toolColumns = { 'Wooden', 'Stone', 'Copper', 'Iron', 'Diamond', 'Netherite', 'Golden'} | |||
end | end | ||
table.insert( toolColumns, 1, ' | table.insert( toolColumns, 1, 'Default' ) | ||
if not simple then | if not simple then | ||
if showShears then | if showShears then | ||
table.insert( toolColumns, ' | table.insert( toolColumns, 'Shears' ) | ||
end | end | ||
if showSword then | if showSword then | ||
table.insert( toolColumns, ' | table.insert( toolColumns, 'Sword' ) | ||
end | end | ||
end | end | ||
| Linia 249: | Linia 110: | ||
local toolSprites = { | local toolSprites = { | ||
Wooden = { 'oak-planks' }, | |||
Stone = { 'cobblestone' }, | |||
Copper = { 'copper-ingot' }, | |||
Iron = { 'iron-ingot' }, | |||
Diamond = { 'diamond' }, | |||
Netherite = { 'netherite-ingot' }, | |||
Golden = { 'gold-ingot' }, | |||
Shears = { 'shears' }, | |||
Sword = { 'wooden-sword' } | |||
} | } | ||
for _, tool in ipairs( toolColumns ) do | for _, tool in ipairs( toolColumns ) do | ||
if toolSprites[tool] then | if toolSprites[tool] then | ||
local image, spriteCat = sprite.sprite{ | local image, spriteCat = sprite.sprite{ | ||
name = | name = '', | ||
toolSprites[tool][2], | toolSprites[tool][2], | ||
text = tool | text = tool | ||
| Linia 300: | Linia 147: | ||
end | end | ||
local hardness = | local hardness = args['twardość'] | ||
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 317: | Linia 164: | ||
Netherite = 5, | Netherite = 5, | ||
None = 6, | 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 335: | Linia 181: | ||
Iron = 6, | Iron = 6, | ||
Diamond = 8, | Diamond = 8, | ||
Netherite = 9, | |||
Golden = 12, | 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 numberMaterials = 6 | ||
local insertBlock | 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 | 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 | ||
| Linia 388: | Linia 236: | ||
end | end | ||
local blockSpriteArgs = { | local blockSpriteArgs = { | ||
name = ' | name = '', | ||
block, | block, | ||
text = blockText, | text = blockText, | ||
| Linia 395: | Linia 243: | ||
} | } | ||
if items[i] == '1' or not items[i] and items[1] == '1' then | if items[i] == '1' or not items[i] and items[1] == '1' then | ||
blockSpriteArgs.data = ' | blockSpriteArgs.data = 'ItemSprite' | ||
end | end | ||
| Linia 406: | Linia 254: | ||
) | ) | ||
local tool = mw.text.trim( simple and ' | 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 ' | local material = mw.text.trim( simple and blockArgs[2] or blockArgs[3] or 'Any' ):gsub( '^%l', string.upper ) | ||
if tool == ' | if tool == 'None' then | ||
material = tool | material = tool | ||
end | end | ||
if not simple then | if not simple then | ||
local hardnessText = | local hardnessText = hardnessVal | ||
if hardnessVal == -1 then | if hardnessVal == -1 then | ||
hardnessText = ( sortable and 'data-sort-value="9999" | ' or '' ) .. "-1 ( | hardnessText = ( sortable and 'data-sort-value="9999" | ' or '' ) .. "-1 (infinite)" | ||
end | end | ||
table.insert( cells, '|' .. hardnessText ) | table.insert( cells, '|' .. hardnessText ) | ||
| Linia 420: | Linia 268: | ||
if showTool then | if showTool then | ||
local toolCell = '—' | local toolCell = '—' | ||
if tool ~= ' | if tool ~= 'Any' and tool ~= 'None' then | ||
if material == 'Wood' then | |||
material = 'Wooden' | |||
end | |||
local isMaterialSpecified = (material ~= 'Any') and (material ~= 'None') | |||
local toolName = ( isMaterialSpecified and material .. ' ' or '' ) .. tool | local toolName = ( isMaterialSpecified and material .. ' ' or '' ) .. tool | ||
local | local toolSpriteName = toolName .. ( (isMaterialSpecified) and '' or ' Required' ) | ||
local image, spriteCat = sprite.sprite{ | local image, spriteCat = sprite.sprite{ | ||
name = | name = '', | ||
toolSpriteName, | |||
title = toolName, | title = toolName, | ||
link = tool, | link = tool, | ||
keepcase = not isMaterialSpecified -- SlotSprite has case sensitive names | |||
} | } | ||
toolCell = ( sortable and 'data-sort-value="' .. toolName .. '" |' or '' ) .. image | toolCell = ( sortable and 'data-sort-value="' .. toolName .. '" |' or '' ) .. image | ||
| Linia 461: | Linia 292: | ||
local function getChoice( choice, text ) | 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/opis', args = { choice, '' } } | ||
end | end | ||
return choices[choice] .. text | return choices[choice] .. text | ||
end | end | ||
local function processTime( actualHardness, baseSpeed ) | local function processTime( actualHardness, baseSpeed, tool ) | ||
-- the number passed in has been multiplied by 100 | -- the number passed in has been multiplied by 100 | ||
local num = actualHardness / baseSpeed | local num = actualHardness / baseSpeed | ||
if num <= 5 then | 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 | 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 | else -- And they must be broken in multiples of 1 game tick | ||
num = math.ceil( num / 5 ) / 20 | num = math.ceil( num / 5 ) / 20 | ||
end | end | ||
return '<span class="calculator-field breakingrow-breakingtime-value" data-calculator-type="plain" data-calculator-formula="' | return '<span class="calculator-field breakingrow-breakingtime-value" data-calculator-type="plain" data-calculator-formula="' | ||
.. 'max(1,ceil(' .. (actualHardness / 5) .. '/(' .. baseSpeed .. ( | .. 'max(1,ceil(' .. (actualHardness / 5) .. '/(' .. baseSpeed .. ((tool ~= 'Any' and tool ~= 'Sword') and '+efficiencySpeed' or '') .. ')/hasteMultiplier))/20' | ||
.. '">' .. num .. '</span>' | .. '">' .. 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="9999" ' or '' ) .. getChoice( ' | table.insert( cells, '| ' .. ( sortable and 'data-sort-value="9999" ' or '' ) .. getChoice( 'no', '∞' ) ) | ||
if showTool then | if showTool then | ||
fillCells( cells, '|—', | fillCells( cells, '|—', numberMaterials ) | ||
end | end | ||
else | else | ||
local drop = ' | local drop = 'yes' | ||
if blockArgs | local forceDrop = false | ||
drop = ' | if blockArgs.drop == '0' then | ||
elseif blockArgs | drop = 'partial' | ||
forceDrop = ' | elseif blockArgs.drop == '1' then | ||
forceDrop = 'yes' | |||
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 shouldDrop = drop | local shouldDrop = drop | ||
if materialGrade[material] < requiredLevel then | if materialGrade[material] < requiredLevel then | ||
shouldDrop = ' | shouldDrop = 'no' | ||
end | end | ||
local breakTime = processTime( hardnessVal * (shouldDrop == ' | -- prevent float number precision loss, multiply by 100 and divide it in processTime function | ||
table.insert( cells, '|' .. getChoice( forceDrop or shouldDrop, | local breakTime = processTime( hardnessVal * (shouldDrop == 'no' and 500 or 150), materialSpeed[material], material ) | ||
table.insert( cells, '|' .. getChoice( forceDrop or shouldDrop, breakTime ) ) | |||
end | end | ||
if not showTool or tool == ' | if not showTool or tool == 'Any' or tool == 'None' then | ||
insertMaterialCell( ' | insertMaterialCell( 'Any' ) | ||
if showTool then | if showTool then | ||
fillCells( cells, '|—', | fillCells( cells, '|—', numberMaterials ) | ||
end | end | ||
else | else | ||
| Linia 516: | Linia 348: | ||
end | end | ||
end | end | ||
end | |||
if not simple and ( showShears or showSword ) then | |||
if | 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 = 'yes' | |||
if toolDrop == '0' then | |||
willDrop = 'partial' | |||
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 567: | Linia 401: | ||
if horizontal then | if horizontal then | ||
local blocksArgs = {} | local blocksArgs = {} | ||
for _, arg in ipairs{ 1, 'note', 'sprite', 'link', 'item', ' | for _, arg in ipairs{ 1, 'note', 'sprite', 'link', 'item', 'drop', 2, 3, 'shears', 'sword' } do | ||
if args[arg] then | if args[arg] then | ||
local col = 0 | local col = 0 | ||
| Linia 597: | Linia 431: | ||
-- Insert breaking time header after block row when simple, or after tool or hardness row when not | -- 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 ) ) | table.insert( rows, simple and 3 or showTool and 5 or 4, '! colspan="' .. columns + 1 .. '" |' .. getBreakingTimeHeader( f ) ) | ||
else | else | ||
insertBlock( args ) | insertBlock( args ) | ||
| Linia 611: | Linia 441: | ||
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 634: | Linia 464: | ||
local result = table.concat( rows, '\n|-\n' ) | local result = table.concat( rows, '\n|-\n' ) | ||
if horizontal then | if horizontal then | ||
local styles = require( [[ | local styles = require( [[Module:TSLoader]] ).call( 'Template:Breaking row/styles.css' ) .. '\n' | ||
return styles .. | return styles .. | ||
'<div style="--calculator-hasteLevel: 0;" class="calculator-container breakingrow-container">' .. | '<div style="--calculator-hasteLevel: 0;" class="calculator-container breakingrow-container">' .. | ||
'<div>\n' .. result .. '\n</div>' .. | '<div>\n' .. result .. '\n</div>' .. | ||
'<div>' .. | '<div>' .. | ||
"''' | "'''Legend'''" .. | ||
'\n*' .. f:expandTemplate{ title = ' | '\n*' .. f:expandTemplate{ title = 'legend', args = {'', class = 'tc-no', 'incorrect tool, drops nothing'}} .. | ||
'\n*' .. f:expandTemplate{ title = ' | '\n*' .. f:expandTemplate{ title = 'legend', args = {'', class = 'tc-partial', 'correct tool, drops nothing or something other than the block itself'}} .. | ||
'\n*' .. f:expandTemplate{ title = ' | '\n*' .. f:expandTemplate{ title = 'legend', args = {'', class = 'tc-yes', 'correct tool, drops the block itself'}} .. | ||
"\n* '' | "\n* ''italicized'' can be [[Instant mining|instant mined]]" .. | ||
'\n' .. | '\n' .. | ||
'</div>' .. | '</div>' .. | ||
'</div>' .. | '</div>' .. | ||
note .. table.concat( categories ) | note .. table.concat( categories ) | ||
end | end | ||
Wersja z 23:27, 19 lip 2025
W tym module nie ma dokumentacji. Jeśli wiesz jak używać tego modułu, proszę, podaj odpowiednie informacje.
local p = {}
local breakingTimeHeader;
local function getBreakingTimeHeader( f )
if breakingTimeHeader == nil then
breakingTimeHeader = '[[Breaking]] time (sec)' .. f:preprocess( '<ref group="FN" name="breakingtimenote">These durations ignore other influential factors (e.g. [[Mining Fatigue]]), and are measured in seconds. For more information, see [[Breaking#Speed|Breaking § Speed]].</ref>' )
end
return breakingTimeHeader
end
function p.row( f )
local args = require( [[Module:ProcessArgs]] ).norm()
local sprite = require( [[Module:Sprite]] )
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['horizontalny'] 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 .. ' | Block'
}
if not simple then
table.insert( header, '! ' .. rowspan .. sortType .. ' | Hardness' )
if showTool then
table.insert( header, '! ' .. rowspan .. ' | Tool' )
end
end
local toolColumns = {}
if showTool then
toolColumns = { 'Wooden', 'Stone', 'Copper', 'Iron', 'Diamond', 'Netherite', 'Golden'}
end
table.insert( toolColumns, 1, 'Default' )
if not simple then
if showShears then
table.insert( toolColumns, 'Shears' )
end
if showSword then
table.insert( toolColumns, 'Sword' )
end
end
if not horizontal then
table.insert( header, '! colspan="' .. #toolColumns .. '" |' .. getBreakingTimeHeader( f ) )
table.insert( header, '|-' )
end
local toolSprites = {
Wooden = { 'oak-planks' },
Stone = { 'cobblestone' },
Copper = { 'copper-ingot' },
Iron = { 'iron-ingot' },
Diamond = { 'diamond' },
Netherite = { 'netherite-ingot' },
Golden = { 'gold-ingot' },
Shears = { 'shears' },
Sword = { 'wooden-sword' }
}
for _, tool in ipairs( toolColumns ) do
if toolSprites[tool] then
local image, spriteCat = sprite.sprite{
name = '',
toolSprites[tool][2],
text = 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 blockSpriteArgs = {
name = '',
block,
text = blockText,
link = link,
id = id
}
if items[i] == '1' or not items[i] and items[1] == '1' then
blockSpriteArgs.data = 'ItemSprite'
end
local image, spriteCat = sprite.link( blockSpriteArgs )
table.insert( blockSprites, image )
table.insert( categories, spriteCat )
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 = ( isMaterialSpecified and material .. ' ' or '' ) .. tool
local toolSpriteName = toolName .. ( (isMaterialSpecified) and '' or ' Required' )
local image, spriteCat = sprite.sprite{
name = '',
toolSpriteName,
title = toolName,
link = tool,
keepcase = not isMaterialSpecified -- SlotSprite has case sensitive names
}
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/opis', 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( 'no', '∞' ) )
if showTool then
fillCells( cells, '|—', numberMaterials )
end
else
local drop = 'yes'
local forceDrop = false
if blockArgs.drop == '0' then
drop = 'partial'
elseif blockArgs.drop == '1' then
forceDrop = 'yes'
end
local requiredLevel = unbreakable and 999 or materialGrade[material]
local function insertMaterialCell( material )
local shouldDrop = drop
if materialGrade[material] < requiredLevel then
shouldDrop = 'no'
end
-- prevent float number precision loss, multiply by 100 and divide it in processTime function
local breakTime = processTime( hardnessVal * (shouldDrop == 'no' 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 = 'yes'
if toolDrop == '0' then
willDrop = 'partial'
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' )
if horizontal then
local styles = require( [[Module:TSLoader]] ).call( 'Template:Breaking row/styles.css' ) .. '\n'
return styles ..
'<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
return result .. note .. table.concat( categories )
end
return p