Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:VanillaImage

From Vault Hunters Official Wiki
Revision as of 05:42, 16 December 2025 by Mnooseman (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision β†’ (diff)

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

-- Module:MinecraftImage
-- Links to images from minecraft.wiki

local p = {}

function p.item(frame)
    -- Get the image name from the template parameter
    local imageName = frame.args[1] or frame.args.name or ""
    local size = frame.args.size or frame.args[2] or "32px"
    local alt = frame.args.alt or imageName
    local link = frame.args.link or ""
    local prefix = frame.args.prefix or "auto"
    
    -- Remove any file extension if provided
    imageName = imageName:gsub("%.png$", ""):gsub("%.gif$", "")
    
    -- Clean up the image name (replace spaces with underscores)
    imageName = imageName:gsub(" ", "_")
    
    -- Add Invicon_ prefix automatically if not already present
    if prefix == "auto" and not imageName:match("^Invicon_") then
        imageName = "Invicon_" .. imageName
    elseif prefix ~= "auto" and prefix ~= "" then
        imageName = prefix .. imageName
    end
    
    -- Construct the URL to minecraft.wiki
    local imageUrl = "https://minecraft.wiki/w/Special:Redirect/file/" .. mw.uri.encode(imageName .. ".png", "PATH")
    
    -- Make sure size has 'px' suffix
    if not size:match("px$") then
        size = size .. "px"
    end
    
    -- Build the wikitext for external image
    local wikitext = "[" .. imageUrl .. " " .. size .. "]"
    
    -- Wrap in link if specified
    if link ~= "" then
        wikitext = "[[" .. link .. "|" .. wikitext .. "]]"
    end
    
    return wikitext
end

-- Alias 'direct' to 'item' for backwards compatibility
p.direct = p.item

return p