Fix a crash on launch when macros exist on neoforge
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
2341dafe1b
commit
d8b37fc4ab
@ -1,6 +1,6 @@
|
||||
package fr.username404.snowygui
|
||||
|
||||
import fr.username404.snowygui.config.Configuration
|
||||
import fr.username404.snowygui.config.LazyConfiguration
|
||||
import fr.username404.snowygui.gui.feature.ButtonImpl
|
||||
import fr.username404.snowygui.gui.feature.ButtonInfo
|
||||
import fr.username404.snowygui.misc.AddKeyMaps
|
||||
@ -13,7 +13,7 @@ import java.lang.reflect.Modifier
|
||||
abstract class Snowy {
|
||||
protected fun Class<*>.isValidForButtonCollection(): Boolean =
|
||||
!Modifier.isAbstract(modifiers) && declaredAnnotations.any { it is ButtonInfo && !it.ignored }
|
||||
private val displayInitMessage: Boolean by Configuration
|
||||
private val displayInitMessage: Lazy<Boolean> by LazyConfiguration
|
||||
abstract val annotatedButtons: Lazy<Set<Class<out ButtonImpl>>>
|
||||
companion object {
|
||||
val MissingComponent: Component = translatable("MISSING_COMPONENT")
|
||||
@ -36,7 +36,7 @@ abstract class Snowy {
|
||||
}
|
||||
}
|
||||
fun atInit() {
|
||||
if (displayInitMessage) logs.info("Init point of SnowyGUI hit.")
|
||||
if (displayInitMessage.value) logs.info("Init point of SnowyGUI hit.")
|
||||
eventsInit()
|
||||
}
|
||||
}
|
||||
@ -175,3 +175,9 @@ object Configuration {
|
||||
operator fun <T> setValue(ref: Any?, property: KProperty<*>, value: T) = @Suppress("DEPRECATION_ERROR")
|
||||
ModifiableValues.setValue(ref, property, value)
|
||||
}
|
||||
|
||||
object LazyConfiguration {
|
||||
inline operator fun <reified T: Any> getValue(ref: Any?, property: KProperty<*>): Lazy<T> = lazy {
|
||||
Configuration.getValue<T>(ref, property);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package fr.username404.snowygui.forge
|
||||
|
||||
import fr.username404.snowygui.ClickGui
|
||||
import fr.username404.snowygui.Snowy
|
||||
import fr.username404.snowygui.config.SnowyConfigScreen
|
||||
import fr.username404.snowygui.config.configScreenParent
|
||||
@ -15,7 +16,11 @@ import net.neoforged.neoforgespi.language.ModFileScanData
|
||||
@Mod("snowygui")
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
class ForgeInit(container: ModContainer): Snowy() {
|
||||
private fun initSetup(event: FMLClientSetupEvent) = atInit()
|
||||
private fun initSetup(event: FMLClientSetupEvent) {
|
||||
atInit()
|
||||
ClickGui.tick()
|
||||
ButtonImpl.initButtons()
|
||||
}
|
||||
override val annotatedButtons = lazy { // Forge-specific reflection
|
||||
ModList.get()
|
||||
.allScanData
|
||||
|
||||
@ -1,18 +1,10 @@
|
||||
package fr.username404.snowygui.forge
|
||||
|
||||
import fr.username404.snowygui.ClickGui
|
||||
import fr.username404.snowygui.gui.feature.ButtonImpl
|
||||
import fr.username404.snowygui.misc.AddKeyMaps
|
||||
import net.neoforged.bus.api.SubscribeEvent
|
||||
import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent
|
||||
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent
|
||||
|
||||
object MiscModBusHandlers {
|
||||
@SubscribeEvent
|
||||
fun handleClickGuiInit(event: RegisterMenuScreensEvent) {
|
||||
ClickGui.tick()
|
||||
ButtonImpl.initButtons()
|
||||
}
|
||||
@SubscribeEvent
|
||||
fun handleKeys(event: RegisterKeyMappingsEvent) {
|
||||
AddKeyMaps.list.forEach {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user