Module:UI

-- -- Taken from: https://minecraft.gamepedia.com/Module:UI local multiRequire = require('Module:MultiRequire') local getArgs = require('Module:Arguments').getArgs local slot = require( Module:Inventory slot ).slot local tooltips = mw.loadData('Module:Inventory slot/Aliases') local parseFrameText = require( Module:Inventory slot ).parseFrameText local rarityAliases = require('Module:RarityTier/Aliases') local table, string, lu, uiText = multiRequire('Module:Table', 'Module:String', 'Module:LibraryUtil', 'Module:UIText') local uiText = uiText._main

local addSlot = function( args, item, prefix, class, default ) local none, nostacksize prefix = prefix or '' if #prefix == 0 then none = 'none' nostacksize = ((item ==  or nil) and ) or (args and args[item] and args[item]:gsub( '[,%d]',  ) or ) end return slot{ nostacksize or args[item], mod = args.Mod, link = none or args[prefix .. 'link'], title = none or args[prefix .. 'title'], class = class, default = default, parsed = args.parsed, forcenum = args.forcenum } end

local p = {}

-- Crafting table function p.craftingTable( f ) local args = f	if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Crafting_Table pixel-image' ) -- CUSTOM: changing grid to use since wikia mobile doesn't support CSS local input = body:tag( 'table' ):addClass( 'mcui-input' ) for num = 1, 3 do		local row = input:tag( 'tr' ):addClass( 'mcui-row' ) for _, letter in ipairs{ 'A', 'B', 'C' } do		   local td = row:tag( 'td' ) td:wikitext( addSlot( args, letter .. num, 'I' ) ) end end local arrow = body:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' ):done if args.arrow or  ~=  then arrow:css(			'background-image',			''		) end body :tag( 'span' ) :addClass( 'mcui-output' ) :wikitext( addSlot( args, 'Output', 'O', 'invslot-large' ) ) local shapeless = args.shapeless or '' local fixed = args.fixed or '' if shapeless ~=  or fixed ~=  then local icon = body:tag( 'span' ) :addClass( 'mcui-icons' ) :tag( 'span' ) :tag( 'br' ) :done if shapeless ~= '' then icon:addClass( 'mcui-shapeless' ) :attr( 'title',					'This recipe is shapeless, the inputs may be placed in any arrangement in the crafting grid.'				) elseif fixed ~= '' then local notFixed = args.notfixed or '' local exceptFixed = '' if notFixed ~= '' then exceptFixed = '; except for ' .. notFixed .. ', which can go anywhere' end icon:addClass( 'mcui-fixed' ) :attr( 'title',					'This recipe is fixed, the input arrangement may not be moved or mirrored in the crafting grid' .. exceptFixed .. '.'				) end end return tostring( mw.html.create( 'div' ):node( body ) ) end

-- Furnace function p.furnace( f ) local args = f	if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Furnace pixel-image' ) local input = body:tag( 'span' ):addClass( 'mcui-input' ) input:wikitext( addSlot( args, 'Input', 'I' ) ) local fuel = input:tag( 'span' ):addClass( 'mcui-fuel' ):tag( 'br' ):done local fuelImg = args.FuelUsage or '' local burning = args.Input or  ~=  and args.Fuel or  ~=  if not burning then fuel:addClass( 'mcui-inactive' ) if fuelImg ~= '' then fuelImg = fuelImg .. ' (in-active)' end end if fuelImg ~= '' then fuel:css(			'background-image',			''		) end input:wikitext( addSlot( args, 'Fuel', 'F' ) ) local arrow = body:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' ):done local arrowImg = args.Progress or '' if not burning or ( args.Output or  ) ==  then arrow:addClass( 'mcui-inactive' ) if arrowImg ~= '' then arrowImg = arrowImg .. ' (in-active)' end end if arrowImg ~= '' then arrow:css(			'background-image',			''		) end body :tag( 'span' ) :addClass( 'mcui-output' ) :wikitext( addSlot( args, 'Output', 'O', 'invslot-large' ) ) return tostring( mw.html.create( 'div' ):node( body ) ) end

-- Brewing Stand function p.brewingStand( f ) local args = f	if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Brewing_Stand pixel-image' ) local input = body:tag( 'span' ):addClass( 'mcui-input' ) input:tag( 'span' ):addClass( 'mcui-bubbling' ):tag( 'br' ) input:wikitext( addSlot( args, 'Input', 'I' ) ) input:tag( 'span' ):addClass( 'mcui-arrow' ):tag( 'br' ) if ( args.Input or  ) ==  or		( ( args.Output1 or  ) ==  and ( args.Output2 or  ) ==  and ( args.Output3 or  ) ==  ) then input:addClass( 'mcui-inactive' ) end body:tag( 'span' ):addClass( 'mcui-paths' ):tag( 'br' ) local output = body:tag( 'span' ):addClass( 'mcui-output' ) for i = 1, 3 do output:wikitext( addSlot( args, 'Output' .. i, 'O' .. i, 'mcui-output' .. i ) ) end return tostring( mw.html.create( 'div' ):node( body ) ) end

