package fr.username404.snowygui import fr.username404.snowygui.config.Configuration import fr.username404.snowygui.gui.feature.ButtonImpl import fr.username404.snowygui.gui.feature.ButtonImpl.Companion.initButtons import fr.username404.snowygui.gui.feature.ButtonInfo import fr.username404.snowygui.misc.AddKeyMaps import net.minecraft.network.chat.Component import net.minecraft.network.chat.Component.translatable import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger 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 abstract val annotatedButtons: Set> companion object { @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") val MissingComponent: Component = translatable("MISSING_COMPONENT") @Suppress("JVM_STATIC_ON_CONST_OR_JVM_FIELD") // See KT-39868 @JvmStatic protected const val FeaturePackage: String = "fr.username404.snowygui.gui.feature" lateinit var annotatedButtons: () -> Set> fun onEvent(e: Any, lambda: argsLambda) = EventSnowy[e.toString()].add(lambda) @JvmField val logs: Logger = LogManager.getLogger() } init { Companion.annotatedButtons = ::annotatedButtons::get } private fun eventsInit() { onEvent("EndTick") { for (Key in AddKeyMaps.list.keys) { if (Key.isDown) { AddKeyMaps.list[Key]?.invoke() } } } } fun atInit() { if (displayInitMessage) logs.info("Init point of SnowyGUI hit.") eventsInit() } }