Don't use URLClassLoader instances on fabric

This commit is contained in:
Username404 2021-07-15 17:10:50 +02:00
parent 3290db57a9
commit 7c9e98bdc0
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
1 changed files with 2 additions and 3 deletions

View File

@ -8,7 +8,7 @@ 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 net.fabricmc.loader.api.FabricLoader
import java.net.URLClassLoader
import net.fabricmc.loader.launch.common.FabricLauncherBase
import kotlin.io.path.exists
import kotlin.io.path.isDirectory
import kotlin.io.path.listDirectoryEntries
@ -28,12 +28,11 @@ class FabricInit: Snowy(), ClientModInitializer {
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<Class<out ButtonImpl>>()
buttonsDirectory.run {
listDirectoryEntries("*.class").forEach { file ->
val foundClass = buttonsLoader.loadClass(file.pathString.drop(1).replace('/', '.').removeSuffix(".class"))
val foundClass = FabricLauncherBase.getClass(file.pathString.drop(1).replace('/', '.').removeSuffix(".class"))
if (foundClass.isValidForButtonCollection()) classSet.add(foundClass.asSubclass(ButtonImpl::class.java))
}
}