From 5ed74f2df49c93ed1617520a935078b59ad7e195 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 1 Sep 2024 22:21:19 +0200 Subject: Add per compat project event listeners [no changelog] --- src/main/kotlin/features/FeatureManager.kt | 12 +++++------ src/main/kotlin/features/debug/DebugView.kt | 11 +--------- src/main/kotlin/features/debug/PowerUserTools.kt | 18 ++++++++-------- src/main/kotlin/features/diana/DianaWaypoints.kt | 24 +++++++++------------- .../features/texturepack/CustomBlockTextures.kt | 10 +++++++-- 5 files changed, 35 insertions(+), 40 deletions(-) (limited to 'src/main/kotlin/features') diff --git a/src/main/kotlin/features/FeatureManager.kt b/src/main/kotlin/features/FeatureManager.kt index 19b91de..c2889eb 100644 --- a/src/main/kotlin/features/FeatureManager.kt +++ b/src/main/kotlin/features/FeatureManager.kt @@ -1,14 +1,12 @@ - - package moe.nea.firmament.features import kotlinx.serialization.Serializable import kotlinx.serialization.serializer import moe.nea.firmament.Firmament -import moe.nea.firmament.annotations.generated.AllSubscriptions import moe.nea.firmament.events.FeaturesInitializedEvent import moe.nea.firmament.events.FirmamentEvent import moe.nea.firmament.events.subscription.Subscription +import moe.nea.firmament.events.subscription.SubscriptionList import moe.nea.firmament.features.chat.AutoCompletions import moe.nea.firmament.features.chat.ChatLinks import moe.nea.firmament.features.chat.QuickCommands @@ -88,13 +86,15 @@ object FeatureManager : DataHolder(serializer(), "feature } fun subscribeEvents() { - AllSubscriptions.provideSubscriptions { - subscribeSingleEvent(it) + SubscriptionList.allLists.forEach { + it.provideSubscriptions { + subscribeSingleEvent(it) + } } } private fun subscribeSingleEvent(it: Subscription) { - it.eventBus.subscribe(false, it.invoke) + it.eventBus.subscribe(false, "${it.owner.javaClass.simpleName}:${it.methodName}", it.invoke) } fun loadFeature(feature: FirmamentFeature) { diff --git a/src/main/kotlin/features/debug/DebugView.kt b/src/main/kotlin/features/debug/DebugView.kt index 7e1b8ec..ee54260 100644 --- a/src/main/kotlin/features/debug/DebugView.kt +++ b/src/main/kotlin/features/debug/DebugView.kt @@ -3,6 +3,7 @@ package moe.nea.firmament.features.debug import moe.nea.firmament.Firmament +import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.TickEvent import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.util.TimeMark @@ -25,14 +26,4 @@ object DebugView : FirmamentFeature { } } - fun recalculateDebugWidget() { - } - - override fun onLoad() { - TickEvent.subscribe { - synchronized(this) { - recalculateDebugWidget() - } - } - } } diff --git a/src/main/kotlin/features/debug/PowerUserTools.kt b/src/main/kotlin/features/debug/PowerUserTools.kt index 7893eff..dccf8f7 100644 --- a/src/main/kotlin/features/debug/PowerUserTools.kt +++ b/src/main/kotlin/features/debug/PowerUserTools.kt @@ -4,6 +4,7 @@ package moe.nea.firmament.features.debug import net.minecraft.block.SkullBlock import net.minecraft.block.entity.SkullBlockEntity +import net.minecraft.client.gui.screen.Screen import net.minecraft.component.DataComponentTypes import net.minecraft.entity.Entity import net.minecraft.entity.LivingEntity @@ -54,15 +55,16 @@ object PowerUserTools : FirmamentFeature { } var lastCopiedStackViewTime = false - override fun onLoad() { - TickEvent.subscribe { - if (!lastCopiedStackViewTime) - lastCopiedStack = null - lastCopiedStackViewTime = false - } - ScreenChangeEvent.subscribe { + @Subscribe + fun resetLastCopiedStack(event: TickEvent) { + if (!lastCopiedStackViewTime) lastCopiedStack = null - } + lastCopiedStackViewTime = false + } + + @Subscribe + fun resetLastCopiedStackOnScreenChange(event: ScreenChangeEvent) { + lastCopiedStack = null } fun debugFormat(itemStack: ItemStack): Text { diff --git a/src/main/kotlin/features/diana/DianaWaypoints.kt b/src/main/kotlin/features/diana/DianaWaypoints.kt index 0a34eaa..205e237 100644 --- a/src/main/kotlin/features/diana/DianaWaypoints.kt +++ b/src/main/kotlin/features/diana/DianaWaypoints.kt @@ -1,14 +1,8 @@ - package moe.nea.firmament.features.diana +import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.AttackBlockEvent -import moe.nea.firmament.events.ParticleSpawnEvent -import moe.nea.firmament.events.ProcessChatEvent -import moe.nea.firmament.events.SoundReceiveEvent import moe.nea.firmament.events.UseBlockEvent -import moe.nea.firmament.events.WorldKeyboardEvent -import moe.nea.firmament.events.WorldReadyEvent -import moe.nea.firmament.events.WorldRenderLastEvent import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.gui.config.ManagedConfig @@ -22,13 +16,15 @@ object DianaWaypoints : FirmamentFeature { val nearbyWaypoints by toggle("nearby-waypoints") { true } } - override fun onLoad() { - UseBlockEvent.subscribe { - NearbyBurrowsSolver.onBlockClick(it.hitResult.blockPos) - } - AttackBlockEvent.subscribe { - NearbyBurrowsSolver.onBlockClick(it.blockPos) - } + + @Subscribe + fun onBlockUse(event: UseBlockEvent) { + NearbyBurrowsSolver.onBlockClick(event.hitResult.blockPos) + } + + @Subscribe + fun onBlockAttack(event: AttackBlockEvent) { + NearbyBurrowsSolver.onBlockClick(event.blockPos) } } diff --git a/src/main/kotlin/features/texturepack/CustomBlockTextures.kt b/src/main/kotlin/features/texturepack/CustomBlockTextures.kt index 0f2c2e6..a149928 100644 --- a/src/main/kotlin/features/texturepack/CustomBlockTextures.kt +++ b/src/main/kotlin/features/texturepack/CustomBlockTextures.kt @@ -168,7 +168,11 @@ object CustomBlockTextures { } private val sodiumReloadTask = runCatching { - Class.forName("moe.nea.firmament.compat.sodium.SodiumChunkReloader").getConstructor().newInstance() as Runnable + val r = Class.forName("moe.nea.firmament.compat.sodium.SodiumChunkReloader") + .getConstructor() + .newInstance() as Runnable + r.run() + r }.getOrElse { if (FabricLoader.getInstance().isModLoaded("sodium")) logger.error("Could not create sodium chunk reloader") @@ -192,7 +196,9 @@ object CustomBlockTextures { @JvmStatic fun getReplacement(block: BlockState, blockPos: BlockPos?): Replacement? { - if (isInFallback() && blockPos == null) return null + if (isInFallback() && blockPos == null) { + return null + } val replacements = currentIslandReplacements?.lookup?.get(block.block) ?: return null for (replacement in replacements) { if (replacement.checks == null || matchesPosition(replacement, blockPos)) -- cgit