diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-09-14 19:46:52 +0200 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-09-14 19:46:52 +0200 |
| commit | 0a96dd618acba15269627c7eae8a2291fb2dc84a (patch) | |
| tree | f31a66cbd13cefbfb2d006f07d3ef3da1010f7e7 /src/main/kotlin/features | |
| parent | 9abe9f46f04f188037687adb2740b32220ad21b2 (diff) | |
| download | Firmament-0a96dd618acba15269627c7eae8a2291fb2dc84a.tar.gz Firmament-0a96dd618acba15269627c7eae8a2291fb2dc84a.tar.bz2 Firmament-0a96dd618acba15269627c7eae8a2291fb2dc84a.zip | |
snapshot
Diffstat (limited to 'src/main/kotlin/features')
55 files changed, 592 insertions, 881 deletions
diff --git a/src/main/kotlin/features/FeatureManager.kt b/src/main/kotlin/features/FeatureManager.kt index 3e235f5..d474d65 100644 --- a/src/main/kotlin/features/FeatureManager.kt +++ b/src/main/kotlin/features/FeatureManager.kt @@ -1,102 +1,18 @@ package moe.nea.firmament.features -import kotlinx.serialization.Serializable -import kotlinx.serialization.serializer -import moe.nea.firmament.Firmament -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 -import moe.nea.firmament.features.debug.DebugView -import moe.nea.firmament.features.debug.DeveloperFeatures -import moe.nea.firmament.features.debug.MinorTrolling -import moe.nea.firmament.features.debug.PowerUserTools -import moe.nea.firmament.features.diana.DianaWaypoints -import moe.nea.firmament.features.events.anniversity.AnniversaryFeatures -import moe.nea.firmament.features.events.carnival.CarnivalFeatures -import moe.nea.firmament.features.fixes.CompatibliltyFeatures -import moe.nea.firmament.features.fixes.Fixes -import moe.nea.firmament.features.inventory.CraftingOverlay -import moe.nea.firmament.features.inventory.ItemRarityCosmetics -import moe.nea.firmament.features.inventory.PetFeatures -import moe.nea.firmament.features.inventory.PriceData -import moe.nea.firmament.features.inventory.SaveCursorPosition -import moe.nea.firmament.features.inventory.SlotLocking -import moe.nea.firmament.features.inventory.WardrobeKeybinds -import moe.nea.firmament.features.inventory.buttons.InventoryButtons -import moe.nea.firmament.features.inventory.storageoverlay.StorageOverlay -import moe.nea.firmament.features.items.EtherwarpOverlay -import moe.nea.firmament.features.mining.PickaxeAbility -import moe.nea.firmament.features.mining.PristineProfitTracker -import moe.nea.firmament.features.misc.CustomCapes -import moe.nea.firmament.features.misc.Hud -import moe.nea.firmament.features.world.FairySouls -import moe.nea.firmament.features.world.Waypoints import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.compatloader.ICompatMeta -import moe.nea.firmament.util.data.DataHolder -object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "features", ::Config) { - @Serializable - data class Config( - val enabledFeatures: MutableMap<String, Boolean> = mutableMapOf() - ) - - private val features = mutableMapOf<String, FirmamentFeature>() - - val allFeatures: Collection<FirmamentFeature> get() = features.values - - private var hasAutoloaded = false - - fun autoload() { - synchronized(this) { - if (hasAutoloaded) return - loadFeature(MinorTrolling) - loadFeature(FairySouls) - loadFeature(AutoCompletions) - // TODO: loadFeature(FishingWarning) - loadFeature(SlotLocking) - loadFeature(StorageOverlay) - loadFeature(PristineProfitTracker) - loadFeature(CraftingOverlay) - loadFeature(PowerUserTools) - loadFeature(Waypoints) - loadFeature(ChatLinks) - loadFeature(CompatibliltyFeatures) - loadFeature(AnniversaryFeatures) - loadFeature(QuickCommands) - loadFeature(PetFeatures) - loadFeature(SaveCursorPosition) - loadFeature(PriceData) - loadFeature(Fixes) - loadFeature(CustomCapes) - loadFeature(Hud) - loadFeature(EtherwarpOverlay) - loadFeature(DianaWaypoints) - loadFeature(ItemRarityCosmetics) - loadFeature(PickaxeAbility) - loadFeature(CarnivalFeatures) - if (Firmament.DEBUG) { - loadFeature(DeveloperFeatures) - loadFeature(DebugView) - } - allFeatures.forEach { it.config } - FeaturesInitializedEvent.publish(FeaturesInitializedEvent(allFeatures.toList())) - hasAutoloaded = true - } - } +object FeatureManager { fun subscribeEvents() { SubscriptionList.allLists.forEach { list -> if (ICompatMeta.shouldLoad(list.javaClass.name)) ErrorUtil.catch("Error while loading events from $list") { list.provideSubscriptions { - it.owner.javaClass.classes.forEach { - runCatching { it.getDeclaredField("INSTANCE").get(null) } - } subscribeSingleEvent(it) } } @@ -106,25 +22,4 @@ object FeatureManager : DataHolder<FeatureManager.Config>(serializer(), "feature private fun <T : FirmamentEvent> subscribeSingleEvent(it: Subscription<T>) { it.eventBus.subscribe(false, "${it.owner.javaClass.simpleName}:${it.methodName}", it.invoke) } - - fun loadFeature(feature: FirmamentFeature) { - synchronized(features) { - if (feature.identifier in features) { - Firmament.logger.error("Double registering feature ${feature.identifier}. Ignoring second instance $feature") - return - } - features[feature.identifier] = feature - feature.onLoad() - } - } - - fun isEnabled(identifier: String): Boolean? = - data.enabledFeatures[identifier] - - - fun setEnabled(identifier: String, value: Boolean) { - data.enabledFeatures[identifier] = value - markDirty() - } - } diff --git a/src/main/kotlin/features/FirmamentFeature.kt b/src/main/kotlin/features/FirmamentFeature.kt deleted file mode 100644 index 08e7019..0000000 --- a/src/main/kotlin/features/FirmamentFeature.kt +++ /dev/null @@ -1,23 +0,0 @@ - - -package moe.nea.firmament.features - -import moe.nea.firmament.events.subscription.SubscriptionOwner -import moe.nea.firmament.util.data.ManagedConfig - -// TODO: remove this entire feature system and revamp config -interface FirmamentFeature : SubscriptionOwner { - val identifier: String - val defaultEnabled: Boolean - get() = true - var isEnabled: Boolean - get() = FeatureManager.isEnabled(identifier) ?: defaultEnabled - set(value) { - FeatureManager.setEnabled(identifier, value) - } - override val delegateFeature: FirmamentFeature - get() = this - val config: ManagedConfig? get() = null - fun onLoad() {} - -} diff --git a/src/main/kotlin/features/chat/AutoCompletions.kt b/src/main/kotlin/features/chat/AutoCompletions.kt index dac1daa..b48069d 100644 --- a/src/main/kotlin/features/chat/AutoCompletions.kt +++ b/src/main/kotlin/features/chat/AutoCompletions.kt @@ -8,13 +8,12 @@ import moe.nea.firmament.commands.thenArgument import moe.nea.firmament.commands.thenExecute import moe.nea.firmament.events.CommandEvent import moe.nea.firmament.events.MaskCommands -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.MC import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig -object AutoCompletions : FirmamentFeature { +object AutoCompletions { @Config object TConfig : ManagedConfig(identifier, Category.CHAT) { @@ -22,9 +21,7 @@ object AutoCompletions : FirmamentFeature { val replaceWarpIsByWarpIsland by toggle("warp-is") { true } } - override val config: ManagedConfig? - get() = TConfig - override val identifier: String + val identifier: String get() = "auto-completions" @Subscribe @@ -46,9 +43,9 @@ object AutoCompletions : FirmamentFeature { thenExecute { val warpName = get(toArg) if (warpName == "is" && TConfig.replaceWarpIsByWarpIsland) { - MC.sendServerCommand("warp island") + MC.sendCommand("warp island") } else { - MC.sendServerCommand("warp $warpName") + MC.sendCommand("warp $warpName") } } } diff --git a/src/main/kotlin/features/chat/ChatLinks.kt b/src/main/kotlin/features/chat/ChatLinks.kt index 6ea07d6..b05a3a0 100644 --- a/src/main/kotlin/features/chat/ChatLinks.kt +++ b/src/main/kotlin/features/chat/ChatLinks.kt @@ -7,7 +7,6 @@ import java.net.URI import java.net.URL import java.util.Collections import java.util.concurrent.atomic.AtomicInteger -import moe.nea.jarvis.api.Point import org.joml.Vector2i import kotlinx.coroutines.Deferred import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -26,17 +25,16 @@ import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ModifyChatEvent import moe.nea.firmament.events.ScreenRenderPostEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.jarvis.JarvisIntegration import moe.nea.firmament.util.MC import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.render.drawTexture import moe.nea.firmament.util.transformEachRecursively import moe.nea.firmament.util.unformattedString -object ChatLinks : FirmamentFeature { - override val identifier: String +object ChatLinks { + val identifier: String get() = "chat-links" @Config @@ -54,7 +52,6 @@ object ChatLinks : FirmamentFeature { private fun isUrlAllowed(url: String) = isHostAllowed(url.removePrefix("https://").substringBefore("/")) - override val config get() = TConfig val urlRegex = "https://[^. ]+\\.[^ ]+(\\.?(\\s|$))".toRegex() val nextTexId = AtomicInteger(0) @@ -76,7 +73,7 @@ object ChatLinks : FirmamentFeature { } imageCache[url] = Firmament.coroutineScope.async { try { - val response = Firmament.httpClient.get(URL(url)) + val response = Firmament.httpClient.get(URI.create(url).toURL()) if (response.status.value == 200) { val inputStream = response.bodyAsChannel().toInputStream(Firmament.globalJob) val image = NativeImage.read(inputStream) diff --git a/src/main/kotlin/features/chat/CopyChat.kt b/src/main/kotlin/features/chat/CopyChat.kt index 5cd847a..5c46465 100644 --- a/src/main/kotlin/features/chat/CopyChat.kt +++ b/src/main/kotlin/features/chat/CopyChat.kt @@ -1,16 +1,13 @@ package moe.nea.firmament.features.chat import net.minecraft.text.OrderedText -import moe.nea.firmament.annotations.Subscribe -import moe.nea.firmament.events.ClientStartedEvent -import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.util.data.Config import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.reconstitute -object CopyChat : FirmamentFeature { - override val identifier: String +object CopyChat { + val identifier: String get() = "copy-chat" @Config @@ -18,16 +15,7 @@ object CopyChat : FirmamentFeature { val copyChat by toggle("copy-chat") { false } } - @Subscribe - fun onInit(event: ClientStartedEvent) { - } - - override val config: ManagedConfig? - get() = TConfig - fun orderedTextToString(orderedText: OrderedText): String { return orderedText.reconstitute().string } - - } diff --git a/src/main/kotlin/features/chat/PartyCommands.kt b/src/main/kotlin/features/chat/PartyCommands.kt index 5a80013..1b34946 100644 --- a/src/main/kotlin/features/chat/PartyCommands.kt +++ b/src/main/kotlin/features/chat/PartyCommands.kt @@ -12,11 +12,11 @@ import moe.nea.firmament.commands.thenExecute import moe.nea.firmament.events.CommandEvent import moe.nea.firmament.events.PartyMessageReceivedEvent import moe.nea.firmament.events.ProcessChatEvent -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.MC import moe.nea.firmament.util.TimeMark import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.tr import moe.nea.firmament.util.useMatch diff --git a/src/main/kotlin/features/chat/QuickCommands.kt b/src/main/kotlin/features/chat/QuickCommands.kt index 88218b4..5221205 100644 --- a/src/main/kotlin/features/chat/QuickCommands.kt +++ b/src/main/kotlin/features/chat/QuickCommands.kt @@ -15,18 +15,19 @@ import moe.nea.firmament.commands.get import moe.nea.firmament.commands.thenArgument import moe.nea.firmament.commands.thenExecute import moe.nea.firmament.events.CommandEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.gui.config.ManagedOption import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData +import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.grey import moe.nea.firmament.util.tr -object QuickCommands : FirmamentFeature { - override val identifier: String +object QuickCommands { + val identifier: String get() = "quick-commands" + @Config object TConfig : ManagedConfig("quick-commands", Category.CHAT) { val enableJoin by toggle("join") { true } val enableDh by toggle("dh") { true } @@ -43,8 +44,12 @@ object QuickCommands : FirmamentFeature { val dispatcher = CommandDispatcher<FabricClientCommandSource>() ClientCommandInternals.setActiveDispatcher(dispatcher) ClientCommandRegistrationCallback.EVENT.invoker() - .register(dispatcher, CommandRegistryAccess.of(network.combinedDynamicRegistries, - network.enabledFeatures)) + .register( + dispatcher, CommandRegistryAccess.of( + network.combinedDynamicRegistries, + network.enabledFeatures + ) + ) ClientCommandInternals.finalizeInit() network.onCommandTree(lastPacket) } catch (ex: Exception) { @@ -100,8 +105,12 @@ object QuickCommands : FirmamentFeature { if (joinName == null) { source.sendFeedback(Text.stringifiedTranslatable("firmament.quick-commands.join.unknown", what)) } else { - source.sendFeedback(Text.stringifiedTranslatable("firmament.quick-commands.join.success", - joinName)) + source.sendFeedback( + Text.stringifiedTranslatable( + "firmament.quick-commands.join.success", + joinName + ) + ) MC.sendCommand("joininstance $joinName") } } @@ -122,8 +131,12 @@ object QuickCommands : FirmamentFeature { ) } if (l !in kuudraLevelNames.indices) { - source.sendFeedback(Text.stringifiedTranslatable("firmament.quick-commands.join.unknown-kuudra", - kuudraLevel)) + source.sendFeedback( + Text.stringifiedTranslatable( + "firmament.quick-commands.join.unknown-kuudra", + kuudraLevel + ) + ) return null } return "KUUDRA_${kuudraLevelNames[l]}" @@ -143,8 +156,12 @@ object QuickCommands : FirmamentFeature { return "CATACOMBS_ENTRANCE" } if (l !in dungeonLevelNames.indices) { - source.sendFeedback(Text.stringifiedTranslatable("firmament.quick-commands.join.unknown-catacombs", - kuudraLevel)) + source.sendFeedback( + Text.stringifiedTranslatable( + "firmament.quick-commands.join.unknown-catacombs", + kuudraLevel + ) + ) return null } return "${if (masterLevel != null) "MASTER_" else ""}CATACOMBS_FLOOR_${dungeonLevelNames[l]}" diff --git a/src/main/kotlin/features/debug/DebugLogger.kt b/src/main/kotlin/features/debug/DebugLogger.kt index 9115956..02073b7 100644 --- a/src/main/kotlin/features/debug/DebugLogger.kt +++ b/src/main/kotlin/features/debug/DebugLogger.kt @@ -4,6 +4,7 @@ import kotlinx.serialization.serializer import net.minecraft.text.Text import moe.nea.firmament.util.MC import moe.nea.firmament.util.collections.InstanceList +import moe.nea.firmament.util.data.Config import moe.nea.firmament.util.data.DataHolder class DebugLogger(val tag: String) { @@ -11,13 +12,14 @@ class DebugLogger(val tag: String) { val allInstances = InstanceList<DebugLogger>("DebugLogger") } + @Config object EnabledLogs : DataHolder<MutableSet<String>>(serializer(), "DebugLogs", ::mutableSetOf) init { allInstances.add(this) } - fun isEnabled() = DeveloperFeatures.isEnabled && EnabledLogs.data.contains(tag) + fun isEnabled() = EnabledLogs.data.contains(tag) fun log(text: String) = log { text } fun log(text: () -> String) { if (!isEnabled()) return diff --git a/src/main/kotlin/features/debug/DebugView.kt b/src/main/kotlin/features/debug/DebugView.kt deleted file mode 100644 index ee54260..0000000 --- a/src/main/kotlin/features/debug/DebugView.kt +++ /dev/null @@ -1,29 +0,0 @@ - - -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 - -object DebugView : FirmamentFeature { - private data class StoredVariable<T>( - val obj: T, - val timer: TimeMark, - ) - - private val storedVariables: MutableMap<String, StoredVariable<*>> = sortedMapOf() - override val identifier: String - get() = "debug-view" - override val defaultEnabled: Boolean - get() = Firmament.DEBUG - - fun <T : Any?> showVariable(label: String, obj: T) { - synchronized(this) { - storedVariables[label] = StoredVariable(obj, TimeMark.now()) - } - } - -} diff --git a/src/main/kotlin/features/debug/DeveloperFeatures.kt b/src/main/kotlin/features/debug/DeveloperFeatures.kt index cb9cf00..e86c6ad 100644 --- a/src/main/kotlin/features/debug/DeveloperFeatures.kt +++ b/src/main/kotlin/features/debug/DeveloperFeatures.kt @@ -16,23 +16,18 @@ import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.DebugInstantiateEvent import moe.nea.firmament.events.TickEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.init.MixinPlugin import moe.nea.firmament.util.MC import moe.nea.firmament.util.TimeMark import moe.nea.firmament.util.asm.AsmAnnotationUtil import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.iterate -object DeveloperFeatures : FirmamentFeature { +object DeveloperFeatures { val DEVELOPER_SUBCOMMAND: String = "dev" - override val identifier: String + val identifier: String get() = "developer" - override val config: TConfig - get() = TConfig - override val defaultEnabled: Boolean - get() = Firmament.DEBUG val gradleDir = Path.of(".").absolute() @@ -98,7 +93,7 @@ object DeveloperFeatures : FirmamentFeature { @JvmStatic fun hookOnBeforeResourceReload(client: MinecraftClient): CompletableFuture<Void> { - val reloadFuture = if (TConfig.autoRebuildResources && isEnabled && gradleDir != null) { + val reloadFuture = if (TConfig.autoRebuildResources && Firmament.DEBUG && gradleDir != null) { |
