Minecraft Wiki

Das Minecraft-Wiki wird von Microsoft nicht mehr als offiziell angesehen, weshalb einige Änderungen vorgenommen werden müssen, unter anderem am Logo des Wikis. Bitte lese diese Ankündigung für mehr Informationen.

MEHR ERFAHREN

Minecraft Wiki
Advertisement
[Erstellen | Versionen | Aktualisieren]Buch und Feder.png DokumentationLua logo.svg Zum Gebrauch von Lua-Modulen siehe die Modul-Hilfe.
Dieses Modul hat keine Dokumentation. Wenn du weißt, wie es funktioniert, dann erstelle sie bitte.
local p = {}

local breakingTimeHeader;
local function getBreakingTimeHeader( f )
    if breakingTimeHeader == nil then
        breakingTimeHeader = '[[Abbauen|Abbauzeit]]' .. f:preprocess( '<ref group="note" name="breakingtimenote">Zeiten sind für nicht verzauberte Werkzeuge, gemessen in Sekunden. <br>Für mehr Informationen, siehe [[Abbauen#Abbauzeit|Abbau § Geschwindigkeit]].</ref>' )
    end
    return breakingTimeHeader
end

function p.row( f )
	local args = require( [[Modul:ParameterUmwandeln]] ).norm()
	local sprite = require( [[Modul: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 horizontal
	if args.horizontal 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() == 'jedes' or args[2]:lower() == 'kein' ) then
			showTool = false
			setDplVar( 'hidetool' )
    		breakingTimeHeader = '[[Abbauen|Abbauzeit]]'
		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"' )
		
		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 .. ' | Härte' )
			if showTool then
				table.insert( header, '! ' .. rowspan .. ' | Werkzeug' )
			end
		end
		
		local toolColumns = {}
		if showTool then
			toolColumns = { 'Holz', 'Stein', 'Eisen', 'Diamant', 'Netherit', 'Gold'}
		end
		table.insert( toolColumns, 1, 'Standard' )
		
		if not simple then
			if showShears then
				table.insert( toolColumns, 'Schere' )
			end
			if showSword then
				table.insert( toolColumns, 'Schwert' )
			end
		end
		
		if not horizontal then
			table.insert( header, '! colspan="' .. #toolColumns .. '" |' .. getBreakingTimeHeader( f ) )
			table.insert( header, '|-' )
		end
		
		local toolSprites = {
			Holz = { 'BlockSprite', 'Eichenholzbretter' },
			Stein = { 'BlockSprite', 'Bruchstein' },
			Eisen = { 'GegenstandSprite', 'Eisenbarren' },
			Diamant = { 'GegenstandSprite', 'Diamant' },
			Netherit = { 'GegenstandSprite', 'Netheritbarren' },
			Gold = { 'GegenstandSprite', 'Goldbarren' },
			Schere = { 'GegenstandSprite', 'Schere' },
			Schwert = { 'GegenstandSprite', 'Holzschwert' }
		}
		for _, tool in ipairs( toolColumns ) do
			if toolSprites[tool] then
				local image, spriteCat = sprite.sprite{
					data = toolSprites[tool][1],
					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 = require( [[Modul:Blockwerte]] ).value
	
	local function fillCells( cellsTable, text, num )
		for i = 1, num do
			table.insert( cellsTable, text )
		end
	end
	local materialGrade = {
		Jedes = 0,
		Holz = 1,
		Gold = 1,
		Stein = 2,
		Eisen = 3,
		Diamant = 4,
        Netherit = 5,
		Kein = 6
	}
	local materialSpeed = {
		Kein = 1,
		Jedes = 1,
		Holz = 2,
		Stein = 4,
		Eisen = 6,
		Diamant = 8,
        Netherit = 9,
		Gold = 12
	}
	local numberMaterials = 6
	
	local function insertBlock( blockArgs )
		local cells = {}
		local blocks = mw.text.split( blockArgs[1], '%s*,%s*' )
		local hardnessVal = tonumber( hardness{ blocks[1], type = 'härte' } )
		if not hardnessVal then
			hardnessVal = '?'
			local title = mw.title.getCurrentTitle()
			if title.namespace == 0 and not title.isSubpage then
				table.insert(categories, '[[Kategorie:Fehlende Härte]]')
			end
		end
		local unbreakable
		if hardnessVal == -1 or blockArgs.liquid then
			unbreakable = 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 = {
				data = 'BlockSprite',
				block,
				text = blockText,
				link = link,
				id = id
			}
			if items[i] == '1' or not items[i] and items[1] == '1' then
				blockSpriteArgs.data = 'GegenstandSprite'
			end
			
			local image, spriteCat = sprite.link( blockSpriteArgs )
			table.insert( blockSprites, image )
			table.insert( categories, spriteCat )
		end
		table.insert( cells,
			'! style="text-align:left" | ' .. table.concat( blockSprites, '<br>' ) .. ( blockArgs.note or '' )
		)
		
		local tool = mw.text.trim( simple and 'Tool' or blockArgs[2] or 'Jedes' ):gsub( '^%l', string.upper )
		local material = mw.text.trim( simple and blockArgs[2] or blockArgs[3] or 'Jedes' ):gsub( '^%l', string.upper )
		if tool == 'Kein' then
			material = tool
		end
		if not simple then
			local hardnessText = hardnessVal
			if hardnessVal == -1 then
				hardnessText = ( sortable and 'data-sort-value="999" | ' or '' ) .. '∞'
			end
			table.insert( cells, '|' .. hardnessText )
			
			if showTool then
				local toolCell = '—'
				if tool ~= 'Jedes' and tool ~= 'Kein' then
					if not material then
						material = ''
					end
					local isMaterialSpecified = (material ~= 'Jedes') and (material ~= 'Kein')
					local toolName = isMaterialSpecified and material .. tool:lower() or tool 
					local fullToolName = (not isMaterialSpecified and 'Holz' .. toolName:lower()) or toolName
					local image, spriteCat = sprite.sprite{
						data = 'GegenstandSprite',
						fullToolName,
						title = toolName,
						link = tool
					}
					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 = 'Tabellenauswahl', args = { choice, '' } }
			end
			return choices[choice] .. text
		end
		
		local function processTime( num )
			-- the number passed in has been multiplied by 100
			if num <= 5 then		-- Blocks have a minimum breaking time of 1 game tick (0.05 seconds)
				num = 0.05
			else					-- And they must be broken in multiples of 1 game tick (0.05 seconds)
				num = math.ceil( num / 5 ) / 20
			end
			return num
		end
		
		if hardnessVal == '?' then
			fillCells( cells, '|?', numberMaterials + 1 )
		else
			if unbreakable then
				table.insert( cells, '| ' .. ( sortable and 'data-sort-value="999" ' or '' ) .. getChoice( 'nein', '∞' ) )
				if showTool then
					fillCells( cells, '|—', numberMaterials )
				end
			else
				local drop = 'ja'
				local forceDrop = false
				if blockArgs.drop == 'behutsam' then
					drop = 'teilweise'
				elseif blockArgs.drop == '1' then
					forceDrop = 'ja'
				end
				local requiredLevel = unbreakable and 999 or materialGrade[material]
				local function insertMaterialCell( material )
					local shouldDrop = drop
					if materialGrade[material] < requiredLevel then
						shouldDrop = 'nein'
					end
					-- prevent float number precision loss, multiply by 100 and divide it in processTime function
					local breakTime = processTime( hardnessVal * (shouldDrop == 'nein' and 500 or 150) / materialSpeed[material] )
					table.insert( cells, '|' .. getChoice( forceDrop or shouldDrop, breakTime ) )
				end
				
				if not showTool or tool == 'Jedes' or tool == 'Kein' then
					insertMaterialCell( 'Jedes' )
					if showTool then
						fillCells( cells, '|—', numberMaterials )
					end
				else
					for _, material in ipairs{ 'Jedes', 'Holz', 'Stein', 'Eisen', 'Diamant', 'Netherit', 'Gold' } 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] == 'Wolle' then
					toolSpeed.Shears = 5
				elseif blocks[1] == 'Laub' then
					toolSpeed.Shears = 15
				elseif blocks[1] == 'Spinnennetz' then
					toolSpeed.Sword = 15
					toolSpeed.Shears = 15
				elseif blocks[1] =='Bambus' 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 = 'ja'
						if toolDrop == 'behutsam' then
							willDrop = 'teilweise'
						end
						-- prevent float number precision loss, multiply by 100 and divide it in processTime function
						local breakTime = processTime( hardnessVal * 150 / toolSpeed[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
	end
	table.insert( rows, '' )
	
	local note = ''
	if args.foot or horizontal then
		note = f:preprocess( '<references group="note"/>' )
		
		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
	
	return table.concat( rows, '\n|-\n' ) .. note .. table.concat( categories )
end
return p
Advertisement