Skip to content

Instantly share code, notes, and snippets.

@Eladkay
Created June 22, 2017 14:59
Show Gist options
  • Save Eladkay/6c263f2aa0179628e7ed2529e2ff1536 to your computer and use it in GitHub Desktop.
Save Eladkay/6c263f2aa0179628e7ed2529e2ff1536 to your computer and use it in GitHub Desktop.
open fun postInit(event: FMLPostInitializationEvent) {
// --Wiki Navbox Generator-- (i made this)
val COLOR_CHAR = '\u00A7'
val STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR.toString() + "[0-9A-FK-OR]")
fun stripColor(input: String?): String? {
if (input == null)
return null
return STRIP_COLOR_PATTERN.matcher(input).replaceAll("")
}
val abbrev = "SIL" // has to be wiki-registered
val items = ModItems.javaClass.declaredFields.map { it.isAccessible = true; it.get(ModItems) }.filter { it is Item }.map { it as Item }.flatMap {
val list = mutableListOf<String>()
val subs = mutableListOf<ItemStack>()
it.getSubItems(it, null, subs)
for(sub in subs)
if("NYI" !in it.getItemStackDisplayName(sub) && "WIP" !in it.getItemStackDisplayName(sub))
list.add("{{NI|${stripColor(it.getItemStackDisplayName(sub))}|mod=$abbrev}}")
list
}.joinToString("{{,}}<!--\n\t\t-->")
val blocks = ModBlocks.javaClass.declaredFields.map { it.isAccessible = true; it.get(ModBlocks) }.filter { it is Block }.map { it as Block }.flatMap {
if(Item.getItemFromBlock(it) == null) return@flatMap listOf<String>()
val list = mutableListOf<String>()
val subs = mutableListOf<ItemStack>()
it.getSubBlocks(Item.getItemFromBlock(it), null, subs)
for(sub in subs)
if("NYI" !in Item.getItemFromBlock(it)!!.getItemStackDisplayName(sub) && "WIP" !in Item.getItemFromBlock(it)!!.getItemStackDisplayName(sub))
list.add("{{NI|${stripColor(Item.getItemFromBlock(it)?.getItemStackDisplayName(sub))}|mod=$abbrev}}")
list
}.joinToString("{{,}}<!--\n\t\t-->")
val navbox = "{{Navbox\n|title={{L|${LibMisc.NAME}}}\n|" +
"name=Navbox ${LibMisc.NAME}\n|list1={{Navbox subgroup\n\t|" +
"title=Items\n\t|state={{{state|uncollapsed}}}\n\t|group1=All\n\t|list1=$items\n\t}}\n\t|list2={{Navbox subgroup\n\t|" +
"title=Blocks\n\t|state={{{state|uncollapsed}}}\n\t|group1=All\n\t|list1=$blocks\n\t}}\n}}"
if(LibrarianLib.DEV_ENVIRONMENT) {
println(navbox)
throw Exception()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment