Minecraft Wiki

除另有声明,转载时均必须注明出处若簡繁轉換出錯,請以遊戲內為準请勇于扩充与修正内容有兴趣逛逛我们的微博沟通交流,欢迎到社区专页需要协助,请在告示板留言

了解更多

Minecraft Wiki
无编辑摘要
无编辑摘要
(未显示4个用户的25个中间版本)
第5行: 第5行:
 
local other = mw.loadData( 'Module:Autolink/Other' )
 
local other = mw.loadData( 'Module:Autolink/Other' )
 
local exclusive = mw.loadData( 'Module:Autolink/Exclusive' )
 
local exclusive = mw.loadData( 'Module:Autolink/Exclusive' )
  +
local earth = mw.loadData( 'Module:Autolink/Earth' )
 
local dungeons = mw.loadData( 'Module:Autolink/Dungeons' )
 
local dungeons = mw.loadData( 'Module:Autolink/Dungeons' )
  +
local colors = {
local colors = { 'white ', 'orange ', 'magenta ', 'light blue ', 'yellow ', 'lime ', 'pink ', 'gray ', 'light gray ', 'cyan ', 'purple ', 'blue ', 'brown ', 'green ', 'red ', 'black ', 'silver ' }
 
  +
['black '] = '黑色',
local colorc = { '白色', '橙色', '品红色', '淡蓝色', '黄色', '黄绿色', '粉红色', '灰色', '淡灰色', '青色', '紫色', '蓝色', '棕色', '绿色', '红色', '黑色', '淡灰色'}
 
  +
['blue '] = '蓝色',
  +
['brown '] = '棕色',
  +
['cyan '] = '青色',
  +
['gray '] = '灰色',
  +
['green '] = '绿色',
  +
['light blue '] = '淡蓝色',
  +
['light gray '] = '淡灰色',
  +
['lime '] = '黄绿色',
  +
['magenta '] = '品红色',
  +
['orange '] = '橙色',
  +
['pink '] = '粉红色',
  +
['purple '] = '紫色',
  +
['red '] = '红色',
  +
['silver '] = '淡灰色',
  +
['white '] = '白色',
  +
['yellow '] = '黄色',
  +
}
   
local function Set (list)
+
local function Set(list)
 
local set = {}
 
local set = {}
 
for _, l in ipairs(list) do set[l] = true end
 
for _, l in ipairs(list) do set[l] = true end
第15行: 第33行:
 
end
 
end
   
local coloredItems = Set { 'firework star', 'hardened clay', 'stained clay', 'banner', 'carpet', 'concrete', 'concrete powder', 'glazed terracotta', 'terracotta', 'shield', 'shulker box', 'stained glass', 'stained glass pane', 'wool', 'bed', 'hardened glass', 'hardened stained glass', 'balloon', 'glow stick', 'hardened glass pane', 'hardened glass', 'sparkler' }
+
local coloredItems = Set { 'firework star', 'hardened clay', 'stained clay', 'banner', 'carpet', 'concrete',
  +
'concrete powder', 'glazed terracotta', 'terracotta', 'shield', 'shulker box', 'stained glass',
  +
'stained glass pane', 'wool', 'bed', 'hardened glass', 'hardened stained glass', 'balloon',
  +
'glow stick', 'hardened glass pane', 'hardened glass', 'sparkler', 'candle' }
   
 
-- used by templates, called via #invoke
 
-- used by templates, called via #invoke
 
function p.link( f )
 
function p.link( f )
 
local args = f
 
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
 
args = require( 'Module:ProcessArgs' ).merge( true )
 
args = require( 'Module:ProcessArgs' ).merge( true )
 
end
 
end
第26行: 第47行:
 
end
 
end
   
function p.invlink( str , mode, type )
+
function p.invlink( str, mode, type )
local arg = string.lower(string.gsub(str , "-" , " "))
+
local arg = str:gsub('-', ' '):lower()
 
-- check for spawn egg
 
-- check for spawn egg
if string.find(arg, ' spawn egg', -10, true) then
+
if arg:find(' spawn egg$') then
local mob = other['EntitySprite'][string.sub(arg, 0, -11)]
+
local mob = other['EntitySprite'][arg:sub(0, -11)]
 
