本站文本内容除另有声明外,转载时均必须注明出处,并遵守CC BY-NC-SA 3.0协议。(转载须知)
本站是中文Minecraft Wiki的镜像站,与Mojang Studios、Weird Gloop没有从属关系。(免责声明)
模块:Autovalue infobox
本模块用于为{{Block}}
和{{Item}}
提供自动值行。
用法
infoboxRows
直接在需要插入信息框行的位置添加{{#invoke: autovalue builders | infoboxRows }}
。
该模块从模板接收以下参数:
参数 | 用途 |
---|---|
autovalue-id | 指定目标名称。若不指定,且有指定title 参数,则使用title ,否则使用页面标题。
|
数据类型 | 直接覆盖值输出。若不指定,则使用自动值。 |
block-id | 指定目标方块名称。若不指定,则使用autovalue-id 的值。
|
item-id | 指定目标物品名称。若不指定,则使用autovalue-id 的值。
|
数据类型-id | 指定目标名称。若不指定,则根据属性类型使用block-id 或item-id 的值。
|
autovalue-disabled-fields | 停用特定的值类型。使用, 作为分隔符。适用于旧版本游戏内容的条目,停用在该版本不存在的属性。
|
nocat | 向Module:Autovalue传入nocat 。
|
noblock | 停用与方块相关的自动值。 |
noitem | 停用与物品相关的自动值。 |
noje | 停用与Java版相关的自动值。 |
nobe | 停用与基岩版相关的自动值。 |
依赖项
另见
- 实现
- 主要用途
- Module:Autovalue builders
- Module:Autovalue infobox
- Module:Breaking table
{{Hardness values}}
{{Blast resistance values}}
- 分类
- 数据
local p = {}
local Autovalue = require( [[Module:Autovalue]] )
local Infobox = require( [[Module:Infobox]] )
local valueTypes = mw.loadData('Module:Autovalue/types')
local function HideFlammablePredicate(values)
return (values['flame odds'] == '0'
and values['burn odds'] == '0'
and values['lava flammable'] == '否'
)
end
local valuesConfig = {
['rarity'] = { hide = (function (values)
return values['rarity'] == '常见'
end) },
['creative tab'] = { onlyje = true },
['creative category'] = { onlybe = true },
['flame odds'] = { hide = HideFlammablePredicate },
['burn odds'] = { hide = HideFlammablePredicate },
['lava flammable'] = { hide = HideFlammablePredicate },
['friction'] = { hide = (function (values)
return values['friction'] == '0.6'
end) },
['speed factor'] = { hide = (function (values)
return values['speed factor'] == '1'
end) },
['durability'] = { hide = (function (values)
return values['durability'] == '\'\'无\'\''
end) },
['burn duration'] = { hide = (function (values)
return values['burn duration'] == '\'\'无\'\''
end) },
['food properties'] = { hide = (function (values)
return values['food properties'] == '\'\'无\'\''
end) },
}
local valuesQueueItem = {
'rarity',
'creative tab',
'creative category',
'durability',
'burn duration',
'food properties',
'maxstack',
}
local valuesQueueBlock = {
'breaking tool',
'hardness',
'blast resistance',
'friction',
'speed factor',
'flame odds',
'burn odds',
'lava flammable',
'suffocating',
'redstone conductor',
'replaceable',
'solid',
'push reaction',
'instrument',
'map color',
}
local function hideValue(values, valueType)
if valuesConfig[valueType]
and type(valuesConfig[valueType].hide) == 'function'
and valuesConfig[valueType].hide(values)
then
return true
else
return false
end
end
local function contentToInfoboxRow(label, field)
return mw.getCurrentFrame():expandTemplate { title = 'Infobox row', args = { label = label, field = field }}
end
local function valueToInfoboxRow(values, valueType, fieldAppend)
return contentToInfoboxRow(valueTypes[valueType].title, values[valueType]..(fieldAppend or ''))
end
local function TabsToTabber(tabs)
if #tabs == 1 then
return tabs[1].value
end
if #tabs < 1 then
return ''
end
local stringifyTabs = {}
for i,tab in ipairs( tabs ) do
local label = tab.key
local content = tab.value
table.insert(stringifyTabs, label..'=\n'..content)
end
return f:extensionTag( 'tabber', table.concat( stringifyTabs, '\n|-|\n' ) )
end
-- 去除参数字符串头尾的空格和换行符。
local function StripSpaceAndLineAtBothEnds(str)
return string.gsub(str, '^[%s\n]*(.-)[%s\n]*$', '%1')
end
-- 模板调用此函数。
local function infoboxRows(args, targetId, valuesQueue)
local argNocat = args.nocat
local argNoJE = args.noje
local argNoBE = args.nobe
local argDisabledValueTypes = args['autovalue-disabled-fields'] or ''
local argLastNamedOthersValueTypes = args['autovalue-last-named-others-fields'] or ''
if mw.title.getCurrentTitle():inNamespace('User') then
argNocat = 'a'
end
local values = {}
local categoriesAppend = ''
local disabledValueTypesList = mw.text.split(argDisabledValueTypes, ',')
local disabledValueTypes = {}
local lastNamedOthersValueTypesList = mw.text.split(argLastNamedOthersValueTypes, ',')
local lastNamedOthersValueTypes = {}
local unknownValueTypeOccured = false
local anyValueDisabled = false
for i,value in ipairs( disabledValueTypesList ) do
local valueTypeToDisable = StripSpaceAndLineAtBothEnds( value )
if valueTypeToDisable ~= '' then
if not valueTypes[valueTypeToDisable] then
unknownValueTypeOccured = true
else
disabledValueTypes[ valueTypeToDisable ] = true
anyValueDisabled = true
end
end
end
for i,value in ipairs( lastNamedOthersValueTypesList ) do
local valueTypeToLastNamedOthers = StripSpaceAndLineAtBothEnds( value )
if valueTypeToLastNamedOthers ~= '' then
if not valueTypes[valueTypeToLastNamedOthers] then
unknownValueTypeOccured = true
else
lastNamedOthersValueTypes[ valueTypeToLastNamedOthers ] = true
end
end
end
if anyValueDisabled then
categoriesAppend = categoriesAppend .. '[[Category:停用自动值的页面]]'
end
if unknownValueTypeOccured then
categoriesAppend = categoriesAppend .. '[[Category:未知自动值类型]]'
end
local valueMode = 'infobox'
if argNoJE and argNoBE then
valueMode = 'null mode'
elseif argNoJE then
valueMode = 'onlyBE'
elseif argNoBE then
valueMode = 'onlyJE'
end
for i, currentValueType in ipairs( valuesQueue ) do
if not disabledValueTypes[currentValueType] then
local currentValueTypeConfig = valuesConfig[currentValueType] or {}
if (currentValueTypeConfig.onlyje and argNoJE)
or (currentValueTypeConfig.onlybe and argNoBE)
then
-- Skip.
else
local autovalueArgName = (currentValueType):gsub("% ", "-")
local overrideName
local manualIdName
if currentValueType == 'block id'
or currentValueType == 'item id'
or currentValueType == 'entity id'
then
overrideName = autovalueArgName..'-raw'
manualIdName = autovalueArgName
else
overrideName = autovalueArgName
manualIdName = autovalueArgName..'-id'
end
local overrideValue = args[overrideName]
--[[ unacceptable now
if overrideValue == nil then
if currentValueType == 'breaking tool' then
overrideValue = args['tooltext']
elseif currentValueType == 'redstone conductor' then
overrideValue = args['redstoneconduct']
end
end
]]
local finalValue
if overrideValue ~= nil then
--categoriesAppend = categoriesAppend .. '[[Category:覆写' .. valueTypes[currentValueType].name .. '的页面]]'
categoriesAppend = categoriesAppend .. '[[Category:覆写自动值的页面]]'
finalValue = overrideValue
elseif valueMode == 'null mode' then
finalValue = '?'
--categoriesAppend = categoriesAppend .. '[[Category:缺失' .. valueTypes[currentValueType].name .. ']]'
else
local currentAutovalueId = args[manualIdName] or targetId
finalValue = Autovalue.getValue(currentAutovalueId, currentValueType, valueMode, argNocat, false, lastNamedOthersValueTypes[currentValueType])
if (
(
currentValueType == 'replaceable'
or currentValueType == 'solid'
or currentValueType == 'block id'
or currentValueType == 'item id'
or currentValueType == 'entity id'
)
and string.len(finalValue) > 256
)
or string.len(finalValue) > 2048
then
finalValue = '<div class="collapsible collapsed collapsetoggle-inline">'..finalValue..'</div>'
if currentValueType ~= 'map color' then
finalValue = finalValue..'[[Category:过长的自动值输出]]'
end
end
end
values[currentValueType] = finalValue
end
end
end
if argNocat then
categoriesAppend = ''
end
local infoboxRows = {}
for i, currentValueType in ipairs( valuesQueue ) do
if values[currentValueType] == nil
or hideValue(values, currentValueType)
then
-- Skip.
else
table.insert(infoboxRows, valueToInfoboxRow(values, currentValueType))
end
end
table.insert(infoboxRows, categoriesAppend)
return table.concat(infoboxRows, '\n')
end
function p.infoboxRowsBlock(f)
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = require('Module:ProcessArgs').merge(true)
end
if args['itemframe'] then
args['noje'] = '1'
end
return infoboxRows(
args,
args['autovalue-id'] or args['block-id'] or args['title'] or frame:preprocess('{{#titleparts:{{BASEPAGENAME}}}}'),
valuesQueueBlock)
end
function p.infoboxRowsItem(f)
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = require('Module:ProcessArgs').merge(true)
end
return infoboxRows(
args,
args['autovalue-id'] or args['item-id'] or args['title'] or frame:preprocess('{{#titleparts:{{BASEPAGENAME}}}}'),
valuesQueueItem)
end
function p.infoboxRowsBlockId(f)
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = require('Module:ProcessArgs').merge(true)
end
if args['itemframe'] then
args['noje'] = '1'
end
return infoboxRows(
args,
args['autovalue-id'] or args['block-id'] or args['title'] or frame:preprocess('{{#titleparts:{{BASEPAGENAME}}}}'),
{'block id'})
end
function p.infoboxRowsItemId(f)
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = require('Module:ProcessArgs').merge(true)
end
return infoboxRows(
args,
args['autovalue-id'] or args['item-id'] or args['title'] or frame:preprocess('{{#titleparts:{{BASEPAGENAME}}}}'),
{'item id'})
end
function p.infoboxRowsEntityId(f)
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = require('Module:ProcessArgs').merge(true)
end
if args['itemframe'] then
args['nobe'] = '1'
end
return infoboxRows(
args,
args['autovalue-id'] or args['entity-id'] or args['title'] or frame:preprocess('{{#titleparts:{{BASEPAGENAME}}}}'),
{'entity id'})
end
function p.infoboxRowsEnchantment(f)
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = require('Module:ProcessArgs').merge(true)
end
return infoboxRows(
args,
args['autovalue-id'] or args['enchantment-id'] or args['title'] or frame:preprocess('{{#titleparts:{{BASEPAGENAME}}}}'),
{
--'enchantment category',
'enchantment cost',
'enchantment flag',
'enchantment incompatible',
'enchantment max level',
'enchantment rarity',
'enchantment id',
})
end
return p