本站文本内容除另有声明外,转载时均必须注明出处,并遵守CC BY-NC-SA 3.0协议。(转载须知
本站是中文Minecraft Wiki的镜像站,与Mojang Studios、Weird Gloop没有从属关系。(免责声明

全站通知:

模块:Autovalue infobox

来自我的世界地下城WIKI_BWIKI_哔哩哔哩
跳到导航 跳到搜索

本模块用于为{{Block}}{{Item}}提供自动值行。

用法

infoboxRows

直接在需要插入信息框行的位置添加{{#invoke: autovalue builders | infoboxRows }}

该模块从模板接收以下参数:

参数 用途
autovalue-id 指定目标名称。若不指定,且有指定title参数,则使用title,否则使用页面标题。
数据类型 直接覆盖值输出。若不指定,则使用自动值。
block-id 指定目标方块名称。若不指定,则使用autovalue-id的值。
item-id 指定目标物品名称。若不指定,则使用autovalue-id的值。
数据类型-id 指定目标名称。若不指定,则根据属性类型使用block-iditem-id的值。
autovalue-disabled-fields 停用特定的值类型。使用,作为分隔符。适用于旧版本游戏内容的条目,停用在该版本不存在的属性。
nocat Module:Autovalue传入nocat
noblock 停用与方块相关的自动值。
noitem 停用与物品相关的自动值。
noje 停用与Java版相关的自动值。
nobe 停用与基岩版相关的自动值。

依赖项

另见

实现
主要用途
分类
数据
数据名称 数据模块 缺失值的维护分类
方块ID
block id
Module:Block id values
Module:Block id values BE
Category:缺失方块ID(0)
物品ID
item id
Module:Item id values
Module:Item id values BE
Category:缺失物品ID(2)
实体ID
entity id
Module:Entity id values
Module:Entity id values BE
Category:缺失实体ID(57)
魔咒ID
enchantment id
Module:Enchantment id values
Module:Enchantment id values BE
Category:缺失魔咒ID(0)
状态效果ID
status effect id
Module:Status effect id values
Module:Status effect id values BE
Category:缺失状态效果ID(0)
生物群系ID
biome id
Module:Biome id values
Module:Biome id values BE
Category:缺失生物群系ID(0)
合适挖掘工具
breaking tool
Module:Breaking tool values
Module:Breaking tool values BE
Category:缺失合适挖掘工具(0)
硬度
hardness
Module:Hardness values
Module:Hardness values BE
Category:缺失硬度(0)
爆炸抗性
blast resistance
Module:Blast resistance values
Module:Blast resistance values BE
Category:缺失爆炸抗性(0)
材料
material
Module:Autovalue/material mapping
Module:Material values
Category:缺失材料(0)
基岩版材料
material BE
Module:Autovalue/material BE mapping
Module:Material BE values
Category:缺失基岩版材料(0)
最大堆叠
maxstack
Module:Maxstack values
Module:Maxstack values BE
Category:缺失最大堆叠(0)
稀有度
rarity
Module:Autovalue/rarity mapping
Module:Rarity values
Module:Rarity values BE
创造标签页
creative tab
Module:Autovalue/creative tab mapping
Module:Creative tab values
Category:缺失创造标签页(2)
创造分类
creative category
Module:Autovalue/creative category mapping
Module:Creative category values
Category:缺失创造分类(2)
窒息生物
suffocating
Module:Suffocating values
Module:Suffocating values BE
Category:缺失窒息生物(0)
红石导体
redstone conductor
Module:Redstone conductor values
Module:Redstone conductor values BE
Category:缺失红石导体(0)
可替代
replaceable
Module:Replaceable values
Module:Replaceable values BE
Category:缺失可替代(0)
固体方块
solid
Module:Solid values
Module:Solid values BE
Category:缺失固体方块(0)
引燃几率
flame odds
Module:Flame odds values
Module:Flame odds values BE
Category:缺失引燃几率(0)
烧毁几率
burn odds
Module:Burn odds values
Module:Burn odds values BE
Category:缺失烧毁几率(0)
熔岩可燃性
lava flammable
Module:Lava flammable values
Module:Lava flammable values BE
Category:缺失熔岩可燃性(0)
活塞推动行为
push reaction
Module:Autovalue/push reaction mapping
Module:Push reaction values
Module:Push reaction values BE
Category:缺失活塞推动行为(0)
地图颜色
map color
Module:Autovalue/map color mapping
Module:Map color values
Module:Map color values BE
Category:缺失地图颜色(0)
乐器
instrument
Module:Autovalue/instrument mapping
Module:Instrument values
Module:Instrument values BE
Category:缺失乐器(0)
阻力系数
friction
Module:Friction values
Module:Friction values BE
速度乘数
speed factor
Module:Speed factor values
Module:Speed factor values BE
耐久度
durability
Module:Durability values
Module:Durability values BE
烧炼时间
burn duration
Module:Burn duration values
Module:Burn duration values BE
食物属性
food properties
Module:Food properties values
Module:Food properties values BE
生物类型
mob type
Module:Autovalue/mob type mapping
Module:Mob type values
Category:缺失生物类型(0)
???
mob category
Module:Autovalue/mob category mapping
Module:Mob category values

entity family
Module:Autovalue/entity family mapping
Module:Entity family values
Category:缺失族(0)
种群控制
population control
Module:Autovalue/population control mapping
Module:Population control values
Category:缺失种群控制(0)
魔咒附魔台可用性
enchantment enchanting table applicable
Module:Autovalue/enchantment enchanting table applicable mapping
Module:Autovalue/enchantment enchanting table applicable mapping BE
Module:Enchantment enchanting table applicable values
Module:Enchantment enchanting table applicable values BE
Category:缺失魔咒附魔台可用性(0)
魔咒铁砧可用性
enchantment avnil applicable
Module:Autovalue/enchantment avnil applicable mapping
Module:Autovalue/enchantment avnil applicable mapping BE
Module:Enchantment avnil applicable values
Module:Enchantment avnil applicable values BE
Category:缺失魔咒铁砧可用性(0)
魔咒类别
enchantment category
Module:Autovalue/enchantment category mapping
Module:Enchantment category values
Category:缺失魔咒类别(0)
魔咒附魔等级
enchantment cost
Module:Enchantment cost values
Module:Enchantment cost values BE
Category:缺失魔咒附魔等级(0)
魔咒出现条件
enchantment flag
Module:Autovalue/enchantment flag mapping
Module:Enchantment flag values
Category:缺失魔咒出现条件(0)
魔咒不共存魔咒
enchantment incompatible
Module:Autovalue/enchantment incompatible mapping
Module:Enchantment incompatible values
Category:缺失魔咒不共存魔咒(0)
魔咒最大等级
enchantment max level
Module:Enchantment max level values Category:缺失魔咒最大等级(0)
魔咒稀有度
enchantment rarity
Module:Autovalue/enchantment rarity mapping
Module:Enchantment rarity values
Category:缺失魔咒稀有度(0)

lzh:Module:Autovalue builders

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