if mob == nil then
 
if mob == nil then
error('missing mob entry: ' .. string.sub(arg, 0, -11))
+
error('missing mob entry: ' .. arg:sub(0, -11))
 
end
 
end
index = string.find(mob, '|', 0, true)
+
local index = mob:find('|')
 
if index then
 
if index then
mob = string.sub(mob, index+1)
+
mob = mob:sub(index + 1)
 
end
 
end
 
return p.mode('刷怪蛋|' .. mob .. '刷怪蛋', mode)
 
return p.mode('刷怪蛋|' .. mob .. '刷怪蛋', mode)
 
end
 
end
  +
 
 
local be
 
local be
 
local lce
 
local lce
-- check for version postfix
+
-- check for version suffix
if string.sub(arg, -3) == ' pe' or string.sub(arg, -3) == ' be' then
+
if arg:find(' pe$') or arg:find(' be$') then
 
be = 1
 
be = 1
arg = string.sub(arg, 0, -4)
+
arg = arg:sub(0, -4)
 
end
 
end
if string.sub(arg, -4) == ' lce' then
+
if arg:find(' lce$') then
 
lce = 1
 
lce = 1
arg = string.sub(arg, 0, -5)
+
arg = arg:sub(0, -5)
 
end
 
end
   
-- check for 'spawn'
+
-- check for 'spawn'
if string.match(arg, '^spawn ') then
+
if arg:find('^spawn ') then
local mob = other['EntitySprite'][string.sub(arg, 7)]
+
local mob = other['EntitySprite'][arg:sub(7)]
 
if mob then
 
if mob then
index = string.find(mob, '|', 0, true)
+
local index = mob:find('|')
 
if index then
 
if index then
mob = string.sub(mob, index+1)
+
mob = mob:sub(index + 1)
 
end
 
end
 
local name = '刷怪蛋|生成' .. mob
 
local name = '刷怪蛋|生成' .. mob
第74行: 第95行:
 
-- check for color prefix
 
-- check for color prefix
 
local color
 
local color
for i, c in ipairs( colors ) do
+
for k, v in pairs( colors ) do
if string.find(arg, c) == 1 then
+
if arg:find(k) == 1 then
local item = string.sub(arg, string.len(c)+1)
+
local i = arg:sub(k:len() + 1)
if coloredItems[item] then
+
if coloredItems[i] then
color = colorc[i]
+
color = v
arg = item
+
arg = i
  +
break
 
end
 
end
end
+
end
 
end
 
end
 
local result
 
local result
 
if type and other[type] then
 
if type and other[type] then
 
result = other[type][arg]
 
result = other[type][arg]
 
end
  +
if result == nil and type and earth[type] then
  +
result = earth[type][arg]
 
end
  +
if result == nil and type and dungeons[type] then
 
result = dungeons[type][arg]
  +
end
  +
if result == nil and type and type == 'ItemSprite' then
  +
result = item[arg]
 
end
 
end
 
if result == nil then
 
if result == nil then
 
result = block[arg] or item[arg]
 
result = block[arg] or item[arg]
end
+
end
if result == nil and string.sub(arg, -1) == 's' then
+
if result == nil and arg:sub(-1) == 's' then
local singular = string.sub(arg, 0, -2)
+
local singular = arg:sub(0, -2)
 
result = block[singular] or item[singular]
 
result = block[singular] or item[singular]
 
end
 
end
 
if result == nil then
 
if result == nil then
 
for _, list in pairs( other ) do
 
for _, list in pairs( other ) do
  +
result = list[arg]
  +
if result then
  +
break
  +
end
  +
end
  +
end
 
if result == nil then
  +
for _, list in pairs( dungeons ) do
 
result = list[arg]
 
result = list[arg]
 
if result then
 
if result then
第106行: 第145行:
 
result = exclusive[arg] or str
 
result = exclusive[arg] or str
 
end
 
end
  +
 
 
if color then
 
if color then
result = result .. '|' .. color .. result
+
result = result .. '|' .. color .. result
 
