diff --git a/build.gradle.kts b/build.gradle.kts index 324cd07..7d0377c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -87,8 +87,7 @@ subprojects { listOf( "$kotlinX:kotlinx-datetime:0.2.0", "com.typesafe:config:1.4.1", - "io.github.config4k:config4k:0.4.2", - "net.oneandone.reflections8:reflections8:0.11.7", "org.javassist:javassist:3.28.0-GA" + "io.github.config4k:config4k:0.4.2" ).forEach { implementation(it); shadowC(it) { isTransitive = false; } } "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") "mappings"(mappingsDep) @@ -126,7 +125,8 @@ allprojects { } tasks { withType(ShadowJar::class) { - relocate("kotlinx-datetime", "${rootProject.group}.kotlinx-datetime") + relocate("kotlinx.datetime", "${rootProject.group}.datetime") + relocate("kotlinx.serialization", "${rootProject.group}.serialization") relocate("org.jetbrains", "${rootProject.group}.jetbrainslibs") relocate("javassist", "${rootProject.group}.javassist") relocate("org.reflections8", "${rootProject.group}.reflectionlib") diff --git a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt index 99d04f6..ba40297 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/Snowy.kt @@ -2,25 +2,15 @@ package fr.username404.snowygui import fr.username404.snowygui.EventSnowy.Companion.useKey import fr.username404.snowygui.config.Configuration.obtained -import fr.username404.snowygui.gui.feature.ButtonInfo import fr.username404.snowygui.misc.AddKeyMaps import io.github.config4k.getValue import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger -import org.reflections8.Reflections -import org.reflections8.scanners.SubTypesScanner -import org.reflections8.scanners.TypeAnnotationsScanner -import org.reflections8.util.ClasspathHelper -import org.reflections8.util.ConfigurationBuilder abstract class Snowy { private val displayInitMessage: Boolean by obtained companion object { - var annotatedButtons: Set> = Reflections(ConfigurationBuilder() - .setUrls(ClasspathHelper.forClassLoader()) - .setScanners(SubTypesScanner(false), TypeAnnotationsScanner()) - .useParallelExecutor() - ).getTypesAnnotatedWith(ButtonInfo::class.java) + lateinit var annotatedButtons: Set> fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda) @JvmField val logs: Logger = LogManager.getLogger() diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt index 29c7864..9dee031 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/feature/ButtonImpl.kt @@ -11,6 +11,7 @@ import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc import fr.username404.snowygui.gui.elements.ClickBox import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type import kotlin.reflect.full.findAnnotation +import kotlin.reflect.jvm.isAccessible abstract class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { companion object { @@ -21,7 +22,9 @@ abstract class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { ((try { it.getConstructor().newInstance() } catch (e: NoSuchMethodException) { - it.kotlin.objectInstance + try { + it.kotlin.objectInstance!! + } catch (e: NullPointerException) { it.kotlin.constructors.first().also { build -> build.isAccessible = true }.call() } }) as ButtonImpl).let { impl -> with(impl) { if (info.kind == ButtonInfo.Companion.Type.TOGGLE) { diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 0a80e84..58f7c89 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { include(modApi("${Groups.FabricApi}:fabric-api-base:${rootProject.property("fabric_api_base_version")}")!!) include(modRuntime("${Groups.FabricApi}:fabric-resource-loader-v0:${rootProject.property("fabric_resource_loader_version")}")!!) modImplementation(group = "net.fabricmc", name = "fabric-language-kotlin", version = rootProject.property("fabric_language_kotlin") as String) + listOf("net.oneandone.reflections8:reflections8:0.11.7", "org.javassist:javassist:3.28.0-GA").forEach { implementation(it); shadowC(it) { isTransitive = false } } modRuntime(modCompileOnly("com.terraformersmc:modmenu:${rootProject.property("modmenu_version")}") { exclude(group = Groups.FabricApi, module = "fabric-api-base") exclude(group = Groups.FabricApi, module = "fabric-resource-loader-v0") diff --git a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt index 01f472c..081d5b2 100644 --- a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt @@ -3,9 +3,15 @@ package fr.username404.snowygui.fabric import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.EventSnowy import fr.username404.snowygui.Snowy +import fr.username404.snowygui.gui.feature.ButtonInfo import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback.EVENT +import org.reflections8.Reflections +import org.reflections8.scanners.SubTypesScanner +import org.reflections8.scanners.TypeAnnotationsScanner +import org.reflections8.util.ClasspathHelper +import org.reflections8.util.ConfigurationBuilder class FabricInit: Snowy(), ClientModInitializer { override fun onInitializeClient() { @@ -17,4 +23,12 @@ class FabricInit: Snowy(), ClientModInitializer { } ) } + init { + annotatedButtons = Reflections( + ConfigurationBuilder() + .setUrls(ClasspathHelper.forClassLoader()) + .setScanners(SubTypesScanner(false), TypeAnnotationsScanner()) + .useParallelExecutor() + ).getTypesAnnotatedWith(ButtonInfo::class.java) + } } \ No newline at end of file diff --git a/forge/build.gradle.kts b/forge/build.gradle.kts index 7e188a8..85503e3 100644 --- a/forge/build.gradle.kts +++ b/forge/build.gradle.kts @@ -7,6 +7,7 @@ dependencies { implementation("thedarkcolour:kotlinforforge:${rootProject.property("kotlinforforge")}.0") implementation(project(path = ":common")) { isTransitive = false } add("developmentForge", project(path = ":common")) { isTransitive = false } + shadowC("org.jetbrains.kotlinx:kotlinx-serialization-core:1.2.1") { isTransitive = false } shadowC(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false } }; loom { useFabricMixin = true