-- Stonecutter function p.stonecutter( f ) local args = f	if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Stonecutter pixel-image' ) local input = body:tag( 'span' ):addClass( 'mcui-input' ) input:wikitext( addSlot( args, 'Input', 'I' ) ) local arrow = body:tag( 'span' ):addClass( 'mcui-stonecutterArrow' ) if (args.arrow or ) ~=  then arrow:css(			'background-image',			''		) end arrow:wikitext( addSlot( args, 'Output', '', 'invslot-plain mcui-stonecutterSprite' ) ) body :tag( 'span' ) :addClass( 'mcui-output' ) :wikitext( addSlot( args, 'Output', 'O', 'invslot-large' ) ) return tostring( mw.html.create( 'div' ):node( body ) ) end

-- Loom function p.loom( f ) local args = f	if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Loom pixel-image' ) local tapestry = body:tag( 'span' ):addClass( 'mcui-tapestry' ) if args.Banner and #args.Banner>0 then tapestry:wikitext( addSlot( args, 'Banner', 'B', 'mcui-inputBanner' ) ) end if args.Dye and #args.Dye>0 then tapestry:wikitext( addSlot( args, 'Dye', 'D', 'mcui-inputDye' ) ) end if args.Pattern and #args.Pattern>0 then tapestry:wikitext( addSlot( args, 'Pattern', 'P', 'mcui-inputPattern' ) ) end tapestry:tag( 'span' ):tag( 'br' ):done local arrow = body:tag( 'span' ):addClass( 'mcui-loomArrow' ) if args.arrow or  ~=  then arrow:css(			'background-image',			''		) end local sprite = args.Sprite local bannerSprite if sprite and #sprite>0 then local animate = require( Module:AnimateSprite ).animate bannerSprite = animate{ args.Sprite, sheet = 'SlotSprite' }	else bannerSprite = ' ' end arrow :tag( 'span' ) :addClass( 'mcui-bannerSprite' ) :wikitext( bannerSprite ) body :tag( 'span' ) :addClass( 'mcui-output' ) :wikitext( addSlot( args, 'Output', 'O', 'invslot-large' ) ) return tostring( mw.html.create( 'div' ):node( body ) ) end

-- Grindstone function p.grindstone( f ) local args = f	if f == mw.getCurrentFrame then args = f:getParent.args else f = mw.getCurrentFrame end local body = mw.html.create( 'span' ):addClass( 'mcui mcui-Grindstone pixel-image' ) local grindstone = body:tag( 'span' ):addClass( 'mcui-grindstone' ) grindstone:wikitext( addSlot( args, 'Input1', 'I1', 'mcui-input1' ) ) grindstone:wikitext( addSlot( args, 'Input2', 'I2', 'mcui-input2' ) ) local arrow = body:tag( 'span' ):addClass( 'mcui-arrow' ) if args.arrow or  ~=  then arrow:css(			'background-image',			''		) end body :tag( 'span' ) :addClass( 'mcui-output' ) :wikitext( addSlot( args, 'Output', 'O', 'invslot-large' ) ) return tostring( mw.html.create( 'div' ):node( body ) ) end

-- Melody function p.noteSequence(f) local args = getArgs(f) local sequence = args[1] return p._noteSequence(sequence) end