end
 
end
   
第121行: 第160行:
 
end
 
end
   
function p.mode( str , mode , postfix )
+
function p.mode( str, mode, suffix )
if postfix then
+
if suffix then
if string.find(str, '|', 0, true) then
+
if str:find('|') then
str = str .. postfix
+
str = str .. suffix
else
+
else
str = str .. '|' .. str .. postfix
+
str = str .. '|' .. str .. suffix
end
+
end
 
end
 
end
index = string.find(str, '|', 0, true)
+
local index = str:find('|')
 
-- return the translated part
 
-- return the translated part
 
if index then
 
if index then
if mode == 'nolink' then
+
if mode == 'nolink' then
return string.sub(str, index+1)
+
return str:sub(index + 1)
 
end
 
end
 
-- return the page link part
 
-- return the page link part
 
if mode == 'linkonly' then
 
if mode == 'linkonly' then
return string.sub(str, 1 , index-1)
+
return str:sub(1, index - 1)
 
end
 
end
 
end
 
end
第146行: 第185行:
 
function p.list( f )
 
function p.list( f )
 
local args = f
 
local args = f
if f == mw.getCurrentFrame() then
+
if f == mw.getCurrentFrame() then
 
args = require( 'Module:ProcessArgs' ).merge( true )
 
args = require( 'Module:ProcessArgs' ).merge( true )
 
end
 
end
 
local type = args[1]
 
local type = args[1]
type = string.lower(type)
+
type = type:lower()
local sprite = nil
+
local sprite = nil
local list = nil
+
local list = nil
 
if type == 'block' then
 
if type == 'block' then
 
list = block
 
list = block
sprite = 'BlockSprite'
+
sprite = 'BlockSprite'
 
elseif type == 'item' then
end
 
if type == 'item' then
 
 
list = item
 
list = item
sprite = 'ItemSprite'
+
sprite = 'ItemSprite'
 
elseif type == 'entity' then
 
list = other['EntitySprite']
 
sprite = 'EntitySprite'
 
elseif type == 'dungeonsitem' then
 
list = dungeons['DungeonsItemSprite']
 
sprite = 'DungeonsItemSprite'
 
elseif type == 'dungeonsentity' then
 
list = dungeons['DungeonsEntitySprite']
  +
sprite = 'DungeonsEntitySprite'
 
elseif type == 'dungeonsenchantment' then
 
list = dungeons['DungeonsEnchantmentSprite']
  +
sprite = 'DungeonsEnchantmentSprite'
 
elseif type == 'dungeonslevel' then
 
list = dungeons['DungeonsLevelSprite']
 
sprite = 'DungeonsLevelSprite'
 
end
 
end
if type == 'entity' then
 
list = other['EntitySprite']
 
sprite = 'EntitySprite'
 
end
 
if type == 'melee' then
 
list = dungeons['MeleeSprite']
 
sprite = 'DungeonsItemSprite'
 
end
 
if type == 'ranged' then
 
list = dungeons['RangedSprite']
 
sprite = 'DungeonsItemSprite'
 
end
 
if type == 'armor' then
 
list = dungeons['ArmorSprite']
 
sprite = 'DungeonsItemSprite'
 
end
 
if type == 'artifact' then
 
list = dungeons['ArtifactSprite']
 
sprite = 'DungeonsItemSprite'
 
end
 
if type == 'cape' then
 
list = dungeons['CapeSprite']
 
sprite = 'DungeonsItemSprite'
 
end
 
if type == 'pet' then
 
list = dungeons['PetSprite']
 
sprite = 'DungeonsItemSprite'
 
end
 
if type == 'consumable' then
 
list = dungeons['ConsumableSprite']
 
sprite = 'DungeonsItemSprite'
 
end
 
if type == 'dungeonsmob' then
 
list = dungeons['MobSprite']
 
sprite = 'EntitySprite'
 
end
 
if type == 'dungeonsenchantment' then
 
list = dungeons['EnchantmentSprite']
 
sprite = 'DungeonsEnchantmentSprite'
 
end
 
