diff --git a/build.gradle.kts b/build.gradle.kts index c4587f5..2dd9acd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -52,8 +52,9 @@ subprojects { "$kotlinX:kotlinx-datetime:0.2.1", "com.typesafe:config:1.4.1", "io.github.config4k:config4k:0.4.2", - "org.jetbrains:annotations:20.1.0" - ).forEach { implementation(it); shadowC(it) { isTransitive = false; } } + "org.jetbrains:annotations:20.1.0", + "com.github.Vatuu:discord-rpc:1.6.2" + ).forEach { implementation(it); shadowC(it) { isTransitive = false; exclude("com.sun.jna") } } "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") "mappings"(mappingsDep) } @@ -73,6 +74,7 @@ subprojects { relocate("com.typesafe.config", "${rootProject.group}.typesafe.config") relocate("io.github.config4k", "${rootProject.group}.config4k") relocate("net.arikia.dev.drpc", "${rootProject.group}.drpc") + exclude("com/sun/jna/**/*") // The shadowed JNA from discord-rpc isn't needed since it is already available at runtime exclude("**/*.kotlin_metadata") exclude("**/*.kotlin_builtins") exclude("META-INF/maven/**/*") @@ -99,6 +101,9 @@ subprojects { adaptclassstrings() "$group.**".also { dontnote(it); dontwarn(it) } + // Required for discord-rpc + keep("class $group.drpc.** { public * ; }") + dontwarn("kotlinx.serialization.**") doFirst { diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/DiscordRPC.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/DiscordRPC.kt new file mode 100644 index 0000000..14204df --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/DiscordRPC.kt @@ -0,0 +1,23 @@ +package fr.username404.snowygui.gui.feature + +import net.arikia.dev.drpc.DiscordRichPresence +import net.minecraft.client.Minecraft +import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type +import net.arikia.dev.drpc.DiscordEventHandlers +import net.arikia.dev.drpc.DiscordRPC as discord_rpc + +@ButtonInfo(Category.MISC, kind = Type.TOGGLE) +object DiscordRPC: ButtonImpl() { + private val RPCHandlers: DiscordEventHandlers = DiscordEventHandlers.Builder().build() + private val RichPresence: DiscordRichPresence.Builder = DiscordRichPresence + .Builder("Playing Minecraft ${Minecraft.getInstance().game.version.name} (${Minecraft.getInstance().launchedVersion})") + .setBigImage("icon", "SnowyGUI") + override fun execAction() { + if (toggled) discord_rpc.discordUpdatePresence(RichPresence.build()) + else discord_rpc.discordClearPresence() + } + init { + Runtime.getRuntime().addShutdownHook(Thread { discord_rpc.discordShutdown() }) + discord_rpc.discordInitialize("839058922102849538", RPCHandlers, true) + } +} \ No newline at end of file