Cast classes to ButtonImpl properly in Snowy.kt, FabricInit.kt and ForgeInit.kt

This commit is contained in:
Username404 2021-05-27 21:29:11 +02:00
parent b1852f743e
commit 6848b26797
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
3 changed files with 3 additions and 3 deletions

View File

@ -19,7 +19,7 @@ abstract class Snowy {
val Gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create() val Gson: Gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create()
@JvmStatic @JvmStatic
protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature" protected val FeaturePackage: String = "fr.username404.snowygui.gui.feature"
lateinit var annotatedButtons: Set<Class<ButtonImpl>> lateinit var annotatedButtons: Set<Class<out ButtonImpl>>
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

@ -30,6 +30,6 @@ class FabricInit: Snowy(), ClientModInitializer {
.setUrls(ClasspathHelper.forPackage(FeaturePackage)) .setUrls(ClasspathHelper.forPackage(FeaturePackage))
.setScanners(SubTypesScanner(false), TypeAnnotationsScanner()) .setScanners(SubTypesScanner(false), TypeAnnotationsScanner())
.useParallelExecutor() .useParallelExecutor()
).getTypesAnnotatedWith(ButtonInfo::class.java).filter { it.isValidForButtonCollection() }.toSet() as Set<Class<ButtonImpl>> ).getTypesAnnotatedWith(ButtonInfo::class.java).filter { it.isValidForButtonCollection() }.map { it.asSubclass(ButtonImpl::class.java) }.toSet()
} }
} }

View File

@ -50,7 +50,7 @@ class ForgeInit: Snowy() {
} }
} }
} }
.map { Class.forName((it!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(it) as Type).className) as Class<ButtonImpl> } .map { Class.forName((it!!.javaClass.getDeclaredField("clazz").apply { isAccessible = true }.get(it) as Type).className).asSubclass(ButtonImpl::class.java)}
.collect(Collectors.toSet()) .collect(Collectors.toSet())
with(MOD_BUS) { with(MOD_BUS) {
addListener(this@ForgeInit::initSetup) addListener(this@ForgeInit::initSetup)