Module:Multiblock 2

local p = {}

p.multiblock = function(f) local args = f.args or f   if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end local alpha = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'} structure = {} local height = 0 for i, letter in ipairs(alpha) do if args[letter .. "A1"] ~= nil then --Good, another row structure[letter] = {} for i, j in ipairs(alpha) do if args[letter .. j .. 1] ~= nil then structure[letter][j] = {} for i = 1, (tonumber(args.oversize) or 5) do if args[letter .. j .. i] ~= nil then structure[letter][j][i] = args[letter .. j .. i]      					end end end end else if i ~= 1 then height = i-1 break --End of multiblock bits else return "Shorted" --Just give up ;)      		end       	end    end

local size = 0 if tableSize(structure) > 0 then for i, letter in ipairs(alpha) do   		if structure["A"][letter] ~= nil then --Relying on the fact that A is the right size, could also check the whole thing for uniformity local s = tableSize(structure["A"][letter]) if (s > size) then size = s   			end else break end end else mw.log("A useless set of args was sent :|") return "Shorted" end --There's no chance of this going wrong at all. EVERYTHING. local page = " " .. f:expandTemplate{title="Cg", args={nil, ((size-1)*64)+32, (height*((32*size)+4))+15}} .. f:expandTemplate{title="Cg", args={"text", f:expandTemplate{title="L", args={args.page or "Crafting Table", "Multiblock"}}, nil, nil, 0, 0, class="craftingGridText craftingGridLink craftingGridTitle"}} local option = {A={0}} --More creative for i = 1, size-1 do --1 since account for A offset, -1 since we're a letter ahead local n = -i local done = 1 option[alpha[i+1]] = {} while n < size and done < i+2 do			table.insert(option[alpha[i+1]], n)			n = n + 2 done = done + 1 end end local offset = size + 1 for i = offset-2, 1, -1 do		option[alpha[offset]] = option[alpha[i]] offset = offset + 1 end for i, outer in pairs(structure) do		for j, inner in pairs(outer) do			for k, num in pairs(inner) do page = page .. f:expandTemplate{title="Cg", args={"cell", num, 32*((size-1)+option[j][k]), ((tableIndex(alpha, i)-1)*((32*size)+4))+(21+(16*(tableIndex(alpha, j)-1))), class="craftingGridNoBg"}} end end end

return page .. " " end

function tableSize(T) --Stupid Lua even needing this local count = 0 for _ in pairs(T) do 		count = count + 1 end return count end

function tableIndex(T, O) --Stupid Lua needing this as well if "table" == type(T) then for i = 1, #T do			if O == T[i] then return i			end end return -1 else error("tableIndex expects table for first argument, " .. type(T) .. " given") end end

return p