- 致编者:请牢记我们的域名wiki.mcbe-dev.net!
- 致编者:欢迎加入本Wiki的官方交流QQ群或Discord服务器!
- 基岩版1.19.31现已发布!(了解更多)
- Inner Core现已支持Xbox模组联机!(了解更多)
- 如果您是第一次来到本Wiki,欢迎注册一个账户
- 点击顶部的“编辑”或“编辑源代码”按钮即可编辑当前页面
- 请知悉:在不登录时也可以编辑和新建页面,但是您当前的IP地址会记录在编辑历史中
Module:GameTag
来自Minecraft基岩版开发Wiki
local p = {}
local IDInfo = require('Module:IDInfo')
local getSprite = require('Module:Sprite').link
function p.getTagContent(tag, link, mode)
local data = mw.text.jsonDecode(mw.title.makeTitle('Data', 'GameTag/TagContent'):getContent() or '{}')
if not (tag and data[tag]) then
return nil
end
local result = {}
if mode == 'list:id' or mode == 'table' or mode == nil then
for _, object in pairs(data[tag]) do
for ID in pairs(object) do
table.insert(result, ID)
end
end
table.sort(result)
if mode == 'list:id' then
return '* <code>' .. table.concat(result, '</code>\n* <code>') .. '</code>'
else
return result
end
elseif mode == 'list:sprite' then
for objectType, object in pairs(data[tag]) do
for _, name in pairs(object) do
if type(name) == 'table' then
for _, _name in ipairs(name) do
table.insert(
result,
(getSprite { [1] = _name, data = objectType .. 'Sprite', text = _name, link = link })
)
end
elseif type(name) == 'string' then
table.insert(
result,
(getSprite { [1] = name, data = objectType .. 'Sprite', text = name, link = link })
)
end
end
end
table.sort(
result,
function(a, b)
return (string.match(a, '<span class="sprite%-text">(.-)</span>') or '') <
(string.match(b, '<span class="sprite%-text">(.-)</span>') or '')
end
)
return '* ' .. table.concat(result, '\n* ')
end
end
function p.main(f)
local args = require('Module:Arguments').getArgs(f)
local mode = mw.ustring.lower(args.mode)
if mode == 'tags' then
local objectType = IDInfo.getObjectType(args.type)
if objectType == 'Block' or objectType == 'Item' then
local identifier, data = IDInfo.getIdentifier(args.id, true)
return mw.title.makeTitle('Data', objectType .. '/' .. identifier).exists
and ('* <code>' .. table.concat(IDInfo.getTags(objectType, identifier, args.datavalue or data), '</code>\n* <code>') .. '</code>')
or mw.ustring.format('[[Category:缺失标识符信息的页面]]Error: Page [[Data:%s/%s]] does not exist.', objectType, identifier)
end
elseif mode == 'list:id' or mode == 'list:sprite' then
return p.getTagContent(args.tag, args.link, mode)
end
return nil
end
return p