Module:Inventory slot/Aliases

-- Initially taken from https://minecraft.gamepedia.com/Module:Inventory_slot/Aliases

local loader = require('Module:Loader')

local string, table, uiText, rarityTier, tooltipsTable, templates, itemVariants = loader.require('String', 'Table', 'UIText', 'RarityTier', 'Inventory slot/Tooltips', 'Inventory_slot/Templates', 'Item/Variants')

local minionData, colorData = loader.loadData('Minion/Data', 'Color/Data')

local aliasesTable, templatesTable, itemVariantsTable = {}, {}, {}

-- Extensible format for transmission of data from fields of Inventory slot/Tooltips to slot -- Same as 'otherInputBoxes' on MediaWiki:Gadget-TooltipsEditor.js local otherInputBoxes = { { 'name' }, { 'title', optional = true }, { 'text', optional = true }, }

local function getTooltips(keys) if type(keys) == "table" then local ret = {} for i, key in ipairs(keys) do			ret[i] = tooltipsTable[key] or aliasesTable[key] or templatesTable[key] or itemVariantsTable[key] end return ret else return tooltipsTable[keys] or aliasesTable[keys] or templatesTable[keys] or itemVariantsTable[keys] end end

-- Item Tool tips -- -- See https://hypixel.net/threads/guide-minecraft-color-codes.1741307/ -- for information on the color syntax. -- -- Other syntax: -- *\ - New line

-- -- Hypixel Skyblock stuff -- table.merge(aliasesTable, {	-- Fake items	['Air (minion)'] = { title = 'Air', name = 'Minions', image = 'Air (minion)', text = '&7Air should be 1 layer/underneath where the minion/is standing.', link = 'none' },	['Blank'] = { image = 'Black Stained Glass Pane', name = 'none', title = 'none', link='none', text='none' },	['Sell Item'] = { name = 'Hopper', title = '&aSell Item', link='none', text='&7Click items in your inventory to/sell them to the shop!' },	['Close'] = { name = 'Barrier', title = '&cClose', link='none', text='none' },	['Cancel'] = { name = 'Barrier', title = '&cCancel', link='none', text='none' },	['Go Back'] = { name = 'Arrow', title = '&aGo Back', link='none'},	['Next Page'] = { name = 'Arrow', title = '&aNext Page', link='none'},	['Previous Page'] = { name = 'Arrow', title = '&aPrevious Page', link='none'},	['SkyBlock Menu'] = { name = 'SkyBlock Menu', title = '&aSkyBlock Menu &7(Right Click)', text = '&7View all of your SkyBlock/&7progress, including your Skills,/&7Collections, Recipes, and more!//&eClick to open!', }, })

-- Make it so minions tiers use the image, but link to actual page local minions = table.keys(minionData)

table.each(minions, function(name)	local stats = minionData[name].stats	local description = minionData[name].description or 'No Description'	for i,v in ipairs(stats) do		local tier = string._toRoman(i)   	local key = name.." Minion "..tier		aliasesTable[key] = { title = '&9'..key, name = name.." Minion#"..tier, image = key, text = description..'//&7Time Between Action: &a'..v.tba..'s/&7Max Storage: &e'..v.storage }	end end)

-- Other colored items -- local colors = colorData.MCColors -- UI Blank (Any Specific Color) -- for _, color in ipairs(colors) do	aliasesTable['Blank ('..color..')'] = { image = color..' Stained Glass Pane', name = 'none', title = 'none', link='none', text='none' } end

local MAX_RUNS = 20 local allow_continue, made_change, currentProcess, templateStorage, installed, runs = true, false, 1, {}, {}, 0 while allow_continue and ((currentProcess == 1) or (table.length(templateStorage) > 0)) do	if (currentProcess > 1) and (not made_change) then allow_continue = false end runs, made_change = runs + 1, false if runs > MAX_RUNS then error('Too many iterations in processing templates') end for key, values in pairs(currentProcess == 1 and templates or templateStorage) do		local default = getTooltips(key) if not default then if allow_continue then templateStorage[key] = values else --error('Key '..key..' no default') end else made_change = true table.push(installed, key) local mandatoryFields = table.merge({ 'title', 'text' }, table.map(table.filter(otherInputBoxes, function(v)				return not v.optional			end), function(v) return v[1] end)) local optionalFields = table.map(table.filter(otherInputBoxes, function(v) return v.optional end), function(v) return v[1] end) local allFields = table.merge({}, mandatoryFields, optionalFields) for _, v in ipairs(mandatoryFields) do if not default[v] then error('Key ' .. key .. ' no default ' .. v) end end local g = { id = values.id } for _, v in ipairs(allFields) do g[v] = default[v] end if type(values) ~= 'table' then values = { values } end for _,item in ipairs(values) do -- ipairs: won't read global settings local repLs = {} local function repl(str) local function _repl(args) for _,sym in ipairs(args) do							str = str:gsub(('{%s}'):format(sym), repLs[sym] or '') end return str end -- Apply all replacements local special, numeric = string.split('osrl', ''), {} local ret = _repl(special) -- special(1st) for i in ret:gmatch('{(%d+)}') do						table.push(numeric, i)					end local ret = _repl(numeric) -- numeric after special(1st) local ret = _repl(special) -- special(2nd) after numeric return ret end local loc = {} local raw, id, vars, rare if type(item) == 'table' then raw = item[1] id, rare = item.id or g.id or item[1], item.r or item.rarity vars = table.slice(item, 2) for _, v in ipairs(allFields) do loc[v] = item[v] or g[v] end else raw, id = item, g.id or item for _, v in ipairs(allFields) do loc[v] = g[v] end end for i,v in ipairs(type(vars) == 'table' and vars or { vars }) do					repLs[tostring(i-1)] = tostring(v):gsub('%%','%%%%') -- so that it does not incorrectly remove '%'s				end repLs['o'], repLs['s'] = raw, raw id = repl(id) repLs['s'] = id				if rare then repLs['r'] = ('&%s'):format(uiText.getFormatting(rare)) repLs['l'] = ('%s&l%s&r'):format(repLs['r'], rarityTier._getRarity(rare):upper) end for k, v in pairs(loc) do					loc[k] = repl(v) end -- Directly insert to tooltips templatesTable[id] = loc end end end for _, key in ipairs(installed) do		templateStorage[key] = nil end currentProcess, installed = currentProcess + 1, {} end

for k,v in pairs(itemVariants) do	itemVariantsTable[k] = getTooltips(v) end

return table.merge( {}, tooltipsTable, aliasesTable, templatesTable, itemVariantsTable )