if type == 'dungeonslevel' then
 
list = dungeons['LevelSprite']
 
sprite = 'DungeonsLevelSprite'
 
end
 
 
if list == nil then
 
if list == nil then
 
return ''
 
return ''
 
end
 
end
   
local spriteids = mw.loadData( 'Module:' .. sprite ).ids
+
local spriteids = mw.loadData( 'Module:' .. sprite ).ids
   
 
local result = ''
 
local result = ''
 
local t = {}
 
local t = {}
  +
 
for k,_ in pairs(list) do
+
for k, _ in pairs(list) do
 
table.insert(t, k)
 
table.insert(t, k)
 
end
 
end
  +
 
 
table.sort(t)
 
table.sort(t)
   
第223行: 第232行:
 
local count = 0
 
local count = 0
   
local frame = mw.getCurrentFrame()
+
local frame = mw.getCurrentFrame()
  +
 
local table = nil
+
local itemlist = nil
 
local header = mw.html.create('tr')
 
local header = mw.html.create('tr')
header:tag('th'):wikitext('图标')
+
header:tag('th'):wikitext('图标')
 
header:tag('th'):wikitext('英文名称')
 
header:tag('th'):wikitext('英文名称')
 
header:tag('th'):wikitext('中文名称')
 
header:tag('th'):wikitext('中文名称')
  +
 
for _,v in ipairs(t) do
+
for _, v in ipairs(t) do
if count == 0 then
+
if count == 0 then
if table ~= nil then
+
if itemlist ~= nil then
result = result .. tostring(table)
+
result = result .. tostring(itemlist)
 
end
 
end
  +
itemlist = mw.html.create('table')
table = mw.html.create('table'):attr('align', 'left'):css('float', 'left'):css('margin', '2px'):css('border', '1px solid silver'):css('text-align', 'center'):css('background-color', '#fff'):node(header)
 
  +
:addClass('data-table')
  +
:node(header)
 
end
 
end
  +
 
 
local row = mw.html.create('tr')
 
local row = mw.html.create('tr')
if spriteids[v] or spriteids[mw.ustring.lower( v ):gsub( '[%s%+]', '-' )] then
+
if spriteids[v] or spriteids[mw.ustring.lower( v ):gsub( '[%s%+]', '-' )] then
row:tag('td'):wikitext(frame:preprocess( '{{' .. sprite .. '|' .. v .. '}}' ))
+
row:tag('td'):wikitext(frame:expandTemplate{ title = sprite, args = { v } })
else
+
else
 
row:tag('td')
 
row:tag('td')
end
+
end
  +
local words = {}
row:tag('td'):wikitext((v:gsub('(%l)(%w*)', function(a,b) return a:upper()..b end)))
 
  +
v:gsub('[^%s]+', function(w) table.insert(words, w) end)
  +
for k, w in ipairs(words) do
  +
if w ~= 'of' and w ~= 'or' and w ~= 'o\'' then
 
words[k] = w:gsub('(%l)(.+)', function(a, b) return a:upper() .. b end)
  +
end
  +
end
  +
row:tag('td'):wikitext(tostring(table.concat(words, ' ')))
 
row:tag('td'):wikitext(p.mode(list[v], 'nolink'))
 
row:tag('td'):wikitext(p.mode(list[v], 'nolink'))
table:node(row)
+
itemlist:node(row)
 
count = count + 1
 
count = count + 1
 
if count == limit then
 
if count == limit then
第253行: 第271行:
 
end
 
end
 
end
 
end
  +
 
result = result .. tostring(table)
+
result = result .. tostring(itemlist)
 
return result
 
return result
 
end
 
end

2021年8月5日 (四) 07:19的版本

Autolink,即自动链接,用于给模板的参数中的英文转换为对应的中文并显示出来,正如Module:Reverselink能将中文参数转换为英文并提供给模板以显示图片。

本模块主要用于:

数据模块

本模块采用以下子页面中的数据:

