Replace the reflections8 library (and therefore javassist) using FabricLoader
This commit is contained in:
parent
f3d4770e00
commit
3290db57a9
|
@ -84,8 +84,6 @@ subprojects {
|
||||||
}
|
}
|
||||||
withType(ShadowJar::class) {
|
withType(ShadowJar::class) {
|
||||||
this.configurations = listOf(shadowC)
|
this.configurations = listOf(shadowC)
|
||||||
relocate("javassist", "${rootProject.group}.javassist")
|
|
||||||
relocate("org.reflections8", "${rootProject.group}.reflectionlib")
|
|
||||||
relocate("com.typesafe.config", "${rootProject.group}.typesafe.config")
|
relocate("com.typesafe.config", "${rootProject.group}.typesafe.config")
|
||||||
relocate("io.github.config4k", "${rootProject.group}.config4k")
|
relocate("io.github.config4k", "${rootProject.group}.config4k")
|
||||||
relocate("net.arikia.dev.drpc", "${rootProject.group}.drpc")
|
relocate("net.arikia.dev.drpc", "${rootProject.group}.drpc")
|
||||||
|
|
|
@ -38,11 +38,11 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
|
||||||
override fun onClose() { minecraft?.screen = configScreenParent }
|
override fun onClose() { minecraft?.screen = configScreenParent }
|
||||||
}; get() = try {
|
}; get() = try {
|
||||||
Class.forName("me.shedaniel.clothconfig2.api.ConfigBuilder")
|
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)
|
(it is ClickBox) && it.isCategory(Category.MACROS)
|
||||||
} as ClickBox
|
} as? ClickBox
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val macrosButtons = macrosBox.buttons as MutableSet<Macro>
|
val macrosButtons = (macrosBox?.buttons ?: LinkedHashSet<Macro>()) as MutableSet<Macro>
|
||||||
fun Collection<Macro>.getTitleCommand(): MutableList<String> = map { it.run { "$title: $command" } }.toMutableList()
|
fun Collection<Macro>.getTitleCommand(): MutableList<String> = map { it.run { "$title: $command" } }.toMutableList()
|
||||||
me.shedaniel.clothconfig2.api.ConfigBuilder.create().setParentScreen(configScreenParent).transparentBackground()
|
me.shedaniel.clothconfig2.api.ConfigBuilder.create().setParentScreen(configScreenParent).transparentBackground()
|
||||||
.setShouldListSmoothScroll(true)
|
.setShouldListSmoothScroll(true)
|
||||||
|
@ -109,7 +109,7 @@ val SnowyConfigScreen: Screen = object: Screen(translationComponent) {
|
||||||
macrosButtons.add(newMacro)
|
macrosButtons.add(newMacro)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}; if (it.isEmpty().also { empty -> macrosBox.hidden = empty })
|
}; if (it.isEmpty().also { empty -> macrosBox?.hidden = empty })
|
||||||
macrosButtons.clear()
|
macrosButtons.clear()
|
||||||
}.build()
|
}.build()
|
||||||
)
|
)
|
||||||
|
|
|
@ -19,7 +19,6 @@ dependencies {
|
||||||
modApi("me.shedaniel.cloth:cloth-config-fabric:${rootProject.property("clothconfig_version")}") { exclude(group = Groups.FabricApi) }
|
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")}")!!)
|
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")
|
||||||
|
|
|
@ -4,15 +4,15 @@ 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.ButtonImpl
|
import fr.username404.snowygui.gui.feature.ButtonImpl
|
||||||
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 net.fabricmc.loader.api.FabricLoader
|
||||||
import org.reflections8.scanners.SubTypesScanner
|
import java.net.URLClassLoader
|
||||||
import org.reflections8.scanners.TypeAnnotationsScanner
|
import kotlin.io.path.exists
|
||||||
import org.reflections8.util.ClasspathHelper
|
import kotlin.io.path.isDirectory
|
||||||
import org.reflections8.util.ConfigurationBuilder
|
import kotlin.io.path.listDirectoryEntries
|
||||||
|
import kotlin.io.path.pathString
|
||||||
|
|
||||||
class FabricInit: Snowy(), ClientModInitializer {
|
class FabricInit: Snowy(), ClientModInitializer {
|
||||||
override fun onInitializeClient() {
|
override fun onInitializeClient() {
|
||||||
|
@ -25,11 +25,19 @@ class FabricInit: Snowy(), ClientModInitializer {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
init {
|
init {
|
||||||
annotatedButtons = Reflections(
|
val modsPaths = FabricLoader.getInstance().allMods.map {
|
||||||
ConfigurationBuilder()
|
it.getPath(FeaturePackage.replace('.', '/'))
|
||||||
.setUrls(ClasspathHelper.forPackage(FeaturePackage))
|
}.filter { it.exists() && it.isDirectory() }
|
||||||
.setScanners(SubTypesScanner(false), TypeAnnotationsScanner())
|
val buttonsLoader = URLClassLoader(modsPaths.map { it.toUri().toURL() }.toTypedArray(), Thread.currentThread().contextClassLoader)
|
||||||
.useParallelExecutor()
|
annotatedButtons = modsPaths.flatMap { buttonsDirectory ->
|
||||||
).getTypesAnnotatedWith(ButtonInfo::class.java).filter { it.isValidForButtonCollection() }.map { it.asSubclass(ButtonImpl::class.java) }.toSet()
|
val classSet = mutableSetOf<Class<out ButtonImpl>>()
|
||||||
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue