Module:Crafting

local p = {} function p.table( f ) local args = f	if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end local grid = require( 'Module:Grid' ) -- Start table when appropriate local multirow = f:callParserFunction( '#dplvar', 'multirow' ) if multirow ~= '1' then multirow = nil end local head = true or args.head or '' if multirow then head = '' elseif head ~= '' then multirow = 1 f:callParserFunction( '#dplvar:set', 'multirow', '1' ) else head = 1 end local header = '' if head ~= '' then local name = '' local description = '' if args.showname == '1' or multirow and args.showname ~= '0' then name = 'Name !! '			f:callParserFunction( '#dplvar:set', 'craftingname', '1' ) end if args.showdescription == '1' then description = ' !! class="unsortable" | Description' f:callParserFunction( '#dplvar:set', 'craftingdescription', '1' ) end local class = args.class or '' local recipeClass = '' if multirow then class = 'sortable collapsible ' .. class recipeClass = 'class="unsortable collapse-button" |' end header = table.concat( {			' {| class="wikitable ' .. class .. '"',			'! ' .. name .. 'Ingredients !! ' .. recipeClass .. ' Crafting recipe' .. description,			'|-'		}, '\n' ) end

-- End table when appropriate local foot = args.foot or '' if multirow then if foot ~= '' then multirow = nil f:callParserFunction( '#dplvar:set', 'multirow', '0' ) end else foot = 1 end -- Name cell local nameCell if args.name or  ~=  then nameCell = args.name elseif multirow or f:callParserFunction( '#dplvar', 'craftingname' ) == '1' then local names = {} local links = {} for v in mw.text.gsplit( args.Output or '', '%s*;%s*' ) do			parts = grid.getParts( v ) if not names[( parts.mod or '' ) .. parts.name] then local link = '' if parts.mod then link = 'Mods/' .. parts.mod .. '/' .. parts.name .. '|'				end if parts.name:find( '^Any ' ) then table.insert( links, 'Any ' .. link .. parts.name:sub( 4 ) .. '' ) else table.insert( links,  .. link .. parts.name ..  ) end names[( parts.mod or '' ) .. parts.name] = 1 end end nameCell = table.concat( links, ' or ' ) end if nameCell and args.upcoming == '1' then nameCell = nameCell .. ' (upcoming)' end -- Create ingredient list local ingredients = {} local ingredientKeys = {} local animatedIngredients = {} local animatedKeys = {} for k, v in pairs( args ) do		v = mw.text.trim( v ) if v ~= '' and tostring( k ):find( '^%u?%d%d?$' ) then if v:find( ';' ) then table.insert( animatedKeys, v ) else local parts = grid.getParts( v ) if not ingredients[parts.name] then table.insert( ingredientKeys, parts.name ) ingredients[parts.name] = { mod = parts.mod } end end end end for k, v in ipairs( animatedKeys ) do		local frames = mw.text.split( v, '%s*;%s*' ) local length = #frames for k2, v2 in ipairs( frames ) do			local parts = grid.getParts( v2 ) if v2 ~= '' and not ingredients[parts.name] and not animatedIngredients[parts.name] then table.insert( ingredientKeys, parts.name ) animatedIngredients[parts.name] = { mod = parts.mod, final = k2 == length } end end end -- Ingredients cell local ingredientsCell if args.ingredients or  ~=  then ingredientsCell = args.ingredients else ingredientsCell = {} for k, v in ipairs( ingredientKeys ) do			local link = '' local separator = ' +' if k == #ingredientKeys then separator = '' elseif animatedIngredients[v] and not animatedIngredients[v].final then separator = ' or' end local mod = ( ingredients[v] or animatedIngredients[v] ).mod if mod then link = 'Mods/'.. mod .. '/' .. v .. '|'			end if v:find( '^Any ' ) then table.insert( ingredientsCell, 'Any ' .. link .. v:sub( 4 ) .. '' .. separator ) else table.insert( ingredientsCell,  .. link .. v ..  .. separator ) end end ingredientsCell = table.concat( ingredientsCell, ' \n' ) end -- Automatic shapeless positioning local newArgs = {} if args[1] then newArgs.shapeless = 1 if args[7] then newArgs.A1 = args[1] newArgs.B1 = args[2] newArgs.C1 = args[3] newArgs.A2 = args[4] newArgs.B2 = args[5] newArgs.C2 = args[6] if args[8] then -- ◼◼◼     ◼◼◼				-- ◼◼◼  OR  ◼◼◼ -- ◼◼◼     ◼◼◻				newArgs.A3 = args[7] newArgs.B3 = args[8] newArgs.C3 = args[9] else -- ◼◼◼				-- ◼◼◼				-- ◻◼◻				newArgs.B3 = args[7] end elseif args[2] then newArgs.A2 = args[1] newArgs.B2 = args[2] if args[5] then -- ◻◻◻     ◻◻◻				-- ◼◼◼  OR  ◼◼◼ -- ◼◼◼     ◼◼◻				newArgs.C2 = args[3] newArgs.A3 = args[4] newArgs.B3 = args[5] newArgs.C3 = args[6] elseif args[4] then -- ◻◻◻				-- ◼◼◻				-- ◼◼◻				newArgs.A3 = args[3] newArgs.B3 = args[4] else -- ◻◻◻     ◻◻◻				-- ◼◼◻  OR  ◼◼◻ -- ◻◼◻     ◻◻◻				newArgs.B3 = args[3] end else -- ◻◻◻			-- ◻◼◻			-- ◻◻◻			newArgs.B2 = args[1] end else newArgs.A1 = args.A1		newArgs.B1 = args.B1		newArgs.C1 = args.C1		newArgs.A2 = args.A2		newArgs.B2 = args.B2		newArgs.C2 = args.C2		newArgs.A3 = args.A3		newArgs.B3 = args.B3		newArgs.C3 = args.C3	end -- Any other args we want to pass along newArgs.Output = args.Output newArgs.Otitle = args.Otitle -- Recipe cell local recipeCell = grid.craftingTable( newArgs ) local row = { ingredientsCell, recipeCell } if nameCell then table.insert( row, 1, nameCell ) end if ( args.description or  ) ~=  and f:callParserFunction( '#dplvar', 'craftingdescription' ) == '1' then table.insert( row, args.description ) end row = table.concat( row, '\n|\n' ) if nameCell then row = '!\n' .. row else row = '|\n' .. row end local footer = '' if foot ~= '' then footer = '|}' f:callParserFunction( '#dplvar:set', 'craftingname', '0', 'craftingdescription', '0' ) end -- Create ingredient categories for DPL local categories = '' if mw.title.getCurrentTitle.namespace == 0 and args.nocat ~= '1' then categories = {} if args.upcoming == '1' then table.insert( '' ) end for k, v in ipairs( ingredientKeys ) do			if v:find( ' Wood$' ) then v = 'Wood' elseif v:find( ' Wood Planks$' ) then v = 'Wood Planks' elseif v:find( ' Stained Glass$' ) then v = 'Stained Glass' elseif v:find( ' Stained Glass Pane$' ) then v = 'Stained Glass Pane' elseif v:find( ' Wool$' ) then v = 'Wool' elseif v:find( '^Block of ' ) then v = 'mineral block' elseif v == 'Sticky Piston' then v = 'Piston' elseif v:find( ' Sandstone$' ) then v = 'Sandstone' elseif v:find( ' Stairs$' ) then v = 'Stairs' elseif v:find( ' Slab$' ) then v = 'Slab' elseif v:find( ' Pressure Plate$' ) then v = 'Pressure Plate' elseif v == 'Red Mushroom' or v == 'Brown Mushroom' then v = 'Mushroom' end table.insert( categories, '' ) end categories = table.concat( categories, '' ) end return header .. '\n' .. row .. '\n|-\n' .. footer .. categories end return p