VOOZH about

URL: https://minecraft.wiki/w/Module:Get_spawn_info

⇱ Module:Get spawn info – Minecraft Wiki


Module:Get spawn info

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[view] [edit] [history] [purge]Jump to code ↴

Implements {{Mob spawn table}}

[view] [edit] [history] [purge]The above documentation is transcluded from Module:Get spawn info/doc.
-- Portions sourced from https://oldschool.runescape.wiki/w/Module:Get_drop_info 
-- Module based on https://minecraft.wiki/w/Module:Get_drop_info
require('strict')
localp={}
localspriteFile=require("Module:SpriteFile")
-- Function for creating tooltips in table headers
localfunctiontooltip(text,title)
returntostring(mw.html.create('span')
:addClass('explain')
:attr('title',title)
:wikitext(text)
:allDone())
end
-- Receives rows with data, returns the table
localfunctionmakeSpawnTable(data)
localret
if#data>0then
ret=mw.html.create('table')
:addClass('wikitable sortable')
:css('text-align','center')
:tag('tr')
:tag('th')
:wikitext('Category: '..data.category)
:done()
:tag('th')
:wikitext('<i>Java Edition</i>')
:attr('colspan',3)
:done()
:tag('th')
:wikitext('<i>Bedrock Edition</i>')
:attr('colspan',2)
:done()
:done()
:tag('tr')
:tag('th')
:wikitext('Spawn area')
:done()
:tag('th')
:wikitext(tooltip('Spawn weight','Weight relative to other spawn entries in the category'))
:done()
:tag('th')
:wikitext('Spawn chance')
:done()
:tag('th')
:wikitext(tooltip('Group size','Number of mobs the game tries to spawn per attempt'))
:done()
:tag('th')
:wikitext(tooltip('Spawn weight','Weight relative to other spawn entries in the category'))
:done()
:tag('th')
:wikitext(tooltip('Group size','Number of mobs the game tries to spawn per attempt'))
:done()
:done()
for_,vinipairs(data)do
ret:node(v.line)
end
ret:allDone()
end
returnret
end
-- Creates a line, combines bedrock and java data for a specific biome into a single line
localfunctionmakeSpawnLine(java,bedrock,notes)
ifbedrock==nilthen
bedrock={}
elseifjava==nilthen
java={}
end
localspawnBiome=(java['Spawned in']orbedrock['Spawned in']):gsub("%+","&plus;")
localsizeTextJE=java['Size']or"—"
localsizeTextBE=bedrock['Size']or"—"
localweightTextBE=bedrock['Weight']or"—"
localchanceTextBE=bedrock['Weight']or"—"
localsortKey=java['Weight']or"—"
localweightTextJE=java['Weight']and'<sup>'..java['Weight']..'</sup>&frasl;<sub>'..java['Total weight']..'</sub>'or"—"
localchanceTextJE=java['Weight']andmath.floor(java['Weight']/java['Total weight']*100*100+0.5)/100..'%'or"—"
-- Sort index in form of a decimal number that is a spawn weight
-- Used to sort the lines from higher to lower chanse of spawn
sortKey=java['Weight']andjava['Weight']/java['Total weight']or0
-- Creating ref tags with notes
localnote=""
ifjava['Note']then
ifnotes[java['Note']]==nilthen
notes[java['Note']]=java['Note name']..notes.count
notes.count=notes.count+1
note=note..mw:getCurrentFrame():extensionTag{name='ref',content=java["Note"]==bedrock["Note"]andjava['Note']orjava['Note'].."{{only|java}}",args={name=notes[java['Note']],group='spawn'}}
elseifnotes[java['Note']]then
note=note..mw:getCurrentFrame():extensionTag{name='ref',args={name=notes[java['Note']],group='spawn'}}
end
end
ifbedrock['Note']andbedrock['Note']~=java['Note']then
ifnotes[bedrock['Note']]==nilthen
notes[bedrock['Note']]=bedrock['Note name']..notes.count
notes.count=notes.count+1
note=note..mw:getCurrentFrame():extensionTag{name='ref',content=bedrock['Note'].."{{only|bedrock}}",args={name=notes[bedrock['Note']],group='spawn'}}
elseifnotes[bedrock['Note']]then
note=note..mw:getCurrentFrame():extensionTag{name='ref',args={name=notes[bedrock['Note']],group='spawn'}}
end
end
-- Formating spawn data of a biome into an HTML <tr> line
localret=mw.html.create('tr')
:tag('td')
:css('text-align','left')
:wikitext(spriteFile.link({name="BiomeSprite",align='middle',spawnBiome}))
:wikitext(note)
:done()
:tag('td')
:wikitext(weightTextJE)
:attr('data-sort-value',sortKey)
:done()
:tag('td')
:wikitext(chanceTextJE)
:done()
:tag('td')
:wikitext((sizeTextJE:gsub('-','&ndash;')))
:done()
:tag('td')
:wikitext(weightTextBE)
:done()
:tag('td')
:wikitext((sizeTextBE:gsub('-','&ndash;')))
:done()
:done()
return{line=ret:allDone(),sortKey=sortKey}
end
-- Function called by the template, runs a Bucket query and creates a table based on that data
functionp.main(frame)
localargs=frame
ifframe==mw.getCurrentFrame()then
args=require('Module:ProcessArgs').merge(true)
else
frame=mw.getCurrentFrame()
end
localspawnedMob=args.nameorargs[1]ormw.title.getCurrentTitle().text
spawnedMob=mw.text.trim(spawnedMob)
-- The Bucket query
localdata=bucket('spawn_table')
.select('page_name','json')
.where('mob',spawnedMob)
.limit(500)
.run()
localspawnTbl={}
localnotes={}
notes.count=0
localspawnPairs={}
-- Getting the mob category, checking if it is the same in Java and Bedrock
localjavaCat,bedrockCat
for_,vinipairs(dataor{})do
localspawnJSON=mw.text.jsonDecode(v.json)
ifnotspawnTbl.categorythen
ifspawnJSON["Edition"]=='java'then
javaCat=spawnJSON['Category']
else
bedrockCat=spawnJSON['Category']
end
ifjavaCat~=nilandbedrockCat~=nilthen
ifjavaCat==bedrockCatthen
spawnTbl.category=javaCat
else
spawnTbl.category="<br>"..javaCat..
frame:expandTemplate{title='Only',args={'java',short=1}}.."<br>"..
bedrockCat..
frame:expandTemplate{title='Only',args={'bedrock',short=1}}
end
end
end
-- Creating a Lua table of biomes each containing a subtable of Bedrock and Java data
ifspawnPairs[spawnJSON["Spawned in"]]==nilthen
spawnPairs[spawnJSON["Spawned in"]]={}
end
ifspawnPairs[spawnJSON["Spawned in"]][spawnJSON["Edition"]]~=nilthen
spawnPairs[spawnJSON["Spawned in"].."1"]={}
spawnPairs[spawnJSON["Spawned in"].."1"][spawnJSON["Edition"]]=spawnJSON
else
spawnPairs[spawnJSON["Spawned in"]][spawnJSON["Edition"]]=spawnJSON
end
end
-- For each of the biome, separating Java and Bedrock tables then creating
-- an HTML line, and then appending the line into the final table
fork,_inpairs(spawnPairs)do
localtableJava=spawnPairs[k].javaornil
localtableBedrock=spawnPairs[k].bedrockornil
table.insert(spawnTbl,makeSpawnLine(tableJava,tableBedrock,notes))
end
-- Sorting the lines from the highest to the lowest chance of spawn
localfunctionsortTable(a,b)
returna.sortKey>b.sortKey
end
table.sort(spawnTbl,sortTable)
assert(#spawnTbl>0,'No spawn info found for '..spawnedMob)
-- Creating a container to hold tables
localret=mw.html.create('div')
:addClass('collapsible collapsetoggle-inline'..(args.collapseand' collapsed'or''))
:tag('div')
:wikitext(spawnedMob.." spawns in:")
:done()
:tag('div')
:addClass('collapsible-content')
:node(makeSpawnTable(spawnTbl))
:wikitext(mw.getCurrentFrame():extensionTag{name="references",args={group='spawn'}})
:done()
:done()
returnret:allDone()
end
returnp
--[[ debug:
mw.log(p.main({name='Cow'}))
--]]
Retrieved from "https://minecraft.wiki/w/Module:Get_spawn_info?oldid=3568832"

Navigation menu