diff --git a/build.gradle.kts b/build.gradle.kts index 457def1..e4cf3ce 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -84,8 +84,6 @@ subprojects { } withType(ShadowJar::class) { this.configurations = listOf(shadowC) - relocate("javassist", "${rootProject.group}.javassist") - relocate("org.reflections8", "${rootProject.group}.reflectionlib") relocate("com.typesafe.config", "${rootProject.group}.typesafe.config") relocate("io.github.config4k", "${rootProject.group}.config4k") relocate("net.arikia.dev.drpc", "${rootProject.group}.drpc") diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt index 2499bcd..a893caa 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/ConfigScreen.kt @@ -38,11 +38,11 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) { override fun onClose() { minecraft?.screen = configScreenParent } }; get() = try { Class.forName("me.shedaniel.clothconfig2.api.ConfigBuilder") - val macrosBox: ClickBox = ClickGui.components.find { + val macrosBox: ClickBox? = ClickGui.components.find { (it is ClickBox) && it.isCategory(Category.MACROS) - } as ClickBox + } as? ClickBox @Suppress("UNCHECKED_CAST") - val macrosButtons = macrosBox.buttons as MutableSet + val macrosButtons = (macrosBox?.buttons ?: LinkedHashSet()) as MutableSet fun Collection.getTitleCommand(): MutableList = map { it.run { "$title: $command" } }.toMutableList() me.shedaniel.clothconfig2.api.ConfigBuilder.create().setParentScreen(configScreenParent).transparentBackground() .setShouldListSmoothScroll(true) @@ -109,7 +109,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) { macrosButtons.add(newMacro) } } - }; if (it.isEmpty().also { empty -> macrosBox.hidden = empty }) + }; if (it.isEmpty().also { empty -> macrosBox?.hidden = empty }) macrosButtons.clear() }.build() ) diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index c70db79..e368330 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -19,7 +19,6 @@ dependencies { modApi("me.shedaniel.cloth:cloth-config-fabric:${rootProject.property("clothconfig_version")}") { exclude(group = Groups.FabricApi) } 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 aadb9cf..bd90afa 100644 --- a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt @@ -4,15 +4,15 @@ import com.mojang.blaze3d.vertex.PoseStack import fr.username404.snowygui.EventSnowy import fr.username404.snowygui.Snowy import fr.username404.snowygui.gui.feature.ButtonImpl -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 +import net.fabricmc.loader.api.FabricLoader +import java.net.URLClassLoader +import kotlin.io.path.exists +import kotlin.io.path.isDirectory +import kotlin.io.path.listDirectoryEntries +import kotlin.io.path.pathString class FabricInit: Snowy(), ClientModInitializer { override fun onInitializeClient() { @@ -25,11 +25,19 @@ class FabricInit: Snowy(), ClientModInitializer { ) } init { - annotatedButtons = Reflections( - ConfigurationBuilder() - .setUrls(ClasspathHelper.forPackage(FeaturePackage)) - .setScanners(SubTypesScanner(false), TypeAnnotationsScanner()) - .useParallelExecutor() - ).getTypesAnnotatedWith(ButtonInfo::class.java).filter { it.isValidForButtonCollection() }.map { it.asSubclass(ButtonImpl::class.java) }.toSet() + val modsPaths = FabricLoader.getInstance().allMods.map { + it.getPath(FeaturePackage.replace('.', '/')) + }.filter { it.exists() && it.isDirectory() } + val buttonsLoader = URLClassLoader(modsPaths.map { it.toUri().toURL() }.toTypedArray(), Thread.currentThread().contextClassLoader) + annotatedButtons = modsPaths.flatMap { buttonsDirectory -> + val classSet = mutableSetOf>() + buttonsDirectory.run { + listDirectoryEntries("*.class").forEach { file -> + val foundClass = buttonsLoader.loadClass(file.pathString.drop(1).replace('/', '.').removeSuffix(".class")) + if (foundClass.isValidForButtonCollection()) classSet.add(foundClass.asSubclass(ButtonImpl::class.java)) + } + } + classSet + }.toSet() } } \ No newline at end of file