function p._noteSequence(sequence) local function simpleSlot(frames) frames = parseFrameText(frames, nil, false, {aliases = '', default = nil}) local function simpleMakeItem(name) return mw.html.create('span'):addClass('invslot-item invslot-item-image'):wikitext(''):done end local body = mw.html.create('span'):addClass('invslot animated') local activeFrame = 1 for i, frame in ipairs(frames) do           local item if frame[1] then item = body:tag('span'):addClass('animated-subframe') local subActiveFrame = 1 --FC-frame.randomise and random(#frame) or 1 for sI, sFrame in ipairs(frame) do                   local sItem = simpleMakeItem(sFrame.name) item:node(sItem) if sI == subActiveFrame then sItem:addClass('animated-active') else sItem:addClass('hidden') end end else item = simpleMakeItem(frame.name) body:node(item) end if i == activeFrame and animated then item:addClass('animated-active') elseif animated then item:addClass('hidden') end end return mw.getCurrentFrame:preprocess(tostring(body)) end

local colors = { "Red", "Yellow", "Lime", "Green", "Purple", "Blue", "Light_Blue" }

local slots = {} for x = 1,7,1 do       slots[x] = {} for y = 1,6,1 do          if y == 5 then slots[x][y] = sequence:gsub('['..x..']', 'Block_of_Quartz;') else slots[x][y] = sequence:gsub('['..x..']', colors[x]..'_Wool;') end if y == 5 then slots[x][y] = slots[x][y]:gsub('[%d%s]', colors[x]..'_Stained_Clay;') else slots[x][y] = slots[x][y]:gsub('[%d%s]', colors[x]..'_Stained_Glass_Pane;') end if y == 5 then for z = 1,y,1 do                      slots[x][y] = colors[x]..'_Stained_Clay;'..slots[x][y] end for z = 1,12-y,1 do                      slots[x][y] = slots[x][y]..colors[x]..'_Stained_Clay;' end else for z = 1,y,1 do                      slots[x][y] = colors[x]..'_Stained_Glass_Pane;'..slots[x][y] end for z = 1,12-y,1 do                      slots[x][y] = slots[x][y]..colors[x]..'_Stained_Glass_Pane;' end end slots[x][y] = slots[x][y]:gsub('[_]', ' ') end end

local table = mw.html.create('table'):addClass('mcui mcui-Crafting_Table pixel-image'):css({margin='0 auto', display='table', cursor='not-allowed'})

for y = 1,6,1 do       local row = table:tag("tr"):addClass('mcui-row') row:tag("td"):wikitext( simpleSlot('Gray Stained Glass Pane') ):done for x = 1,7,1 do           row:tag("td"):wikitext( simpleSlot(slots[x][y]) ):done end row:tag("td"):wikitext( simpleSlot('Gray Stained Glass Pane') ):done row:done end table:done return tostring(table) end

- -- Template: Collection UI -- -- Creates a main collection UI for a given item - function p.collectionUI(frame) return p._collectionUI(pipeline(frame, getArgs, table.unpackRaw)) end

- -- _collectionUI Helper functions - local rarityReplace = mw.clone(rarityAliases) for k, v in pairs(rarityReplace) do	rarityReplace[k] = '' end

local function replaceRarity(s) return s and s:gsub(s, rarityReplace) end - -- function: _collectionUI(args: table|frame) -- -- Invoked by. - function p._collectionUI(args) checkType(1, args, { 'table' }) local slots = {} local collection = args[1] and args[1]:gsub('E?n?c?h?a?n?t?e?d? ?', ):gsub('Block ?o?f? ?', ) local title = mw.title.getCurrentTitle local wt = mw.html.create('table') :attr{ class="mcui mcui-Crafting_Table pixel-image" } :css{ ['margin'] = '0 auto'; ['display'] = 'table'; }		:tag('tr') :css{ ['position'] = 'absolute'; ['top'] = '2px'; }			:tag('td') :attr{ colspan=9 } :css{ ['font-family'] = 'minecraft'; ['color'] = 'black'; ['font-size'] = '16px'; }				:wikitext(collection or title.rootText) :done :done for x = 1, 9, 1 do		slots[x] = {} if x >= 3 and x <= 4 then local rowArgs = table.numData(args) local total = 0 for i = 1, 2, 1 do				local v = rowArgs[i] and rowArgs[i].row local rewards = {} local count = 0 if v then for i, v in ipairs(string.split(v, '\n')) do						local _type v = string.methods(v):_trim if v:getValue ~= '' and i <= 9 then if v:charAt(1) == "*" then if v:charAt(2) == "*" then _type = 'item' else _type = 'amount' end end if _type == 'amount' then count = count+1 rewards[count] = {} rewards[count].amount = v:sub(2) elseif _type == 'item' then local item, type = v:sub(3):match('^(.-)%s*,%s*(.+)$') item = item or v:sub(3) local tooltip = tooltips[item] local split = string.split(tooltip and tooltip.text, '[\n\\]') table.push(rewards[count], { item, rarity = replaceRarity(split[#split-1]) or '&f&l', type=type }) end end end end for y, v in ipairs(rewards) do					total = total+1 error(table.dump(slots)) slots[i+3][y] = { total == 1 and "Yello Stained Glass Pane,"..total or 'Red Stained Glass Pane,'..total, title=table.concat{ '&e', collection, ' ', string._toRoman(total) }, text=uiText(dedent						\n&7Progress: &e0&6%%						&f%s &e0&6\/&e%s						&7%s:						%s						&eClick to view rewards!						):format(							('-'):rep(20),							string._formatNum(string._toNumber(v.amount)),							#v > 1 and 'Recipes' or 'Recipe',							table.concat(table.map(v, function(val)								return table.concat{ val.rarity..val[1], ' ', val.type or 'Recipe' }							end), '/')						) }				end end end for y = 1, 6, 1 do			if x == 1 and y == 5 then slots[x][y] = { args.title or collection..' Collection', link='none', title='&a'..collection..' Collection', text=uiText(dedent					&7View all your %s Collection 					&7progress and rewards!					&7Total Collected: &e0					:format(collection)) }			else slots[x][y] = { 'Blank' } end end end for x, xValue in ipairs(slots) do		for y, yValue in ipairs(xValue) do		end end end

- -- function: test(parameters) -- -- - function p.test(v) local rewards = {} for i, v in ipairs(string.split(v, '\n')) do						local _type v = string.methods(v):_trim if v:getValue ~= '' then if v:charAt(1) == "*" then if v:charAt(2) == "*" then _type = 'item' else _type = 'amount' end end if _type == 'amount' then count = count+1 rewards[count] = {} rewards[count].amount = v:sub(3) elseif _type == 'item' then table.push(rewards[count], v:sub(3)) end end end return table.dump(rewards) end

return p