Module

BannerFromCommand

From Dogcraft Wiki

No edit summary
No edit summary
Line 28: Line 28:
end]]--
end]]--
args = frame.args
args = frame.args
local alignment = tostring(args.align)
if alignment == nil or alignment == "nil" then
alignment = "bottom"
end
local scaling = tonumber(args.scale)
if scaling == nil or scaling == NaN then
scaling = 1
end
local command = tostring(args.command)
local command = tostring(args.command)
Line 40: Line 50:
     local iterator = string.gmatch(nbt, "{([^}]*)}")
     local iterator = string.gmatch(nbt, "{([^}]*)}")
      
      
     local res = "{{Banner|color=" .. bannercolor
     local opts = {align = alignment, scale = scaling}
    local opts = {}
      
      
     for i = 1, 16 do
     for i = 1, 16 do
Line 57: Line 66:
     opts["pattern" .. i] = guipattern
     opts["pattern" .. i] = guipattern
     opts["patternColor" .. i] = color
     opts["patternColor" .. i] = color
   
    res = res .. "|pattern" .. i .. "=" .. guipattern .. "|patternColor" .. i .. "=" .. color
    
    
     end
     end
      
      
     res = res .. "}}" .. frame:expandTemplate{title="Banner", args=opts} .. nbt
     res = frame:expandTemplate{title="Banner", args=opts}
      
      
return res
return res

Revision as of 17:58, 10 February 2026

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

-- Copyright (c) 2024, XPModder, Dogcraft.net and contributors
-- 
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
-- to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
-- and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
-- 
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
-- 
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- 
-- End license text.

-- A module to parse minecraft give commands for banners
local p = {}

-- The main function called on #invoke via the template
function p.Parse(frame)
    
	local args = {}
	    
	-- get the arguments
	--[[if frame == mw.getCurrentFrame() then
		args = frame:getParent().args
	else
		args = frame.args
	end]]--
	args = frame.args
	
	local alignment = tostring(args.align)
	if alignment == nil or alignment == "nil" then
		alignment = "bottom"
	end
	
	local scaling = tonumber(args.scale)
	if scaling == nil or scaling == NaN then
		scaling = 1
	end
	
	local command = tostring(args.command)
	if command == nil or command == "nil" then
		return "Error! No command given!"
	end
    
    local bannerstart, bannerstop, bannercolor = string.find(command, "%s*(%S*)_banner%s*%[")
    
    local nbt = string.sub(command, bannerstop)
    
    local iterator = string.gmatch(nbt, "{([^}]*)}")
    
    local opts = {align = alignment, scale = scaling}
    
    for i = 1, 16 do
    
    	local part = iterator()
    	if part == nil then
    		break
    	end
    	
    	local patternstart, patternstop, pattern = string.find(part, "pattern:%s*([^%s,}]*)")
    	local guipattern = frame:expandTemplate{title="BannerPatternTranslate", args={"fromNBT", pattern}}
    	
    	local colorstart, colorstop, color = string.find(part, "color:%s*([^%s,}]*)")
    	
    	opts["pattern" .. i] = guipattern
    	opts["patternColor" .. i] = color
    	
    end
    
    res = frame:expandTemplate{title="Banner", args=opts}
    
	return res
    
end

return p
This page was last modified on 10 February 2026, at 17:58. (2 days ago)
Background Valentine's Day Event 2024 by TigerNL