Module:Inventory

From Modded Wiki
Jump to navigation Jump to search

Documentation for this module may be created at Module:Inventory/doc

local p = {}
local noInvText = 0

--[[

LOCAL addInventory()

Adds inventory underneath the GUI, true by default

]]
local function addInventory(args)
	local hotbar = {}
	local j = 0
	while j < 9 do
		table.insert(hotbar, require("Module:Inventory slot").slot{args[j + 1]})
		j = j + 1
	end
	
	local inventory = {}
	
	local i = 1
	while i < 4 do
		table.insert(inventory, '<span style="display: block;">')
		
		-- For each column (9 for each row)
		local j = 0
		while j < 9 do
			table.insert(inventory, require("Module:Inventory slot").slot{args[(i*9) + j + 1]})
			j = j + 1
		end
		
		table.insert(inventory, '</span>')
		i = i + 1
	end
	
	function _invText()
		if noInvText == 1 then
			return ''
		else
			return '<span style="position: absolute; bottom:159px; left: 8px; color: #3F3F3F; font-family: Minecraft; font-size: 16px;">Inventory</span>'
		end
	end
	return _invText() .. '<span style="position: absolute; bottom: 6px; left: 6px">' .. table.concat(inventory) .. '<span style="display:block; margin-top:8px">'.. table.concat(hotbar) .. '</span></span>'
end

--[[

LOCAL recipeBook()

Adds a recipe book for survival, crafting table and furnace inventories

]]


local function recipeBook(t)
	local attr = ''
	
	if t == 's' then attr = 'top: 114px; left: 200px;' 
	elseif t == 'ct' then attr = 'top: 60px; left: 2px;'
	else attr = 'top: 60px; left: 32px;' end
	
	return '<span class="mcui-Inventory-Recipe_Book-button" style="position: absolute;' .. attr .. 'padding: 2px 4px 2px 4px;">[[File:Invicon Recipe Book.png|32px|link=]]</span>'
end