这些页面中的每条数据可以按下面2种形式中的任意一种来组织:

  • ['注册名'] = '输出内容',
    • 只包含输出内容,不包含任何flag,所有flag均采用其默认值。
  • ['注册名'] = { '输出内容', flag1, flag2, ... },
    • 指定用于控制特殊行为的flag。各flag的顺序及其含义见grabFlags函数中的定义,目前定义如下:
      • flag1,引用名hideinlist:布尔值,用于控制对应项目是否不在标准译名列表中出现。false为出现,true为不出现,默认值false。
      • flag2,引用名groups:字符串(逗号分隔),用于按组显示特定内容。默认为main(若需要指定其他组,main则默认不包含,需手动填写)。

依赖项


语言
local p = {}

local block = mw.loadData( 'Module:Autolink/Block' )
local item = mw.loadData( 'Module:Autolink/Item' )
local other = mw.loadData( 'Module:Autolink/Other' )
local exclusive = mw.loadData( 'Module:Autolink/Exclusive' )
local earth = mw.loadData( 'Module:Autolink/Earth' )
local dungeons = mw.loadData( 'Module:Autolink/Dungeons' )
local colors = {
	['black '] = '黑色',
	['blue '] = '蓝色',
	['brown '] = '棕色',
	['cyan '] = '青色',
	['gray '] = '灰色',
	['green '] = '绿色',
	['light blue '] = '淡蓝色',
	['light gray '] = '淡灰色',
	['lime '] = '黄绿色',
	['magenta '] = '品红色',
	['orange '] = '橙色',
	['pink '] = '粉红色',
	['purple '] = '紫色',
	['red '] = '红色',
	['silver '] = '淡灰色',
	['white '] = '白色',
	['yellow '] = '黄色',
}

local function Set(list)
	local set = {}
	for _, l in ipairs(list) do set[l] = true end
	return set
end

local coloredItems = Set { 'firework star', 'hardened clay', 'stained clay', 'banner', 'carpet', 'concrete',
	'concrete powder', 'glazed terracotta', 'terracotta', 'shield', 'shulker box', 'stained glass',
	'stained glass pane', 'wool', 'bed', 'hardened glass', 'hardened stained glass', 'balloon',
	'glow stick', 'hardened glass pane', 'hardened glass', 'sparkler', 'candle' }

