本站文本内容除另有声明外,转载时均必须注明出处,并遵守CC BY-NC-SA 3.0协议。(转载须知)
本站是中文Minecraft Wiki的镜像站,与Mojang Studios、Weird Gloop没有从属关系。(免责声明)
全站通知:
模块:Autovalue builders
刷
历
编
跳到导航
跳到搜索
本模块用于为挖掘、爆炸、创造模式物品栏、火、窒息、活塞、音符盒、地图等条目提供自动值项目表。
用法
依赖项
另见
- 实现
- 主要用途
- Module:Autovalue builders
- Module:Autovalue infobox
- Module:Breaking table
{{Hardness values}}
{{Blast resistance values}}
- 分类
- 数据
local p = {}
local Autovalue = require( [[Module:Autovalue]] )
local ProcessArgs = require( [[Module:ProcessArgs]] )
function p.allGroups()
local groups = mw.loadData('Module:Autovalue/groups')
local lines = {}
table.insert(lines, '{| class="wikitable"')
table.insert(lines, '|+ 集合')
table.insert(lines, '! 集合名称')
table.insert(lines, '! 包含的项目')
for k, v in pairs( groups ) do
table.insert(lines, '|-')
table.insert(lines, '| [[' .. k .. ']]')
local codes = {}
for i, str in ipairs( v ) do
if str:find('^[a-z0-9_]+$') then
table.insert(codes, '<code>' .. str .. '</code>')
else
table.insert(codes, '<code>[[' .. str .. ']]</code>')
end
end
table.insert(lines, '| ' .. table.concat(codes))
end
table.insert(lines, '|}')
return table.concat(lines, '\n')
end
local function tableKeys(targetTable)
local entries = {}
for k, v in pairs( targetTable ) do
table.insert(entries, k)
end
return entries
end
local function tableValues(targetTable)
local entries = {}
for k, v in pairs( targetTable ) do
table.insert(entries, v)
end
return entries
end
local function joinObjectTable(...)
local entries = {}
for i = 1, select('#', ... ) do
local t = select(i, ... )
for k, v in pairs( t ) do
entries[k] = v
end
end
return entries
end
local function joinArrayTable(...)
local entries = {}
for i = 1, select('#', ... ) do
local t = select(i, ... )
for i, v in ipairs( t ) do
table.insert(entries, v)
end
end
return entries
end
local function arrayTableDuplicate(targetTable)
local entries = {}
local seenValues = {}
for i, v in ipairs( targetTable ) do
if not seenValues[v] then
seenValues[v] = true
table.insert(entries, v)
end
end
return entries
end
function p.allEnrties(name)
return arrayTableDuplicate(joinArrayTable(
tableKeys(mw.loadData(name)),
tableKeys(mw.loadData(name..' BE'))
))
end
local beExtraBlocks = {
'下界反应核',
'发光的黑曜石',
'切石机(MATTIS)',
'reserved6',
'客户端请求占位符方块',
'数据更新方块',
'未知方块',
'隐形基岩',
'允许方块',
'拒绝方块',
'边界',
'相机',
'红色火把',
'绿色火把',
'蓝色火把',
'紫色火把',
'元素',
'强化玻璃',
'染色强化玻璃',
'强化玻璃板',
'染色强化玻璃板',
'元素构造器',
'化合物创建器',
'实验台',
'材料分解器',
'加热块',
'水下火把',
'黑板',
}
local beExtraItems = {
'荧光棒',
'相片',
'公文包',
'冰弹',
'漂白剂',
'气球',
'烟花棒',
'超级肥料',
'化合物',
'药物',
'生成NPC',
'生成智能体',
}
local function allBlocks()
return arrayTableDuplicate(joinArrayTable(
tableKeys(mw.loadData('Module:Block id values')),
beExtraBlocks
))
end
local function allItems()
return arrayTableDuplicate(joinArrayTable(
tableKeys(mw.loadData('Module:Item id values')),
beExtraBlocks,
beExtraItems
))
end
local function allNames()
return arrayTableDuplicate(joinArrayTable(
tableKeys(mw.loadData('Module:Autovalue/groups')),
tableKeys(mw.loadData('Module:Block id values')),
tableKeys(mw.loadData('Module:Item id values')),
beExtraBlocks,
beExtraItems
))
end
function p.knownName(name)
local allNamesTable = allNames()
for i, v in ipairs(allNamesTable) do
if name == v then
return true
end
end
return false
end
function p.knownBlockName(name)
local allNamesTable = arrayTableDuplicate(joinArrayTable(
tableKeys(mw.loadData('Module:Autovalue/groups')),
tableKeys(mw.loadData('Module:Block id values')),
beExtraBlocks
))
for i, v in ipairs(allNamesTable) do
if name == v then
return true
end
end
return false
end
function p.allBlocks(f)
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = ProcessArgs.merge(true)
end
local argJoin = args['join'] or ', '
--return table.concat(p.allEnrties('Module:Block id values'), argJoin)
return table.concat(allBlocks(), argJoin)
end
function p.allItems(f)
local args = f
local frame = mw.getCurrentFrame()
if f == frame then
args = ProcessArgs.merge(true)
end
local argJoin = args['join'] or ','
--return table.concat(p.allEnrties('Module:Item id values'), argJoin)
return table.concat(allItems(), argJoin)
end
function p.blastResistanceTable(f)
local argNocat = false
--local entries = p.allEnrties('Module:Block id values')
local entries = tableKeys(mw.loadData('Module:Block id values'))
local rows = {}
for i, v in ipairs( entries ) do
table.insert(rows, {
name = v,
rawValue = Autovalue.getRawValue(v, 'blast resistance', false) or Autovalue.getRawValue(v, 'blast resistance', true) or -1,
readsValue = Autovalue.getValue(v, 'blast resistance', 'content', argNocat, false, false),
only = nil,
})
end
table.sort(rows, function(r1, r2)
return r1.rawValue > r2.rawValue
end)
local resultTable = {
' {| class="wikitable collapsible sortable collapsed" data-sort-type="number" data-description="方块的爆炸抗性"',
'! 方块',
'! 爆炸抗性',
}
for i, row in ipairs( rows ) do
local blocklink, spriteCat = require( [[Module:Sprite]] ).link({
require( [[Module:Reverselink]] ).xlink(row.name),
['data'] = 'BlockSprite'
})
local only = ''
if row.only then
only = mw.getCurrentFrame():expandTemplate { title = 'Only', args = { row.only } }
end
table.insert(resultTable, '|-')
table.insert(resultTable, '| '..blocklink..only..spriteCat)
table.insert(resultTable, '| data-sort-value="'..row.rawValue..'" | '..row.readsValue)
end
table.insert(resultTable, '|}')
return table.concat(resultTable, '\n')
end
function p.reverseautolink()
local generatedLinks = {}
local links = joinObjectTable(
mw.loadData('Module:Autolink/Block'),
mw.loadData('Module:Autolink/Item')
)
for k, v in pairs( links ) do
local name
if type(v) == 'table' then
name = v[1]
else
name = v
end
local point = string.find(name, '|', 1)
if point ~= nil then
name = string.sub(name, point + 1, string.len(name))
end
generatedLinks[name] = string.gsub(k, "%f[%a].", string.upper)
end
return generatedLinks
end
function p.missingReverselink()
local Reverselink = require( [[Module:Reverselink]] )
local allNames = arrayTableDuplicate(joinArrayTable(
tableKeys(mw.loadData('Module:Block id values')),
tableKeys(mw.loadData('Module:Item id values')),
beExtraBlocks,
beExtraItems
))
local noRlinkNames = {}
local noRlinkNoIdeaNames = {}
local rautolinks = p.reverseautolink()
for i, v in ipairs( allNames ) do
local rlinkName = Reverselink.xlink(v)
if v == rlinkName then
local possiblelink = rautolinks[v]
if possiblelink then
table.insert(noRlinkNames, '\t[\''..v..'\'] = \''..possiblelink..'\',')
else
table.insert(noRlinkNoIdeaNames, '\t[\''..v..'\'] = \''..'??????'..'\',')
end
end
end
return '<pre>'..table.concat(noRlinkNames, '\n')..'</pre><pre>'..table.concat(noRlinkNoIdeaNames, '\n')..'</pre>'
end
return p