--[[

{{#invoke: Inventory|crafting}}

]]

function p.crafting( f )
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	local slot = require( 'Module:Inventory slot' )
	
	local inv = ''

	if args.noinv ~= nil or args.noinv ~= '' then
		inv = addInventory(args)
	end
	
	local tableHeight = '' 
	
	if args.noinv then tableHeight = '124px' else tableHeight = '304px' end
	
	return '<div><span class="mcui mcui-Inventory-border pixel-image" style="box-sizing: content-box; border-width: 8px; border-style: solid; border-radius: 0; background-clip: padding-box; width: 324px; height:' .. tableHeight .. '">' ..
	'<span style="display: block; color: #3F3F3F; font-family: Minecraft; font-size: 16px; text-align:left; margin-left: 44px; margin-top: -6px; overflow: hidden; text-overflow: ellipsis;">' .. (args.title or 'Crafting') .. '</span>' ..
	'<span style="position: absolute; top: 24px; left: 50px;"><span style="display: block;">' .. slot.slot{args.A1} .. slot.slot{args.B1} .. slot.slot{args.C1} .. '</span>'..
	'<span style="display: block;">' .. slot.slot{args.A2} .. slot.slot{args.B2} .. slot.slot{args.C2} .. '</span>'..
	'<span style="display: block;">' .. slot.slot{args.A3} .. slot.slot{args.B3} .. slot.slot{args.C3} .. '</span></span>' ..
	'<span class="mcui-Inventory-Crafting_Table-arrow" style="position: absolute; top: 60px; left: 172px; width: 44px; height: 32px;"><br></span>' ..
	slot.slot{args.Output, class='invslot-large', style='position: absolute; top: 52px; left: 230px;'} .. 
	recipeBook('ct') .. inv .. '</span></div>'
end

--[[

{{#invoke: Inventory|furnace}}

]]

function p.furnace( f )
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	local slot = require( 'Module:Inventory slot' )
	
	local inv = ''
	
	if args.noinv ~= nil or args.noinv ~= '' then
		inv = addInventory(args)
	end
	
	local tableHeight = '' 
	
	if args.noinv then tableHeight = '124px' else tableHeight = '304px' end
	
	lit = ''
	if args.lit == nil or args.lit == '' then lit = '-inactive' end
	
	return '<div><span class="mcui mcui-Inventory-border pixel-image" style="box-sizing: content-box; border-width: 8px; border-style: solid; border-radius: 0; background-clip: padding-box; width: 324px; height:' .. tableHeight .. '">' ..
	'<span style="display: block; color: #3F3F3F; font-family: Minecraft; font-size: 16px; text-align:center; margin-top: -6px; overflow: hidden; text-overflow: ellipsis;">' .. (args.title or 'Furnace') .. '</span>' ..
	'<span style="position: absolute; top: 24px; left: 102px;">' .. slot.slot{args.Input} .. '<span class="mcui-Inventory-Furnace-fire' .. lit .. '" style="display: block; width: 36px; height: 36px;"><br></span>' ..
	slot.slot{args.Fuel, style='display: block; position: absolute; top: 72px;'} ..
	'<span class="mcui-Inventory-Furnace-progress'.. lit ..'" style="display: block; position: absolute; top: 36px; left: 50px; width: 44px; height: 36px;"><br></span>' ..
	slot.slot{args.Output, class='invslot-large', style='position: absolute; top: 28px; left: 112px;'} .. '</span>' ..
	recipeBook('f') .. inv .. '</span></div>'
end

--[[

{{#invoke: Inventory|brewing}}

]]

function p.brewing (f)
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	local slot = require( 'Module:Inventory slot' )
	
	local inv = ''

	if args.noinv ~= nil or args.noinv ~= '' then
		inv = addInventory(args)
	end
	
	local tableHeight = '' 
	
	if args.noinv then tableHeight = '124px' else tableHeight = '304px' end
	
	local function _fuel ()
		if args.fuel and args.fuel ~= '' then
			if tonumber(args.fuel) <= 100 then
				return (36 / 100 * tonumber(args.fuel))
			else
				return 36
			end
		else
			return 0
		end
	end

	local function _progress ()
		if args.progress and args.progress ~= '' then
			local progress = 57
			
			if tonumber(args.progress) <= 100 then 
				progress = 57 / 100 * tonumber(args.progress)
			end
			
			return '<span class="mcui-Inventory-Brewing_Stand-arrow" style="position: absolute; top: 21px; left: 184px; width: 18px; height:' .. progress .. 'px;"><br></span>'
		else
			return ''
		end
	end
		
	return '<div><span class="mcui mcui-Inventory-border pixel-image" style="box-sizing: content-box; border-width: 8px; border-style: solid; border-radius: 0; background-clip: padding-box; width: 324px; height:' .. tableHeight .. '">' ..
	'<span style="display: block; color: #3F3F3F; font-family: Minecraft; font-size: 16px; text-align:center; margin-top: -6px; overflow: hidden; text-overflow: ellipsis;">' .. (args.title or 'Brewing Stand') .. '</span>' ..
	slot.slot{args.Fuel, default='Brewing Fuel', style='position: absolute; top: 24px; left: 24px;'} .. 
	slot.slot{args.Input, style='position: absolute; top: 24px; left: 148px;'} .. 
	slot.slot{args.Output1, default='Brewing', style='position: absolute; top: 92px; left: 102px;'} .. 
	slot.slot{args.Output2, default='Brewing', style='position: absolute; top: 106px; left: 148px;' } .. 
	slot.slot{args.Output3, default='Brewing', style='position: absolute; top: 92px; left: 194px;'} ..
	'<span class="mcui-Inventory-Brewing_Stand-pipes" style="position: absolute; top: 48px; left: 58px; width: 92px; height: 42px;"><br></span>' ..
	'<span class="mcui-Inventory-Brewing_Stand-paths" style="position: absolute; top: 58px; left: 136px; width: 60px; height: 50px;"><br></span>' ..
	'<span class="mcui-Inventory-Brewing_Stand-fuel" style="position: absolute; top: 80px; left: 112px; background-size: cover; width:' .. _fuel() .. 'px; height: 8px;"><br></span>' ..
	'<span class="mcui-Inventory-Brewing_Stand-bubbles' .. (args.progress or '-inactive') .. '" style="position: absolute; top: 21px; left: 120px; background-size: cover; width: 24px; height: 57px;"><br></span>' ..
	'<span class="mcui-Inventory-Brewing_Stand-arrow-inactive" style="position: absolute; top: 21px; left: 184px; width: 18px; height: 57px;"><br></span>' ..
	_progress() ..
	inv .. '</span></div>'
end

--[[

{{#invoke: Inventory|anvil}}

]]

function p.anvil (f)
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	local slot = require( 'Module:Inventory slot' )
	
	local inv = ''

	if args.noinv ~= nil or args.noinv ~= '' then
		inv = addInventory(args)
	end
	
	local tableHeight = '' 
	
	if args.noinv then tableHeight = '124px' else tableHeight = '304px' end
	
	local crossed = ''
	
	if args.crossed then
		crossed = '-inactive'
	end
	
	function _title()
		if args.text then
			
			local _text = mw.html.create( 'span' ):addClass('mcui-Anvil-inputbox mcui-input')
			if args.Input1 or args.text then
				local animate = require( [[Module:AnimateText]] ).animate
				
				if args.text then
					itemName = animate{
						args.text:gsub( ';' , ',,' )
	    			}
				else
					itemName = animate{
						args.Input1:gsub( ';' , ',,' )
	    			}
	    		end
			else
				_text:addClass( 'mcui-inactive' )
				itemName = '<br>'
			end
			
			_text:wikitext( ( itemName:gsub( 'class="animated"', 'class="mcui-Anvil-inputtext animated"' ) ) )
			
			return '<span class="mcui-Inventory-Anvil-input" style="position: absolute; top: 32px; right: 6px; width: 220px; height: 32px;">'..
			'<span style="display: block; margin: 5px 6px; color: #FCFCFC; text-shadow: 0.125em 0.125em 0 #3E3E3E; font-family: Minecraft; font-size: 16px; overflow: hidden; text-overflow: ellipsis; max-width: 208px;">' ..
			tostring(_text) ..
			'</span></span>'
		else
			return '<span class="mcui-Inventory-Anvil-input-inactive" style="position: absolute; top: 32px; right: 6px; width: 220px; height: 32px;"><br></span>'
		end
	end
	
	function _cost()
		--return '' --
		if args.cost and args.cost ~= '' then

			function _expensive()
				if args.expensive and args.expensive ~= '' then
					return 'color: #FC5F5F; text-shadow: 0.125em 0.125em #3E1818, 0.125em 0 #3E1818, 0 0.125em #3E1818;'
				else
					return 'color: #7EFC20; text-shadow: 0.125em 0.125em #203E08, 0.125em 0 #203E08, 0 0.125em #203E08;'
				end
			end
			
			function _cost()
				if args.cost == 'expensive' then
					return 'Too Expensive!'
				else
					return 'Enchantment Cost: ' .. args.cost
				end
			end
			
			return '<span style="display: block; position: absolute; top: 126px; right: 8px; background: #898989; padding: 0 4px 0 4px; font-family: Minecraft; font-size: 16px;' ..
			_expensive() .. 'overflow: hidden; text-overflow: ellipsis; max-width: 308px;">' .. _cost() .. '</span>'
		end
		
		return ''
	end
	
	return '<div><span class="mcui mcui-Inventory-border pixel-image" style="box-sizing: content-box; border-width: 8px; border-style: solid; border-radius: 0; background-clip: padding-box; width: 324px; height:' .. tableHeight .. '">' ..
	'<span style="display: block; color: #3F3F3F; font-family: Minecraft; font-size: 16px; text-align:left; margin-left: 106px; margin-top: -6px; overflow: hidden; text-overflow: ellipsis;">' .. (args.title or 'Repair & Name') .. '</span>' ..
	_title() ..
	'<span style="display: block; position: absolute; top: 84px; left: 44px;">' ..
	slot.slot{args.Input1} ..
	slot.slot{args.Input2, style='margin-left: 62px'} ..
	slot.slot{args.Output, style='margin-left: 80px'} .. '</span>' ..
	'<span class="mcui-Inventory-Anvil-hammer" style="position: absolute; top: 6px; left: 26px; background-size: cover; width: 60px; height: 60px;"><br></span>' ..
	'<span class="mcui-Inventory-Anvil-plus" style="position: absolute; top: 90px; left: 98px; background-size: cover; width: 26px; height: 26px;"><br></span>' ..
	'<span class="mcui-Inventory-Anvil-arrow'.. crossed ..'" style="display: block; position: absolute; top: 88px; left: 196px; width: 44px; height: 30px;"><br></span>' ..
	_cost()  ..
	inv .. '</span></div>'
end

--[[

{{#invoke: Inventory|legacy_smithing}}

]]

function p.legacy_smithing (f)
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	local slot = require( 'Module:Inventory slot' )	
	
	local inv = ''

	if args.noinv ~= nil or args.noinv ~= '' then
		inv = addInventory(args)
	end
	
	local crossed = ''
	
	if args.crossed then
		crossed = '-inactive'
	end
	
	local tableHeight = '' 
	
	if args.noinv then tableHeight = '124px' else tableHeight = '304px' end
		
	return '<div><span class="mcui mcui-Inventory-border pixel-image" style="box-sizing: content-box; border-width: 8px; border-style: solid; border-radius: 0; background-clip: padding-box; width: 324px; height:' .. tableHeight .. '">' ..
	'<span style="display: block; color: #3F3F3F; font-family: Minecraft; font-size: 16px; text-align:left; margin-left: 106px; margin-top: 18px; overflow: hidden; text-overflow: ellipsis;">' .. (args.title or 'Upgrade Gear') .. '</span>' ..
	'<span style="display: block; position: absolute; top: 84px; left: 44px;">' ..
	slot.slot{args.Input1} ..
	slot.slot{args.Input2, default = 'Smithing', style='margin-left: 62px'} ..
	slot.slot{args.Output, style='margin-left: 80px'} .. '</span>' ..
	'<span class="mcui-Inventory-Smithing_Table-hammer" style="position: absolute; top: 6px; left: 26px; background-size: cover; width: 60px; height: 60px;"><br></span>' ..
	'<span class="mcui-Inventory-Anvil-plus" style="position: absolute; top: 90px; left: 98px; background-size: cover; width: 26px; height: 26px;"><br></span>' ..
	'<span class="mcui-Inventory-Anvil-arrow'.. crossed ..'" style="display: block; position: absolute; top: 88px; left: 196px; width: 44px; height: 30px;"><br></span>' ..
	inv .. '</span></div>'
end

--[[

{{#invoke: Inventory|smithing}}

]]

function p.smithing (f)
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	local slot = require( 'Module:Inventory slot' )
	
	local inv = ''

	if args.noinv ~= nil or args.noinv ~= '' then
		inv = addInventory(args)
	end
	
	return ''
end

--[[

{{#invoke: Inventory|survival}}

]]

function p.survival (f)
	local args = f
	if f == mw.getCurrentFrame() then 
		args = require( 'Module:ProcessArgs' ).merge( true )
	else
		f = mw.getCurrentFrame()
	end
	local slot = require( 'Module:Inventory slot' )
	
	noInvText = 1
	local inv = addInventory(args)
	
	function _armor()
		return '<span style="display: block; position: absolute; top: 6px; left: 6px;">' ..
		slot.slot{args[103], default = (args[103] or 'Head'), style = 'display: block;'} ..
		slot.slot{args[102], default = (args[102] or 'Chest'), style = 'display: block;'} ..
		slot.slot{args[101], default = (args[101] or 'Legs'), style = 'display: block;'} ..
		slot.slot{args[100], default = (args[100] or 'Feet'), style = 'display: block;'} ..
		'</span>' .. 
		'<span class="invslot" style="display: block; position: absolute; top: 6px; left: 42px; width: 98px; height: 140px; background:' .. (args.background or 'black') .. ';"><span class="mcui-Inventory-Player-Steve" style="display: block; position: absolute; width: 98px; height: 140px;"></span><br></span>' ..
		slot.slot{args.offhand, default = (args.offhand or 'Offhand'), style = 'position: absolute; top: 114px; left: 144px;'} ..
		''
	end
	
	return '<div><span class="mcui mcui-Inventory-border pixel-image" style="box-sizing: content-box; border-width: 8px; border-style: solid; border-radius: 0; background-clip: padding-box; width: 324px; height: 304px">' ..
	_armor() ..
	'<span style="position: absolute; top: 26px; left: 186px;"><span style="position: absolute; top: -26px; color: #3F3F3F; font-family: Minecraft; font-size: 16px;">Crafting</span>' ..
	'<span style="display:inline-block;"><span style="display:block;">' .. slot.slot{(args.A1 or '')} .. slot.slot{(args.B1 or '')} .. '</span>' ..
	'<span style="display:block;">' .. slot.slot{(args.A2 or '')} .. slot.slot{(args.B2 or '')} .. '</span></span>' ..
	'<span class="mcui-Inventory-Table-arrow" style="display: inline-block; width: 32px; height: 26px; vertical-align: top; margin-left: 4px; margin-top: 24px;"><br></span>'..
	'<span style="display: inline-block; vertical-align: top; margin-left: 4px; margin-top: 20px;">' .. slot.slot{(args.Output or '')} ..'</span></span>' ..
	recipeBook('s') .. inv .. '</span></div>'
end

return p