aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-06-26 08:28:26 +0200
committerGitHub <noreply@github.com>2024-06-26 08:28:26 +0200
commit41f2ff07c87e6b47bcbec531e6a8bcff53d800dc (patch)
tree6e8bbe701cf8058bd6e8c6dffa040d1742284c9a /src/main
parente88f416c48f9659f89b7047d7629cd9a1d1535bc (diff)
downloadskyhanni-41f2ff07c87e6b47bcbec531e6a8bcff53d800dc.tar.gz
skyhanni-41f2ff07c87e6b47bcbec531e6a8bcff53d800dc.tar.bz2
skyhanni-41f2ff07c87e6b47bcbec531e6a8bcff53d800dc.zip
Add OneConfig mods to quick mod switcher (#2155)
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt77
1 files changed, 22 insertions, 55 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt
index 2741605ef..95f18c3c3 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/misc/QuickModMenuSwitch.kt
@@ -34,17 +34,10 @@ object QuickModMenuSwitch {
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val modsJar = event.getConstant<ModGuiSwitcherJson>("ModGuiSwitcher")
- mods = buildList {
- out@ for ((name, mod) in modsJar.mods) {
- for (path in mod.guiPath) {
- try {
- Class.forName(path)
- add(Mod(name, mod.description, mod.command, mod.guiPath))
- continue@out
- } catch (_: Exception) {
- }
- }
- }
+ mods = modsJar.mods.filter { mod ->
+ mod.value.guiPath.any { runCatching { Class.forName(it) }.isSuccess }
+ }.map { (name, mod) ->
+ Mod(name, mod.description, mod.command, mod.guiPath)
}
}
@@ -108,11 +101,21 @@ object QuickModMenuSwitch {
return config.javaClass.name
}
if (openGui == "cc.polyfrost.oneconfig.gui.OneConfigGui") {
- /** TODO support different oneconfig mods:
- * Partly Sane Skies
- * Dankers SkyBlock Mod
- * Dulkir
- */
+ val actualGui = Minecraft.getMinecraft().currentScreen
+ val currentPage = actualGui.javaClass.getDeclaredField("currentPage")
+ .makeAccessible()
+ .get(actualGui)
+ if (currentPage.javaClass.simpleName == "ModConfigPage") {
+ val optionPage = currentPage.javaClass.getDeclaredField("page")
+ .makeAccessible()
+ .get(currentPage)
+ val mod = optionPage.javaClass.getField("mod")
+ .makeAccessible()
+ .get(optionPage)
+ val modName = mod.javaClass.getField("name")
+ .get(mod) as String
+ return "cc.polyfrost.oneconfig.gui.OneConfigGui:$modName"
+ }
}
return openGui
@@ -132,7 +135,7 @@ object QuickModMenuSwitch {
Renderable.string(nameFormat + mod.name),
bypassChecks = true,
onClick = { open(mod) },
- condition = { System.currentTimeMillis() > lastGuiOpen + 250 }
+ condition = { System.currentTimeMillis() > lastGuiOpen + 250 },
)
add(listOf(renderable, nameSuffix))
}
@@ -143,44 +146,8 @@ object QuickModMenuSwitch {
currentlyOpeningMod = mod.name
update()
try {
- when (mod.command) {
- "patcher" -> {
- val patcher = Class.forName("club.sk1er.patcher.Patcher")
- val instance = patcher.getDeclaredField("instance").get(null)
- val config = instance.javaClass.getDeclaredMethod("getPatcherConfig").invoke(instance)
- val gui = Class.forName("gg.essential.vigilance.Vigilant").getDeclaredMethod("gui").invoke(config)
- val guiUtils = Class.forName("gg.essential.api.utils.GuiUtil")
- for (method in guiUtils.declaredMethods) {
- try {
- method.invoke(null, gui)
- return
- } catch (_: Exception) {
- }
- }
- ErrorManager.skyHanniError("Error trying to open the gui for mod " + mod.name + "!")
- }
-
- "hytil" -> {
- val hytilsReborn = Class.forName("cc.woverflow.hytils.HytilsReborn")
- val instance = hytilsReborn.getDeclaredField("INSTANCE").get(null)
- val config = instance.javaClass.getDeclaredMethod("getConfig").invoke(instance)
- val gui = Class.forName("gg.essential.vigilance.Vigilant").getDeclaredMethod("gui").invoke(config)
- val guiUtils = Class.forName("gg.essential.api.utils.GuiUtil")
- for (method in guiUtils.declaredMethods) {
- try {
- method.invoke(null, gui)
- return
- } catch (_: Exception) {
- }
- }
- ChatUtils.chat("Error trying to open the gui for mod " + mod.name + "!")
- }
-
- else -> {
- val thePlayer = Minecraft.getMinecraft().thePlayer
- ClientCommandHandler.instance.executeCommand(thePlayer, "/${mod.command}")
- }
- }
+ val thePlayer = Minecraft.getMinecraft().thePlayer
+ ClientCommandHandler.instance.executeCommand(thePlayer, "/" + mod.command)
} catch (e: Exception) {
ErrorManager.logErrorWithData(e, "Error trying to open the gui for mod " + mod.name)
}