-- used by templates, called via #invoke
function p.link( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs' ).merge( true )
	end
	return p.invlink( args[1] , args[2] , args[3] )
end

function p.invlink( str, mode, type )
	local arg = str:gsub('-', ' '):lower()
	-- check for spawn egg
	if arg:find(' spawn egg$') then
		local mob = other['EntitySprite'][arg:sub(0, -11)]
		if mob == nil then
			error('missing mob entry: ' .. arg:sub(0, -11))
		end
		local index = mob:find('|')
		if index then
			mob = mob:sub(index + 1)
		end
		return p.mode('刷怪蛋|' .. mob .. '刷怪蛋', mode)
	end

	local be
	local lce
	-- check for version suffix
	if arg:find(' pe$') or arg:find(' be$') then
		be = 1
		arg = arg:sub(0, -4)
	end
	if arg:find(' lce$') then
		lce = 1
		arg = arg:sub(0, -5)
	end

	-- check for 'spawn'
	if arg:find('^spawn ') then
		local mob = other['EntitySprite'][arg:sub(7)]
		if mob then
			local index = mob:find('|')
			if index then
				mob = mob:sub(index + 1)
			end
			local name = '刷怪蛋|生成' .. mob
			if be then
				return p.mode(name, mode, '(基岩版)')
			end
			if lce then
				return p.mode(name, mode, '(原主机版)')
			end
			return p.mode(name, mode)
		end
	end

	-- check for color prefix
	local color
	for k, v in pairs( colors ) do
		if arg:find(k) == 1 then
			local i = arg:sub(k:len() + 1)
			if coloredItems[i] then
				color = v
				arg = i
				break
			end
		end
	end
	local result
	if type and other[type] then
		result = other[type][arg]
	end
	if result == nil and type and earth[type] then
		result = earth[type][arg]
	end
	if result == nil and type and dungeons[type] then
		result = dungeons[type][arg]
	end
	if result == nil and type and type == 'ItemSprite' then
		result = item[arg]
	end
	if result == nil then
		result = block[arg] or item[arg]
	end
	if result == nil and arg:sub(-1) == 's' then
		local singular = arg:sub(0, -2)
		result = block[singular] or item[singular]
	end
	if result == nil then
		for _, list in pairs( other ) do
			result = list[arg]
			if result then
				break
			end
		end
	end
	if result == nil then
		for _, list in pairs( dungeons ) do
			result = list[arg]
			if result then
				break
			end
		end
	end

	if result == nil then
		result = exclusive[arg] or str
	end

	if color then
		result = result .. '|' .. color .. result
	end

	if be then
		return p.mode(result, mode, '(基岩版)')
	end
	if lce then
		return p.mode(result, mode, '(原主机版)')
	end

	return p.mode(result, mode)
end

function p.mode( str, mode, suffix )
	if suffix then
		if str:find('|') then
			str = str .. suffix
		else
			str = str .. '|' .. str .. suffix
		end
	end
	local index = str:find('|')
	-- return the translated part
	if index then
		if mode == 'nolink' then
		  return str:sub(index + 1)
		end
		-- return the page link part
		if mode == 'linkonly' then
			return str:sub(1, index - 1)
		end
	end
	return str
end

-- list out all entries with the type
function p.list( f )
	local args = f
	if f == mw.getCurrentFrame() then
		args = require( 'Module:ProcessArgs' ).merge( true )
	end
	local type = args[1]
	type = type:lower()
	local sprite = nil
	local list = nil
	if type == 'block' then
		list = block
		sprite = 'BlockSprite'
	elseif type == 'item' then
		list = item
		sprite = 'ItemSprite'
	elseif type == 'entity' then
		list = other['EntitySprite']
		sprite = 'EntitySprite'
	elseif type == 'dungeonsitem' then
		list = dungeons['DungeonsItemSprite']
		sprite = 'DungeonsItemSprite'
	elseif type == 'dungeonsentity' then
		list = dungeons['DungeonsEntitySprite']
		sprite = 'DungeonsEntitySprite'
	elseif type == 'dungeonsenchantment' then
		list = dungeons['DungeonsEnchantmentSprite']
		sprite = 'DungeonsEnchantmentSprite'
	elseif type == 'dungeonslevel' then
		list = dungeons['DungeonsLevelSprite']
		sprite = 'DungeonsLevelSprite'
	end
	if list == nil then
		return ''
	end

	local spriteids = mw.loadData( 'Module:' .. sprite ).ids

	local result = ''
	local t = {}

	for k, _ in pairs(list) do
		table.insert(t, k)
	end

	table.sort(t)

	local limit = 50
	local count = 0

	local frame = mw.getCurrentFrame()

	local itemlist = nil
	local header = mw.html.create('tr')
	header:tag('th'):wikitext('图标')
	header:tag('th'):wikitext('英文名称')
	header:tag('th'):wikitext('中文名称')

	for _, v in ipairs(t) do
		if count == 0 then
			if itemlist ~= nil then
				result = result .. tostring(itemlist)
			end
			itemlist = mw.html.create('table')
				:addClass('data-table')
				:node(header)
		end

		local row = mw.html.create('tr')
		if spriteids[v] or spriteids[mw.ustring.lower( v ):gsub( '[%s%+]', '-' )] then
			row:tag('td'):wikitext(frame:expandTemplate{ title = sprite, args = { v } })
		else
			row:tag('td')
		end
		local words = {}
		v:gsub('[^%s]+', function(w) table.insert(words, w) end)
		for k, w in ipairs(words) do
			if w ~= 'of' and w ~= 'or' and w ~= 'o\'' then
				words[k] = w:gsub('(%l)(.+)', function(a, b) return a:upper() .. b end)
			end
		end
		row:tag('td'):wikitext(tostring(table.concat(words, ' ')))
		row:tag('td'):wikitext(p.mode(list[v], 'nolink'))
		itemlist:node(row)
		count = count + 1
		if count == limit then
			count = 0
		end
	end

	result = result .. tostring(itemlist)
	return result
end

return p