imported>Ttv pedro270707 |
imported>Ttv pedro270707 |
Line 1: |
Line 1: |
| local p = {} | | local p = {} |
|
| |
| p.itemSets = {
| |
| ["Any Wool"] = {
| |
| "White Wool",
| |
| "Orange Wool",
| |
| "Magenta Wool",
| |
| "Light Blue Wool",
| |
| "Yellow Wool",
| |
| "Lime Wool",
| |
| "Pink Wool",
| |
| "Gray Wool",
| |
| "Light Gray Wool",
| |
| "Cyan Wool",
| |
| "Purple Wool",
| |
| "Blue Wool",
| |
| "Brown Wool",
| |
| "Green Wool",
| |
| "Red Wool",
| |
| "Black Wool"
| |
| },
| |
| ["Any Planks"] = {
| |
| "Wooden Planks",
| |
| "White Wooden Planks",
| |
| "Orange Wooden Planks",
| |
| "Magenta Wooden Planks",
| |
| "Light Blue Wooden Planks",
| |
| "Yellow Wooden Planks",
| |
| "Lime Wooden Planks",
| |
| "Pink Wooden Planks",
| |
| "Gray Wooden Planks",
| |
| "Light Gray Wooden Planks",
| |
| "Cyan Wooden Planks",
| |
| "Purple Wooden Planks",
| |
| "Blue Wooden Planks",
| |
| "Brown Wooden Planks",
| |
| "Green Wooden Planks",
| |
| "Red Wooden Planks",
| |
| "Black Wooden Planks"
| |
| },
| |
| ["Any Wooden Stairs"] = {
| |
| "Wooden Stairs",
| |
| "White Wooden Stairs",
| |
| "Orange Wooden Stairs",
| |
| "Magenta Wooden Stairs",
| |
| "Light Blue Wooden Stairs",
| |
| "Yellow Wooden Stairs",
| |
| "Lime Wooden Stairs",
| |
| "Pink Wooden Stairs",
| |
| "Gray Wooden Stairs",
| |
| "Light Gray Wooden Stairs",
| |
| "Cyan Wooden Stairs",
| |
| "Purple Wooden Stairs",
| |
| "Blue Wooden Stairs",
| |
| "Brown Wooden Stairs",
| |
| "Green Wooden Stairs",
| |
| "Red Wooden Stairs",
| |
| "Black Wooden Stairs"
| |
| },
| |
| ["Any Fence"] = {
| |
| "Oak Fence",
| |
| "White Wooden Fence",
| |
| "Orange Wooden Fence",
| |
| "Magenta Wooden Fence",
| |
| "Light Blue Wooden Fence",
| |
| "Yellow Wooden Fence",
| |
| "Lime Wooden Fence",
| |
| "Pink Wooden Fence",
| |
| "Gray Wooden Fence",
| |
| "Light Gray Wooden Fence",
| |
| "Cyan Wooden Fence",
| |
| "Purple Wooden Fence",
| |
| "Blue Wooden Fence",
| |
| "Brown Wooden Fence",
| |
| "Green Wooden Fence",
| |
| "Red Wooden Fence",
| |
| "Black Wooden Fence"
| |
| },
| |
| ["Any Fence Gate"] = {
| |
| "Wooden Fence Gate",
| |
| "White Wooden Fence Gate",
| |
| "Orange Wooden Fence Gate",
| |
| "Magenta Wooden Fence Gate",
| |
| "Light Blue Wooden Fence Gate",
| |
| "Yellow Wooden Fence Gate",
| |
| "Lime Wooden Fence Gate",
| |
| "Pink Wooden Fence Gate",
| |
| "Gray Wooden Fence Gate",
| |
| "Light Gray Wooden Fence Gate",
| |
| "Cyan Wooden Fence Gate",
| |
| "Purple Wooden Fence Gate",
| |
| "Blue Wooden Fence Gate",
| |
| "Brown Wooden Fence Gate",
| |
| "Green Wooden Fence Gate",
| |
| "Red Wooden Fence Gate",
| |
| "Black Wooden Fence Gate"
| |
| },
| |
| ["Any Wooden Slab"] = {
| |
| "Wooden Slab",
| |
| "White Wooden Slab",
| |
| "Orange Wooden Slab",
| |
| "Magenta Wooden Slab",
| |
| "Light Blue Wooden Slab",
| |
| "Yellow Wooden Slab",
| |
| "Lime Wooden Slab",
| |
| "Pink Wooden Slab",
| |
| "Gray Wooden Slab",
| |
| "Light Gray Wooden Slab",
| |
| "Cyan Wooden Slab",
| |
| "Purple Wooden Slab",
| |
| "Blue Wooden Slab",
| |
| "Brown Wooden Slab",
| |
| "Green Wooden Slab",
| |
| "Red Wooden Slab",
| |
| "Black Wooden Slab"
| |
| },
| |
| ["Any Wooden Chest"] = {
| |
| "Wooden Chest",
| |
| "White Wooden Chest",
| |
| "Orange Wooden Chest",
| |
| "Magenta Wooden Chest",
| |
| "Light Blue Wooden Chest",
| |
| "Yellow Wooden Chest",
| |
| "Lime Wooden Chest",
| |
| "Pink Wooden Chest",
| |
| "Gray Wooden Chest",
| |
| "Light Gray Wooden Chest",
| |
| "Cyan Wooden Chest",
| |
| "Purple Wooden Chest",
| |
| "Blue Wooden Chest",
| |
| "Brown Wooden Chest",
| |
| "Green Wooden Chest",
| |
| "Red Wooden Chest",
| |
| "Black Wooden Chest"
| |
| },
| |
| ["Any Cobblestone"] = {
| |
| "Cobblestone",
| |
| "Cobbled Basalt",
| |
| "Cobbled Limestone",
| |
| "Cobbled Granite"
| |
| },
| |
| ["Any Log"] = {
| |
| "Oak Log",
| |
| "Pine Log",
| |
| "Birch Log",
| |
| "Cherry Log",
| |
| "Eucalyptus Log",
| |
| "Mossy Oak Log"
| |
| },
| |
| ["Any Sapling"] = {
| |
| "Oak Sapling",
| |
| "Retro Oak Sapling",
| |
| "Pine Sapling",
| |
| "Birch Sapling",
| |
| "Cherry Sapling",
| |
| "Eucalyptus Sapling",
| |
| "Shrub Sapling"
| |
| },
| |
| ["Any Redstone Ore"] = {
| |
| "Stone Redstone Ore",
| |
| "Granite Redstone Ore",
| |
| "Limestone Redstone Ore",
| |
| "Basalt Redstone Ore"
| |
| },
| |
| ["Any Iron Ore"] = {
| |
| "Raw Iron Ore",
| |
| "Stone Iron Ore",
| |
| "Granite Iron Ore",
| |
| "Limestone Iron Ore",
| |
| "Basalt Iron Ore"
| |
| },
| |
| ["Any Gold Ore"] = {
| |
| "Raw Gold Ore",
| |
| "Stone Iron Ore",
| |
| "Granite Iron Ore",
| |
| "Limestone Iron Ore",
| |
| "Basalt Iron Ore"
| |
| },
| |
| ["Any Coal Ore"] = {
| |
| "Stone Coal Ore",
| |
| "Granite Coal Ore",
| |
| "Limestone Coal Ore",
| |
| "Basalt Coal Ore"
| |
| },
| |
| ["Any Lapis Lazuli Ore"] = {
| |
| "Stone Lapis Lazuli Ore",
| |
| "Granite Lapis Lazuli Ore",
| |
| "Limestone Lapis Lazuli Ore",
| |
| "Basalt Lapis Lazuli Ore"
| |
| },
| |
| ["Any Diamond Ore"] = {
| |
| "Stone Diamond Ore",
| |
| "Granite Diamond Ore",
| |
| "Limestone Diamond Ore",
| |
| "Basalt Diamond Ore"
| |
| },
| |
| ["Any Music Disc"] = {
| |
| "13 Music Disc",
| |
| "Cat Music Disc",
| |
| "Blocks Music Disc",
| |
| "Chirp Music Disc",
| |
| "Far Music Disc",
| |
| "Mall Music Disc",
| |
| "Mellohi Music Disc",
| |
| "Stal Music Disc",
| |
| "Strad Music Disc",
| |
| "Ward Music Disc",
| |
| "Dog Music Disc",
| |
| "Wait Music Disc"
| |
| },
| |
| ["Leather Armor"] = {
| |
| "Leather Cap",
| |
| "Leather Tunic",
| |
| "Leather Pants",
| |
| "Leather Boots"
| |
| },
| |
| ["Chainmail Armor"] = {
| |
| "Chainmail Helmet",
| |
| "Chainmail Chestplate",
| |
| "Chainmail Leggings",
| |
| "Chainmail Boots"
| |
| },
| |
| ["Iron Armor"] = {
| |
| "Iron Helmet",
| |
| "Iron Chestplate",
| |
| "Iron Leggings",
| |
| "Iron Boots"
| |
| },
| |
| ["Golden Armor"] = {
| |
| "Golden Helmet",
| |
| "Golden Chestplate",
| |
| "Golden Leggings",
| |
| "Golden Boots"
| |
| },
| |
| ["Diamond Armor"] = {
| |
| "Diamond Helmet",
| |
| "Diamond Chestplate",
| |
| "Diamond Leggings",
| |
| "Diamond Boots"
| |
| },
| |
| ["Steel Armor"] = {
| |
| "Steel Helmet",
| |
| "Steel Chestplate",
| |
| "Steel Leggings",
| |
| "Steel Boots"
| |
| },
| |
| ["Any Blast Furnace Fuel"] = {
| |
| "Nether Coal",
| |
| "Olivine",
| |
| "Block of Nether Coal",
| |
| "Block of Olivine"
| |
| },
| |
| ["Any Block of Coal"] = {
| |
| "Block of Coal",
| |
| "Block of Nether Coal",
| |
| "Block of Charcoal"
| |
| },
| |
| ["Any Block of Fuel"] = {
| |
| "Block of Coal",
| |
| "Block of Nether Coal",
| |
| "Block of Charcoal",
| |
| "Block of Olivine"
| |
| },
| |
| --[[ ["Any Fuel"] = {
| |
| "Nether Coal",
| |
| "Olivine",
| |
|
| |
| "Coal",
| |
| "Charcoal",
| |
|
| |
| "Wooden Planks",
| |
| "White Wooden Planks",
| |
| "Orange Wooden Planks",
| |
| "Magenta Wooden Planks",
| |
| "Light Blue Wooden Planks",
| |
| "Yellow Wooden Planks",
| |
| "Lime Wooden Planks",
| |
| "Pink Wooden Planks",
| |
| "Gray Wooden Planks",
| |
| "Light Gray Wooden Planks",
| |
| "Cyan Wooden Planks",
| |
| "Purple Wooden Planks",
| |
| "Blue Wooden Planks",
| |
| "Brown Wooden Planks",
| |
| "Green Wooden Planks",
| |
| "Red Wooden Planks",
| |
| "Black Wooden Planks",
| |
|
| |
| "Oak Sapling",
| |
| "Retro Oak Sapling",
| |
| "Pine Sapling",
| |
| "Birch Sapling",
| |
| "Cherry Sapling",
| |
| "Eucalyptus Sapling",
| |
| "Shrub Sapling",
| |
|
| |
| "Oak Log",
| |
| "Pine Log",
| |
| "Birch Log",
| |
| "Cherry Log",
| |
| "Eucalyptus Log",
| |
| "Mossy Oak Log",
| |
|
| |
| "Oak Fence",
| |
| "White Wooden Fence",
| |
| "Orange Wooden Fence",
| |
| "Magenta Wooden Fence",
| |
| "Light Blue Wooden Fence",
| |
| "Yellow Wooden Fence",
| |
| "Lime Wooden Fence",
| |
| "Pink Wooden Fence",
| |
| "Gray Wooden Fence",
| |
| "Light Gray Wooden Fence",
| |
| "Cyan Wooden Fence",
| |
| "Purple Wooden Fence",
| |
| "Blue Wooden Fence",
| |
| "Brown Wooden Fence",
| |
| "Green Wooden Fence",
| |
| "Red Wooden Fence",
| |
| "Black Wooden Fence",
| |
|
| |
| "Wooden Fence Gate",
| |
| "White Wooden Fence Gate",
| |
| "Orange Wooden Fence Gate",
| |
| "Magenta Wooden Fence Gate",
| |
| "Light Blue Wooden Fence Gate",
| |
| "Yellow Wooden Fence Gate",
| |
| "Lime Wooden Fence Gate",
| |
| "Pink Wooden Fence Gate",
| |
| "Gray Wooden Fence Gate",
| |
| "Light Gray Wooden Fence Gate",
| |
| "Cyan Wooden Fence Gate",
| |
| "Purple Wooden Fence Gate",
| |
| "Blue Wooden Fence Gate",
| |
| "Brown Wooden Fence Gate",
| |
| "Green Wooden Fence Gate",
| |
| "Red Wooden Fence Gate",
| |
| "Black Wooden Fence Gate",
| |
|
| |
| "Wooden Slab",
| |
| "White Wooden Slab",
| |
| "Orange Wooden Slab",
| |
| "Magenta Wooden Slab",
| |
| "Light Blue Wooden Slab",
| |
| "Yellow Wooden Slab",
| |
| "Lime Wooden Slab",
| |
| "Pink Wooden Slab",
| |
| "Gray Wooden Slab",
| |
| "Light Gray Wooden Slab",
| |
| "Cyan Wooden Slab",
| |
| "Purple Wooden Slab",
| |
| "Blue Wooden Slab",
| |
| "Brown Wooden Slab",
| |
| "Green Wooden Slab",
| |
| "Red Wooden Slab",
| |
| "Black Wooden Slab",
| |
|
| |
| "Wooden Stairs",
| |
| "White Wooden Stairs",
| |
| "Orange Wooden Stairs",
| |
| "Magenta Wooden Stairs",
| |
| "Light Blue Wooden Stairs",
| |
| "Yellow Wooden Stairs",
| |
| "Lime Wooden Stairs",
| |
| "Pink Wooden Stairs",
| |
| "Gray Wooden Stairs",
| |
| "Light Gray Wooden Stairs",
| |
| "Cyan Wooden Stairs",
| |
| "Purple Wooden Stairs",
| |
| "Blue Wooden Stairs",
| |
| "Brown Wooden Stairs",
| |
| "Green Wooden Stairs",
| |
| "Red Wooden Stairs",
| |
| "Black Wooden Stairs",
| |
|
| |
| "Wooden Chest",
| |
| "White Wooden Chest",
| |
| "Orange Wooden Chest",
| |
| "Magenta Wooden Chest",
| |
| "Light Blue Wooden Chest",
| |
| "Yellow Wooden Chest",
| |
| "Lime Wooden Chest",
| |
| "Pink Wooden Chest",
| |
| "Gray Wooden Chest",
| |
| "Light Gray Wooden Chest",
| |
| "Cyan Wooden Chest",
| |
| "Purple Wooden Chest",
| |
| "Blue Wooden Chest",
| |
| "Brown Wooden Chest",
| |
| "Green Wooden Chest",
| |
| "Red Wooden Chest",
| |
| "Black Wooden Chest",
| |
|
| |
| "Block of Coal",
| |
| "Block of Nether Coal",
| |
| "Block of Charcoal",
| |
| "Block of Olivine",
| |
|
| |
| "Wooden Pressure Plate",
| |
| "Workbench",
| |
| "Jukebox",
| |
| "Boat",
| |
| "Stick",
| |
| "Sign",
| |
| "Wooden Door",
| |
| "Fishing Rod",
| |
| } --]]
| |
| }
| |
|
| |
|
| function p.createSlot( f ) | | function p.createSlot( f ) |
Line 415: |
Line 8: |
| f = mw.getCurrentFrame() | | f = mw.getCurrentFrame() |
| end | | end |
| | |
| | local aliases = require( "Module:Inventory slot/aliases" ).aliases |
| | | |
| local sprite = require( "Module:Sprite" ).get | | local sprite = require( "Module:Sprite" ).get |
Line 442: |
Line 37: |
| local item = value.item | | local item = value.item |
| local count = value.count | | local count = value.count |
| if p.itemSets[item] then | | if aliases[item] then |
| for j, subvalue in ipairs(p.itemSets[item]) do | | for j, subvalue in ipairs(aliases[item]) do |
| local display = i == j == 1 and "display: inline-block" or "display: none" | | local display = i == j == 1 and "display: inline-block" or "display: none" -- sets display of the first element to `inline-block` and the rest to `none` |
| | local subname = nil |
| | local subitem = nil |
| | local sublink = nil |
| | if type(subvalue) == "string" then |
| | subname = subvalue |
| | subitem = subvalue |
| | else |
| | subname = subvalue.name or subvalue.item |
| | subitem = subvalue.item |
| | end |
| local link = nil | | local link = nil |
| | |
| local slot = mw.html.create( "div" ) | | local slot = mw.html.create( "div" ) |
| slot:addClass( "minecraft-item" ) | | slot:addClass( "minecraft-item" ) |
| :cssText( table.concat( slotCss, ";" ) ) | | :cssText( table.concat( slotCss, ";" ) ) |
| :attr( "data-mctitle", (name or subvalue) ) | | :attr( "data-mctitle", (name or subname or subitem) ) |
| slot:wikitext( sprite( { data = "InvSprite", id = subvalue } ) ) | | |
| if item ~= pageName and subvalue then | | if subitem:match( '\.gif$' ) or subitem:match( '\.png$' ) then |
| link = subvalue | | slot:wikitext( "[[File:" .. subitem .. "|32px]]" ) |
| | else |
| | slot:wikitext( sprite( { data = "InvSprite", id = subvalue } ) ) |
| | end |
| | |
| | if subitem ~= pageName and subname then |
| | link = subname |
| end | | end |
| | | |
This module creates an inventory slot. {{Inventory slot}}
should be preferred, rather than directly invoking this module on the article.
local p = {}
function p.createSlot( f )
local args = f
if f == mw.getCurrentFrame() then
args = require( 'Module:ProcessArgs' ).merge( true )
else
f = mw.getCurrentFrame()
end
local aliases = require( "Module:Inventory slot/aliases" ).aliases
local sprite = require( "Module:Sprite" ).get
local ids = mw.loadData( "Module:InvSprite" ).ids
local width = args.width or 32
local height = args.height or 32
local item = args.item or ""
local pageName = mw.title.getCurrentTitle().text
local slotContainerCss = {
"width: " .. width .. "px",
"height: " .. height .. "px",
"position: relative"
}
local slotContainer = mw.html.create( "div" )
slotContainer:addClass( "inventory-slot" )
:cssText( table.concat( slotContainerCss, ";" ) )
local slotCss = {
"display: inline-block",
"width: 32px",
"height: 32px",
"position: relative"
}
for i, value in ipairs(p.parseString( args.item )) do
local name = value.name
local item = value.item
local count = value.count
if aliases[item] then
for j, subvalue in ipairs(aliases[item]) do
local display = i == j == 1 and "display: inline-block" or "display: none" -- sets display of the first element to `inline-block` and the rest to `none`
local subname = nil
local subitem = nil
local sublink = nil
if type(subvalue) == "string" then
subname = subvalue
subitem = subvalue
else
subname = subvalue.name or subvalue.item
subitem = subvalue.item
end
local link = nil
local slot = mw.html.create( "div" )
slot:addClass( "minecraft-item" )
:cssText( table.concat( slotCss, ";" ) )
:attr( "data-mctitle", (name or subname or subitem) )
if subitem:match( '\.gif$' ) or subitem:match( '\.png$' ) then
slot:wikitext( "[[File:" .. subitem .. "|32px]]" )
else
slot:wikitext( sprite( { data = "InvSprite", id = subvalue } ) )
end
if subitem ~= pageName and subname then
link = subname
end
if count then
local itemCount = mw.html.create( "span" )
itemCount:cssText( "position: absolute; right: -2px; bottom: -5px; pointer-events: none;" )
:addClass( "c-f" )
:addClass( "shadow" )
:wikitext( count )
slot:node( itemCount )
end
if link and mw.title.new( link ).exists then
slotContainer:wikitext( "<span style='" .. display .. "'>" .. "[[" .. link .. "|" .. tostring( slot ) .. "]]" .. "</span>" )
else
slotContainer:wikitext( "<span style='" .. display .. "'>" .. tostring( slot ) .. "</span>" )
end
end
else
local display = i == 1 and "display: inline-block" or "display: none"
local link = nil
local slot = mw.html.create( "div" )
slot:addClass( "minecraft-item" )
:cssText( table.concat( slotCss, ";" ) )
:attr( "data-mctitle", (name or item) )
slot:wikitext( sprite( { data = "InvSprite", id = item } ) )
if item ~= pageName and item then
link = item
end
if count then
local itemCount = mw.html.create( "span" )
itemCount:cssText( "position: absolute; right: -2px; bottom: -5px; pointer-events: none;" )
:addClass( "c-f" )
:addClass( "shadow" )
:wikitext( count )
slot:node( itemCount )
end
if link and mw.title.new( link ).exists then
slotContainer:wikitext( "<span style='" .. display .. "'>" .. "[[" .. link .. "|" .. tostring( slot ) .. "]]" .. "</span>" )
else
slotContainer:wikitext( "<span style='" .. display .. "'>" .. tostring( slot ) .. "</span>" )
end
end
end
return slotContainer
end
function p.parseString(input)
if input then
local strings = {}
for str in input:gmatch("[^;]+") do
table.insert(strings, str:match("^%s*(.-)%s*$"))
end
local result = {}
for _, str in ipairs(strings) do
local name, item, count = str:match("^%[(.-)%](.-),?(%d*)$")
if name then
table.insert(result, { name = name:gsub("^%s*(.-)%s*$", "%1"), item = item:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
else
item, count = str:match("(.-),?(%d*)$")
table.insert(result, { name = nil, item = item:gsub("^%s*(.-)%s*$", "%1"), count = tonumber(count) })
end
end
return result
else
return {}
end
end
return p