Fix the ButtonImpl.initialize() method producing null, use reflections8 only on fabric and shadow kotlinx.serialization on forge

This commit is contained in:
Username404-59 2021-05-16 14:43:21 +02:00
parent c39670c764
commit f9fd9222ef
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
6 changed files with 24 additions and 15 deletions

View File

@ -87,8 +87,7 @@ subprojects {
listOf( listOf(
"$kotlinX:kotlinx-datetime:0.2.0", "$kotlinX:kotlinx-datetime:0.2.0",
"com.typesafe:config:1.4.1", "com.typesafe:config:1.4.1",
"io.github.config4k:config4k:0.4.2", "io.github.config4k:config4k:0.4.2"
"net.oneandone.reflections8:reflections8:0.11.7", "org.javassist:javassist:3.28.0-GA"
).forEach { implementation(it); shadowC(it) { isTransitive = false; } } ).forEach { implementation(it); shadowC(it) { isTransitive = false; } }
"minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}") "minecraft"("com.mojang:minecraft:${rootProject.property("minecraft")}")
"mappings"(mappingsDep) "mappings"(mappingsDep)
@ -126,7 +125,8 @@ allprojects {
} }
tasks { tasks {
withType(ShadowJar::class) { 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("org.jetbrains", "${rootProject.group}.jetbrainslibs")
relocate("javassist", "${rootProject.group}.javassist") relocate("javassist", "${rootProject.group}.javassist")
relocate("org.reflections8", "${rootProject.group}.reflectionlib") relocate("org.reflections8", "${rootProject.group}.reflectionlib")

View File

@ -2,25 +2,15 @@ package fr.username404.snowygui
import fr.username404.snowygui.EventSnowy.Companion.useKey import fr.username404.snowygui.EventSnowy.Companion.useKey
import fr.username404.snowygui.config.Configuration.obtained import fr.username404.snowygui.config.Configuration.obtained
import fr.username404.snowygui.gui.feature.ButtonInfo
import fr.username404.snowygui.misc.AddKeyMaps import fr.username404.snowygui.misc.AddKeyMaps
import io.github.config4k.getValue import io.github.config4k.getValue
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger 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 { abstract class Snowy {
private val displayInitMessage: Boolean by obtained private val displayInitMessage: Boolean by obtained
companion object { companion object {
var annotatedButtons: Set<Class<*>> = Reflections(ConfigurationBuilder() lateinit var annotatedButtons: Set<Class<*>>
.setUrls(ClasspathHelper.forClassLoader())
.setScanners(SubTypesScanner(false), TypeAnnotationsScanner())
.useParallelExecutor()
).getTypesAnnotatedWith(ButtonInfo::class.java)
fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda) fun onEvent(e: String, lambda: argsLambda) = useKey(e).add(lambda)
@JvmField @JvmField
val logs: Logger = LogManager.getLogger() val logs: Logger = LogManager.getLogger()

View File

@ -11,6 +11,7 @@ import fr.username404.snowygui.gui.Renderable.Rendering.defaultRectFunc
import fr.username404.snowygui.gui.elements.ClickBox import fr.username404.snowygui.gui.elements.ClickBox
import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type import fr.username404.snowygui.gui.feature.ButtonInfo.Companion.Type
import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.findAnnotation
import kotlin.reflect.jvm.isAccessible
abstract class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) { abstract class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
companion object { companion object {
@ -21,7 +22,9 @@ abstract class ButtonImpl: ColoredElement(0.0, 0.0, 73, 8, opacity = 0.60F) {
((try { ((try {
it.getConstructor().newInstance() it.getConstructor().newInstance()
} catch (e: NoSuchMethodException) { } 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 -> }) as ButtonImpl).let { impl ->
with(impl) { with(impl) {
if (info.kind == ButtonInfo.Companion.Type.TOGGLE) { if (info.kind == ButtonInfo.Companion.Type.TOGGLE) {

View File

@ -18,6 +18,7 @@ dependencies {
include(modApi("${Groups.FabricApi}:fabric-api-base:${rootProject.property("fabric_api_base_version")}")!!) 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")}")!!) 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) 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")}") { modRuntime(modCompileOnly("com.terraformersmc:modmenu:${rootProject.property("modmenu_version")}") {
exclude(group = Groups.FabricApi, module = "fabric-api-base") exclude(group = Groups.FabricApi, module = "fabric-api-base")
exclude(group = Groups.FabricApi, module = "fabric-resource-loader-v0") exclude(group = Groups.FabricApi, module = "fabric-resource-loader-v0")

View File

@ -3,9 +3,15 @@ package fr.username404.snowygui.fabric
import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.PoseStack
import fr.username404.snowygui.EventSnowy import fr.username404.snowygui.EventSnowy
import fr.username404.snowygui.Snowy import fr.username404.snowygui.Snowy
import fr.username404.snowygui.gui.feature.ButtonInfo
import net.fabricmc.api.ClientModInitializer import net.fabricmc.api.ClientModInitializer
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback.EVENT 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 { class FabricInit: Snowy(), ClientModInitializer {
override fun onInitializeClient() { 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)
}
} }

View File

@ -7,6 +7,7 @@ dependencies {
implementation("thedarkcolour:kotlinforforge:${rootProject.property("kotlinforforge")}.0") implementation("thedarkcolour:kotlinforforge:${rootProject.property("kotlinforforge")}.0")
implementation(project(path = ":common")) { isTransitive = false } implementation(project(path = ":common")) { isTransitive = false }
add("developmentForge", 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 } shadowC(project(path = ":common", configuration = "transformProductionForge")) { isTransitive = false }
}; loom { }; loom {
useFabricMixin = true useFabricMixin = true