diff options
Diffstat (limited to 'src/main/kotlin')
111 files changed, 749 insertions, 1095 deletions
diff --git a/src/main/kotlin/Firmament.kt b/src/main/kotlin/Firmament.kt index 198defa..3ac01c0 100644 --- a/src/main/kotlin/Firmament.kt +++ b/src/main/kotlin/Firmament.kt @@ -51,7 +51,6 @@ import moe.nea.firmament.repo.HypixelStaticData import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData -import moe.nea.firmament.util.data.IDataHolder import moe.nea.firmament.util.mc.InitLevel import moe.nea.firmament.util.tr @@ -144,7 +143,7 @@ object Firmament { }) RepoManager.initialize() SBData.init() - FeatureManager.autoload() + FeatureManager.subscribeEvents() HypixelStaticData.spawnDataCollectionLoop() ClientCommandRegistrationCallback.EVENT.register(this::registerCommands) ClientLifecycleEvents.CLIENT_STARTED.register(ClientLifecycleEvents.ClientStarted { diff --git a/src/main/kotlin/apis/Profiles.kt b/src/main/kotlin/apis/Profiles.kt index a6c334b..ec4a6e4 100644 --- a/src/main/kotlin/apis/Profiles.kt +++ b/src/main/kotlin/apis/Profiles.kt @@ -7,19 +7,19 @@ package moe.nea.firmament.apis import io.github.moulberry.repo.constants.Leveling import io.github.moulberry.repo.data.Rarity import java.time.Instant +import java.util.UUID import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.UseSerializers +import kotlin.reflect.KProperty1 +import net.minecraft.util.DyeColor +import net.minecraft.util.Formatting import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.LegacyFormattingCode import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.assertNotNullOr import moe.nea.firmament.util.json.DashlessUUIDSerializer import moe.nea.firmament.util.json.InstantAsLongSerializer -import net.minecraft.util.DyeColor -import net.minecraft.util.Formatting -import java.util.* -import kotlin.reflect.KProperty1 @Serializable diff --git a/src/main/kotlin/apis/Routes.kt b/src/main/kotlin/apis/Routes.kt index 5e29402..737763d 100644 --- a/src/main/kotlin/apis/Routes.kt +++ b/src/main/kotlin/apis/Routes.kt @@ -2,19 +2,15 @@ package moe.nea.firmament.apis -import io.ktor.client.call.* -import io.ktor.client.request.* -import io.ktor.http.* -import io.ktor.util.* -import java.util.* +import io.ktor.client.call.body +import io.ktor.client.request.get +import io.ktor.http.isSuccess +import io.ktor.util.CaseInsensitiveMap +import java.util.UUID import kotlinx.coroutines.Deferred import kotlinx.coroutines.async import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import kotlin.collections.MutableMap -import kotlin.collections.listOf -import kotlin.collections.mutableMapOf -import kotlin.collections.set import moe.nea.firmament.Firmament import moe.nea.firmament.util.MinecraftDispatcher diff --git a/src/main/kotlin/apis/UrsaManager.kt b/src/main/kotlin/apis/UrsaManager.kt index 13f7aef..19e030c 100644 --- a/src/main/kotlin/apis/UrsaManager.kt +++ b/src/main/kotlin/apis/UrsaManager.kt @@ -2,17 +2,19 @@ package moe.nea.firmament.apis -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.http.* +import io.ktor.client.request.get +import io.ktor.client.request.header +import io.ktor.client.statement.HttpResponse +import io.ktor.client.statement.bodyAsText +import io.ktor.http.appendPathSegments +import java.time.Duration +import java.time.Instant +import java.util.UUID import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.withContext -import moe.nea.firmament.Firmament import net.minecraft.client.MinecraftClient -import java.time.Duration -import java.time.Instant -import java.util.* +import moe.nea.firmament.Firmament object UrsaManager { private data class Token( diff --git a/src/main/kotlin/commands/Duration.kt b/src/main/kotlin/commands/Duration.kt index 42f143d..58ce5d8 100644 --- a/src/main/kotlin/commands/Duration.kt +++ b/src/main/kotlin/commands/Duration.kt @@ -7,7 +7,6 @@ import com.mojang.brigadier.exceptions.DynamicCommandExceptionType import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder import java.util.concurrent.CompletableFuture -import java.util.function.Function import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds import kotlin.time.DurationUnit diff --git a/src/main/kotlin/commands/dsl.kt b/src/main/kotlin/commands/dsl.kt index d1f0d8c..c5955d7 100644 --- a/src/main/kotlin/commands/dsl.kt +++ b/src/main/kotlin/commands/dsl.kt @@ -7,14 +7,14 @@ import com.mojang.brigadier.builder.ArgumentBuilder import com.mojang.brigadier.builder.RequiredArgumentBuilder import com.mojang.brigadier.context.CommandContext import com.mojang.brigadier.suggestion.SuggestionProvider +import java.lang.reflect.ParameterizedType +import java.lang.reflect.Type +import java.lang.reflect.TypeVariable +import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource import kotlinx.coroutines.launch import moe.nea.firmament.Firmament import moe.nea.firmament.util.MinecraftDispatcher import moe.nea.firmament.util.iterate -import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource -import java.lang.reflect.ParameterizedType -import java.lang.reflect.Type -import java.lang.reflect.TypeVariable typealias DefaultSource = FabricClientCommandSource diff --git a/src/main/kotlin/commands/rome.kt b/src/main/kotlin/commands/rome.kt index d12da44..b1b2aa2 100644 --- a/src/main/kotlin/commands/rome.kt +++ b/src/main/kotlin/commands/rome.kt @@ -20,7 +20,6 @@ import moe.nea.firmament.features.inventory.storageoverlay.StorageOverviewScreen import moe.nea.firmament.features.mining.MiningBlockInfoUi import moe.nea.firmament.gui.config.AllConfigsGui import moe.nea.firmament.gui.config.BooleanHandler -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.gui.config.ManagedOption import moe.nea.firmament.init.MixinPlugin import moe.nea.firmament.repo.HypixelStaticData @@ -38,6 +37,7 @@ import moe.nea.firmament.util.accessors.messages import moe.nea.firmament.util.asBazaarStock import moe.nea.firmament.util.collections.InstanceList import moe.nea.firmament.util.collections.WeakCache +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.mc.SNbtFormatter import moe.nea.firmament.util.tr import moe.nea.firmament.util.unformattedString diff --git a/src/main/kotlin/events/AllowChatEvent.kt b/src/main/kotlin/events/AllowChatEvent.kt index 3069843..a1b4828 100644 --- a/src/main/kotlin/events/AllowChatEvent.kt +++ b/src/main/kotlin/events/AllowChatEvent.kt @@ -2,8 +2,8 @@ package moe.nea.firmament.events -import moe.nea.firmament.util.unformattedString import net.minecraft.text.Text +import moe.nea.firmament.util.unformattedString /** * Filter whether the user should see a chat message altogether. May or may not be called for every chat packet sent by diff --git a/src/main/kotlin/events/EntityRenderTintEvent.kt b/src/main/kotlin/events/EntityRenderTintEvent.kt index 29b888b..54cbff2 100644 --- a/src/main/kotlin/events/EntityRenderTintEvent.kt +++ b/src/main/kotlin/events/EntityRenderTintEvent.kt @@ -5,6 +5,7 @@ import net.minecraft.client.render.OverlayTexture import net.minecraft.client.render.entity.state.EntityRenderState import net.minecraft.entity.Entity import net.minecraft.entity.LivingEntity +import moe.nea.firmament.events.EntityRenderTintEvent.Companion.overlayOverride import moe.nea.firmament.util.render.TintedOverlayTexture /** diff --git a/src/main/kotlin/events/FeaturesInitializedEvent.kt b/src/main/kotlin/events/FeaturesInitializedEvent.kt deleted file mode 100644 index ad2ad8a..0000000 --- a/src/main/kotlin/events/FeaturesInitializedEvent.kt +++ /dev/null @@ -1,8 +0,0 @@ - -package moe.nea.firmament.events - -import moe.nea.firmament.features.FirmamentFeature - -data class FeaturesInitializedEvent(val features: List<FirmamentFeature>) : FirmamentEvent() { - companion object : FirmamentEventBus<FeaturesInitializedEvent>() -} diff --git a/src/main/kotlin/events/IsSlotProtectedEvent.kt b/src/main/kotlin/events/IsSlotProtectedEvent.kt index 8fe0a96..6ab0174 100644 --- a/src/main/kotlin/events/IsSlotProtectedEvent.kt +++ b/src/main/kotlin/events/IsSlotProtectedEvent.kt @@ -3,7 +3,6 @@ package moe.nea.firmament.events import net.minecraft.item.ItemStack import net.minecraft.screen.slot.Slot import net.minecraft.screen.slot.SlotActionType -import net.minecraft.text.Text import moe.nea.firmament.util.CommonSoundEffects import moe.nea.firmament.util.MC import moe.nea.firmament.util.grey diff --git a/src/main/kotlin/events/ModifyChatEvent.kt b/src/main/kotlin/events/ModifyChatEvent.kt index a5868e8..4a7025c 100644 --- a/src/main/kotlin/events/ModifyChatEvent.kt +++ b/src/main/kotlin/events/ModifyChatEvent.kt @@ -2,8 +2,8 @@ package moe.nea.firmament.events -import moe.nea.firmament.util.unformattedString import net.minecraft.text.Text +import moe.nea.firmament.util.unformattedString /** * Allow modification of a chat message before it is sent off to the user. Intended for display purposes. diff --git a/src/main/kotlin/events/SlotRenderEvents.kt b/src/main/kotlin/events/SlotRenderEvents.kt index 5234176..9076d53 100644 --- a/src/main/kotlin/events/SlotRenderEvents.kt +++ b/src/main/kotlin/events/SlotRenderEvents.kt @@ -3,11 +3,8 @@ package moe.nea.firmament.events import net.minecraft.client.gui.DrawContext -import net.minecraft.client.render.RenderLayer -import net.minecraft.client.texture.Sprite import net.minecraft.screen.slot.Slot import net.minecraft.util.Identifier -import moe.nea.firmament.util.MC import moe.nea.firmament.util.render.drawGuiTexture interface SlotRenderEvents { diff --git a/src/main/kotlin/events/WorldRenderLastEvent.kt b/src/main/kotlin/events/WorldRenderLastEvent.kt index 3c2103d..93d7e8c 100644 --- a/src/main/kotlin/events/WorldRenderLastEvent.kt +++ b/src/main/kotlin/events/WorldRenderLastEvent.kt @@ -3,13 +3,9 @@ package moe.nea.firmament.events import net.minecraft.client.render.Camera -import net.minecraft.client.render.GameRenderer -import net.minecraft.client.render.LightmapTextureManager import net.minecraft.client.render.RenderTickCounter import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.util.math.MatrixStack -import net.minecraft.util.math.Position -import net.minecraft.util.math.Vec3d /** * This event is called after all world rendering is done, but before any GUI rendering (including hand) has been done. diff --git a/src/main/kotlin/events/subscription/Subscription.kt b/src/main/kotlin/events/subscription/Subscription.kt index 1c1d3bd..812da92 100644 --- a/src/main/kotlin/events/subscription/Subscription.kt +++ b/src/main/kotlin/events/subscription/Subscription.kt @@ -3,11 +3,7 @@ package moe.nea.firmament.events.subscription import moe.nea.firmament.events.FirmamentEvent import moe.nea.firmament.events.FirmamentEventBus -import moe.nea.firmament.features.FirmamentFeature -interface SubscriptionOwner { - val delegateFeature: FirmamentFeature -} data class Subscription<T : FirmamentEvent>( val owner: Any, 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) { val builder = ProcessBuilder("./gradlew", ":processResources") builder.directory(gradleDir.toFile()) builder.inheritIO() diff --git a/src/main/kotlin/features/debug/MinorTrolling.kt b/src/main/kotlin/features/debug/MinorTrolling.kt index 32035a6..d802d40 100644 --- a/src/main/kotlin/features/debug/MinorTrolling.kt +++ b/src/main/kotlin/features/debug/MinorTrolling.kt @@ -5,12 +5,10 @@ package moe.nea.firmament.features.debug import net.minecraft.text.Text import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ModifyChatEvent -import moe.nea.firmament.features.FirmamentFeature - // In memorian Dulkir -object MinorTrolling : FirmamentFeature { - override val identifier: String +object MinorTrolling { + val identifier: String get() = "minor-trolling" val trollers = listOf("nea89o", "lrg89") diff --git a/src/main/kotlin/features/debug/PowerUserTools.kt b/src/main/kotlin/features/debug/PowerUserTools.kt index 90b73bb..049a0fb 100644 --- a/src/main/kotlin/features/debug/PowerUserTools.kt +++ b/src/main/kotlin/features/debug/PowerUserTools.kt @@ -27,13 +27,13 @@ import moe.nea.firmament.events.ItemTooltipEvent import moe.nea.firmament.events.ScreenChangeEvent import moe.nea.firmament.events.TickEvent import moe.nea.firmament.events.WorldKeyboardEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.mixins.accessor.AccessorHandledScreen import moe.nea.firmament.util.ClipboardUtils 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.focusedItemStack +import moe.nea.firmament.util.grey import moe.nea.firmament.util.mc.IntrospectableItemModelManager import moe.nea.firmament.util.mc.SNbtFormatter import moe.nea.firmament.util.mc.SNbtFormatter.Companion.toPrettyString @@ -42,10 +42,9 @@ import moe.nea.firmament.util.mc.iterableArmorItems import moe.nea.firmament.util.mc.loreAccordingToNbt import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.tr -import moe.nea.firmament.util.grey -object PowerUserTools : FirmamentFeature { - override val identifier: String +object PowerUserTools { + val identifier: String get() = "power-user" @Config @@ -66,9 +65,6 @@ object PowerUserTools : FirmamentFeature { val dontHighlightSemicolonItems by toggle("dont-highlight-semicolon-items") { false } } - override val config - get() = TConfig - var lastCopiedStack: Pair<ItemStack, Text>? = null set(value) { field = value diff --git a/src/main/kotlin/features/diana/AncestralSpadeSolver.kt b/src/main/kotlin/features/diana/AncestralSpadeSolver.kt index 48004e8..a2869f0 100644 --- a/src/main/kotlin/features/diana/AncestralSpadeSolver.kt +++ b/src/main/kotlin/features/diana/AncestralSpadeSolver.kt @@ -10,19 +10,16 @@ import moe.nea.firmament.events.SoundReceiveEvent import moe.nea.firmament.events.WorldKeyboardEvent import moe.nea.firmament.events.WorldReadyEvent import moe.nea.firmament.events.WorldRenderLastEvent -import moe.nea.firmament.events.subscription.SubscriptionOwner -import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SkyBlockIsland -import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.TimeMark import moe.nea.firmament.util.WarpUtil import moe.nea.firmament.util.render.RenderInWorldContext import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyblock.SkyBlockItems -object AncestralSpadeSolver : SubscriptionOwner { +object AncestralSpadeSolver { var lastDing = TimeMark.farPast() private set private val pitches = mutableListOf<Float>() @@ -122,8 +119,4 @@ object AncestralSpadeSolver : SubscriptionOwner { pitches.clear() lastDing = TimeMark.farPast() } - - override val delegateFeature: FirmamentFeature - get() = DianaWaypoints - } diff --git a/src/main/kotlin/features/diana/DianaWaypoints.kt b/src/main/kotlin/features/diana/DianaWaypoints.kt index 68ee1ea..650e6f9 100644 --- a/src/main/kotlin/features/diana/DianaWaypoints.kt +++ b/src/main/kotlin/features/diana/DianaWaypoints.kt @@ -3,31 +3,29 @@ package moe.nea.firmament.features.diana import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.AttackBlockEvent import moe.nea.firmament.events.UseBlockEvent -import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.util.data.Config import moe.nea.firmament.util.data.ManagedConfig -object DianaWaypoints : FirmamentFeature { - override val identifier get() = "diana" - override val config get() = TConfig +object DianaWaypoints { + val identifier get() = "diana" @Config - object TConfig : ManagedConfig(identifier, Category.EVENTS) { - val ancestralSpadeSolver by toggle("ancestral-spade") { true } - val ancestralSpadeTeleport by keyBindingWithDefaultUnbound("ancestral-teleport") - val nearbyWaypoints by toggle("nearby-waypoints") { true } - } - - - @Subscribe - fun onBlockUse(event: UseBlockEvent) { - NearbyBurrowsSolver.onBlockClick(event.hitResult.blockPos) - } - - @Subscribe - fun onBlockAttack(event: AttackBlockEvent) { - NearbyBurrowsSolver.onBlockClick(event.blockPos) - } + object TConfig : ManagedConfig(identifier, Category.EVENTS) { + val ancestralSpadeSolver by toggle("ancestral-spade") { true } + val ancestralSpadeTeleport by keyBindingWithDefaultUnbound("ancestral-teleport") + val nearbyWaypoints by toggle("nearby-waypoints") { true } + } + + + @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/diana/NearbyBurrowsSolver.kt b/src/main/kotlin/features/diana/NearbyBurrowsSolver.kt index 2fb4002..e1fb856 100644 --- a/src/main/kotlin/features/diana/NearbyBurrowsSolver.kt +++ b/src/main/kotlin/features/diana/NearbyBurrowsSolver.kt @@ -11,13 +11,11 @@ import moe.nea.firmament.events.ParticleSpawnEvent import moe.nea.firmament.events.ProcessChatEvent import moe.nea.firmament.events.WorldReadyEvent import moe.nea.firmament.events.WorldRenderLastEvent -import moe.nea.firmament.events.subscription.SubscriptionOwner -import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.util.TimeMark import moe.nea.firmament.util.collections.mutableMapWithMaxSize import moe.nea.firmament.util.render.RenderInWorldContext.Companion.renderInWorld -object NearbyBurrowsSolver : SubscriptionOwner { +object NearbyBurrowsSolver { private val recentlyDugBurrows: MutableMap<BlockPos, TimeMark> = mutableMapWithMaxSize(20) @@ -134,9 +132,6 @@ object NearbyBurrowsSolver : SubscriptionOwner { burrows.remove(blockPos) lastBlockClick = blockPos } - - override val delegateFeature: FirmamentFeature - get() = DianaWaypoints } fun Position.toBlockPos(): BlockPos { diff --git a/src/main/kotlin/features/events/anniversity/AnniversaryFeatures.kt b/src/main/kotlin/features/events/anniversity/AnniversaryFeatures.kt index e26b4c9..80b30ee 100644 --- a/src/main/kotlin/features/events/anniversity/AnniversaryFeatures.kt +++ b/src/main/kotlin/features/events/anniversity/AnniversaryFeatures.kt @@ -1,9 +1,7 @@ - package moe.nea.firmament.features.events.anniversity import io.github.notenoughupdates.moulconfig.observer.ObservableList import io.github.notenoughupdates.moulconfig.xml.Bind -import moe.nea.jarvis.api.Point import org.joml.Vector2i import kotlin.time.Duration.Companion.seconds import net.minecraft.entity.passive.PigEntity @@ -13,8 +11,6 @@ import moe.nea.firmament.events.EntityInteractionEvent import moe.nea.firmament.events.ProcessChatEvent import moe.nea.firmament.events.TickEvent import moe.nea.firmament.events.WorldReadyEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.gui.hud.MoulConfigHud import moe.nea.firmament.repo.ExpensiveItemCacheApi import moe.nea.firmament.repo.ItemNameLookup @@ -24,206 +20,204 @@ import moe.nea.firmament.util.SHORT_NUMBER_FORMAT import moe.nea.firmament.util.SkyblockId 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.parseShortNumber import moe.nea.firmament.util.useMatch -object AnniversaryFeatures : FirmamentFeature { - override val identifier: String - get() = "anniversary" +object AnniversaryFeatures { + val identifier: String + get() = "anniversary" @Config - object TConfig : ManagedConfig(identifier, Category.EVENTS) { - val enableShinyPigTracker by toggle("shiny-pigs") {true} - val trackPigCooldown by position("pig-hud", 200, 300) { Vector2i(100, 200) } - } - - override val config: ManagedConfig? - get() = TConfig - - data class ClickedPig( - val clickedAt: TimeMark, - val startLocation: BlockPos, - val pigEntity: PigEntity - ) { - @Bind("timeLeft") - fun getTimeLeft(): Double = 1 - clickedAt.passedTime() / pigDuration - } - - val clickedPigs = ObservableList<ClickedPig>(mutableListOf()) - var lastClickedPig: PigEntity? = null - - val pigDuration = 90.seconds - - @Subscribe - fun onTick(event: TickEvent) { - clickedPigs.removeIf { it.clickedAt.passedTime() > pigDuration } - } - - val pattern = "SHINY! You extracted (?<reward>.*) from the piglet's orb!".toPattern() - - @Subscribe - fun onChat(event: ProcessChatEvent) { - if(!TConfig.enableShinyPigTracker)return - if (event.unformattedString == "Oink! Bring the pig back to the Shiny Orb!") { - val pig = lastClickedPig ?: return - // TODO: store proper location based on the orb location, maybe - val startLocation = pig.blockPos ?: return - clickedPigs.add(ClickedPig(TimeMark.now(), startLocation, pig)) - lastClickedPig = null - } - if (event.unformattedString == "SHINY! The orb is charged! Click on it for loot!") { - val player = MC.player ?: return - val lowest = - clickedPigs.minByOrNull { it.startLocation.getSquaredDistance(player.pos) } ?: return - clickedPigs.remove(lowest) - } - pattern.useMatch(event.unformattedString) { - val reward = group("reward") - val parsedReward = parseReward(reward) - addReward(parsedReward) - PigCooldown.rewards.atOnce { - PigCooldown.rewards.clear() - rewards.mapTo(PigCooldown.rewards) { PigCooldown.DisplayReward(it) } - } - } - } - - fun addReward(reward: Reward) { - val it = rewards.listIterator() - while (it.hasNext()) { - val merged = reward.mergeWith(it.next()) ?: continue - it.set(merged) - return - } - rewards.add(reward) - } - - val rewards = mutableListOf<Reward>() - - fun <T> ObservableList<T>.atOnce(block: () -> Unit) { - val oldObserver = observer - observer = null - block() - observer = oldObserver - update() - } - - sealed interface Reward { - fun mergeWith(other: Reward): Reward? - data class EXP(val amount: Double, val skill: String) : Reward { - override fun mergeWith(other: Reward): Reward? { - if (other is EXP && other.skill == skill) - return EXP(amount + other.amount, skill) - return null - } - } - - data class Coins(val amount: Double) : Reward { - override fun mergeWith(other: Reward): Reward? { - if (other is Coins) - return Coins(other.amount + amount) - return null - } - } - - data class Items(val amount: Int, val item: SkyblockId) : Reward { - override fun mergeWith(other: Reward): Reward? { - if (other is Items && other.item == item) - return Items(amount + other.amount, item) - return null - } - } - - data class Unknown(val text: String) : Reward { - override fun mergeWith(other: Reward): Reward? { - return null - } - } - } - - val expReward = "\\+(?<exp>$SHORT_NUMBER_FORMAT) (?<kind>[^ ]+) XP".toPattern() - val coinReward = "(?i)\\+(?<amount>$SHORT_NUMBER_FORMAT) Coins".toPattern() - val itemReward = "(?:(?<amount>[0-9]+)x )?(?<name>.*)".toPattern() - fun parseReward(string: String): Reward { - expReward.useMatch<Unit>(string) { - val exp = parseShortNumber(group("exp")) - val kind = group("kind") - return Reward.EXP(exp, kind) - } - coinReward.useMatch<Unit>(string) { - val coins = parseShortNumber(group("amount")) - return Reward.Coins(coins) - } - itemReward.useMatch(string) { - val amount = group("amount")?.toIntOrNull() ?: 1 - val name = group("name") - val item = ItemNameLookup.guessItemByName(name, false) ?: return@useMatch - return Reward.Items(amount, item) - } - return Reward.Unknown(string) - } - - @Subscribe - fun onWorldClear(event: WorldReadyEvent) { - lastClickedPig = null - clickedPigs.clear() - } - - @Subscribe - fun onEntityClick(event: EntityInteractionEvent) { - if (event.entity is PigEntity) { - lastClickedPig = event.entity - } - } - - @Subscribe - fun init(event: WorldReadyEvent) { - PigCooldown.forceInit() - } - - object PigCooldown : MoulConfigHud("anniversary_pig", TConfig.trackPigCooldown) { - override fun shouldRender(): Boolean { - return clickedPigs.isNotEmpty() && TConfig.enableShinyPigTracker - } - - @Bind("pigs") - fun getPigs() = clickedPigs - - class DisplayReward(val backedBy: Reward) { - @Bind - fun count(): String { - return when (backedBy) { - is Reward.Coins -> backedBy.amount - is Reward.EXP -> backedBy.amount - is Reward.Items -> backedBy.amount - is Reward.Unknown -> 0 - }.toString() - } - - val itemStack = if (backedBy is Reward.Items) { - SBItemStack(backedBy.item, backedBy.amount) - } else { - SBItemStack(SkyblockId.NULL) - } - - @OptIn(ExpensiveItemCacheApi::class) + object TConfig : ManagedConfig(identifier, Category.EVENTS) { + val enableShinyPigTracker by toggle("shiny-pigs") { true } + val trackPigCooldown by position("pig-hud", 200, 300) { Vector2i(100, 200) } + } + + data class ClickedPig( + val clickedAt: TimeMark, + val startLocation: BlockPos, + val pigEntity: PigEntity + ) { + @Bind("timeLeft") + fun getTimeLeft(): Double = 1 - clickedAt.passedTime() / pigDuration + } + + val clickedPigs = ObservableList<ClickedPig>(mutableListOf()) + var lastClickedPig: PigEntity? = null + + val pigDuration = 90.seconds + + @Subscribe + fun onTick(event: TickEvent) { + clickedPigs.removeIf { it.clickedAt.passedTime() > pigDuration } + } + + val pattern = "SHINY! You extracted (?<reward>.*) from the piglet's orb!".toPattern() + + @Subscribe + fun onChat(event: ProcessChatEvent) { + if (!TConfig.enableShinyPigTracker) return + if (event.unformattedString == "Oink! Bring the pig back to the Shiny Orb!") { + val pig = lastClickedPig ?: return + // TODO: store proper location based on the orb location, maybe + val startLocation = pig.blockPos ?: return + clickedPigs.add(ClickedPig(TimeMark.now(), startLocation, pig)) + lastClickedPig = null + } + if (event.unformattedString == "SHINY! The orb is charged! Click on it for loot!") { + val player = MC.player ?: return + val lowest = + clickedPigs.minByOrNull { it.startLocation.getSquaredDistance(player.pos) } ?: return + clickedPigs.remove(lowest) + } + pattern.useMatch(event.unformattedString) { + val reward = group("reward") + val parsedReward = parseReward(reward) + addReward(parsedReward) + PigCooldown.rewards.atOnce { + PigCooldown.rewards.clear() + rewards.mapTo(PigCooldown.rewards) { PigCooldown.DisplayReward(it) } + } + } + } + + fun addReward(reward: Reward) { + val it = rewards.listIterator() + while (it.hasNext()) { + val merged = reward.mergeWith(it.next()) ?: continue + it.set(merged) + return + } + rewards.add(reward) + } + + val rewards = mutableListOf<Reward>() + + fun <T> ObservableList<T>.atOnce(block: () -> Unit) { + val oldObserver = observer + observer = null + block() + observer = oldObserver + update() + } + + sealed interface Reward { + fun mergeWith(other: Reward): Reward? + data class EXP(val amount: Double, val skill: String) : Reward { + override fun mergeWith(other: Reward): Reward? { + if (other is EXP && other.skill == skill) + return EXP(amount + other.amount, skill) + return null + } + } + + data class Coins(val amount: Double) : Reward { + override fun mergeWith(other: Reward): Reward? { + if (other is Coins) + return Coins(other.amount + amount) + return null + } + } + + data class Items(val amount: Int, val item: SkyblockId) : Reward { + override fun mergeWith(other: Reward): Reward? { + if (other is Items && other.item == item) + return Items(amount + other.amount, item) + return null + } + } + + data class Unknown(val text: String) : Reward { + override fun mergeWith(other: Reward): Reward? { + return null + } + } + } + + val expReward = "\\+(?<exp>$SHORT_NUMBER_FORMAT) (?<kind>[^ ]+) XP".toPattern() + val coinReward = "(?i)\\+(?<amount>$SHORT_NUMBER_FORMAT) Coins".toPattern() + val itemReward = "(?:(?<amount>[0-9]+)x )?(?<name>.*)".toPattern() + fun parseReward(string: String): Reward { + expReward.useMatch<Unit>(string) { + val exp = parseShortNumber(group("exp")) + val kind = group("kind") + return Reward.EXP(exp, kind) + } + coinReward.useMatch<Unit>(string) { + val coins = parseShortNumber(group("amount")) + return Reward.Coins(coins) + } + itemReward.useMatch(string) { + val amount = group("amount")?.toIntOrNull() ?: 1 + val name = group("name") + val item = ItemNameLookup.guessItemByName(name, false) ?: return@useMatch + return Reward.Items(amount, item) + } + return Reward.Unknown(string) + } + + @Subscribe + fun onWorldClear(event: WorldReadyEvent) { + lastClickedPig = null + clickedPigs.clear() + } + + @Subscribe + fun onEntityClick(event: EntityInteractionEvent) { + if (event.entity is PigEntity) { + lastClickedPig = event.entity + } + } + + @Subscribe + fun init(event: WorldReadyEvent) { + PigCooldown.forceInit() + } + + object PigCooldown : MoulConfigHud("anniversary_pig", TConfig.trackPigCooldown) { + override fun shouldRender(): Boolean { + return clickedPigs.isNotEmpty() && TConfig.enableShinyPigTracker + } + + @Bind("pigs") + fun getPigs() = clickedPigs + + class DisplayReward(val backedBy: Reward) { + @Bind + fun count(): String { + return when (backedBy) { + is Reward.Coins -> backedBy.amount + is Reward.EXP -> backedBy.amount + is Reward.Items -> backedBy.amount + is Reward.Unknown -> 0 + }.toString() + } + + val itemStack = if (backedBy is Reward.Items) { + SBItemStack(backedBy.item, backedBy.amount) + } else { + SBItemStack(SkyblockId.NULL) + } + + @OptIn(ExpensiveItemCacheApi::class) @Bind - fun name(): String { - return when (backedBy) { - is Reward.Coins -> "Coins" - is Reward.EXP -> backedBy.skill - is Reward.Items -> itemStack.asImmutableItemStack().name.string - is Reward.Unknown -> backedBy.text - } - } - - @Bind - fun isKnown() = backedBy !is Reward.Unknown - } - - @get:Bind("rewards") - val rewards = ObservableList<DisplayReward>(mutableListOf()) - - } + fun name(): String { + return when (backedBy) { + is Reward.Coins -> "Coins" + is Reward.EXP -> backedBy.skill + is Reward.Items -> itemStack.asImmutableItemStack().name.string + is Reward.Unknown -> backedBy.text + } + } + + @Bind + fun isKnown() = backedBy !is Reward.Unknown + } + + @get:Bind("rewards") + val rewards = ObservableList<DisplayReward>(mutableListOf()) + + } } diff --git a/src/main/kotlin/features/events/anniversity/CenturyRaffleFeatures.kt b/src/main/kotlin/features/events/anniversity/CenturyRaffleFeatures.kt index 9eb098a..13ecd7b 100644 --- a/src/main/kotlin/features/events/anniversity/CenturyRaffleFeatures.kt +++ b/src/main/kotlin/features/events/anniversity/CenturyRaffleFeatures.kt @@ -8,10 +8,10 @@ import net.minecraft.text.Style import net.minecraft.util.Formatting import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.EntityRenderTintEvent -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.render.TintedOverlayTexture import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyblock.SkyBlockItems diff --git a/src/main/kotlin/features/events/carnival/CarnivalFeatures.kt b/src/main/kotlin/features/events/carnival/CarnivalFeatures.kt index 877b54b..3f149ff 100644 --- a/src/main/kotlin/features/events/carnival/CarnivalFeatures.kt +++ b/src/main/kotlin/features/events/carnival/CarnivalFeatures.kt @@ -1,19 +1,16 @@ package moe.nea.firmament.features.events.carnival -import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.util.data.Config import moe.nea.firmament.util.data.ManagedConfig -object CarnivalFeatures : FirmamentFeature { +object CarnivalFeatures { @Config object TConfig : ManagedConfig(identifier, Category.EVENTS) { val enableBombSolver by toggle("bombs-solver") { true } val displayTutorials by toggle("tutorials") { true } } - override val config: ManagedConfig? - get() = TConfig - override val identifier: String + val identifier: String get() = "carnival" } diff --git a/src/main/kotlin/features/fixes/CompatibliltyFeatures.kt b/src/main/kotlin/features/fixes/CompatibliltyFeatures.kt index 1858e87..55592c5 100644 --- a/src/main/kotlin/features/fixes/CompatibliltyFeatures.kt +++ b/src/main/kotlin/features/fixes/CompatibliltyFeatures.kt @@ -4,13 +4,12 @@ import net.minecraft.particle.ParticleTypes import net.minecraft.util.math.Vec3d import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ParticleSpawnEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.compatloader.CompatLoader import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig -object CompatibliltyFeatures : FirmamentFeature { - override val identifier: String +object CompatibliltyFeatures { + val identifier: String get() = "compatibility" @Config @@ -19,9 +18,6 @@ object CompatibliltyFeatures : FirmamentFeature { val explosionSize by integer("explosion-power", 10, 50) { 1 } } - override val config: ManagedConfig? - get() = TConfig - interface ExplosiveApiWrapper { fun spawnParticle(vec3d: Vec3d, power: Float) diff --git a/src/main/kotlin/features/fixes/Fixes.kt b/src/main/kotlin/features/fixes/Fixes.kt index d3876a7..e7027ac 100644 --- a/src/main/kotlin/features/fixes/Fixes.kt +++ b/src/main/kotlin/features/fixes/Fixes.kt @@ -8,14 +8,13 @@ import net.minecraft.text.Text import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.HudRenderEvent import moe.nea.firmament.events.WorldKeyboardEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig 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.tr -object Fixes : FirmamentFeature { - override val identifier: String +object Fixes { + val identifier: String get() = "fixes" @Config @@ -34,9 +33,6 @@ object Fixes : FirmamentFeature { val hideOffHand by toggle("hide-off-hand") { false } } - override val config: ManagedConfig - get() = TConfig - fun handleIsPressed( keyBinding: KeyBinding, cir: CallbackInfoReturnable<Boolean> diff --git a/src/main/kotlin/features/garden/HideComposterNoises.kt b/src/main/kotlin/features/garden/HideComposterNoises.kt index 2e8eb76..843e4f9 100644 --- a/src/main/kotlin/features/garden/HideComposterNoises.kt +++ b/src/main/kotlin/features/garden/HideComposterNoises.kt @@ -5,10 +5,10 @@ import net.minecraft.sound.SoundEvent import net.minecraft.sound.SoundEvents import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.SoundReceiveEvent -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SkyBlockIsland import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig object HideComposterNoises { @Config diff --git a/src/main/kotlin/features/inventory/CraftingOverlay.kt b/src/main/kotlin/features/inventory/CraftingOverlay.kt index f823086..30d2c6b 100644 --- a/src/main/kotlin/features/inventory/CraftingOverlay.kt +++ b/src/main/kotlin/features/inventory/CraftingOverlay.kt @@ -7,13 +7,12 @@ import net.minecraft.util.Formatting import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ScreenChangeEvent import moe.nea.firmament.events.SlotRenderEvents -import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.repo.ExpensiveItemCacheApi import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.util.MC import moe.nea.firmament.util.skyblockId -object CraftingOverlay : FirmamentFeature { +object CraftingOverlay { private var screen: GenericContainerScreen? = null private var recipe: NEUCraftingRecipe? = null @@ -43,7 +42,7 @@ object CraftingOverlay : FirmamentFeature { } } - override val identifier: String + val identifier: String get() = "crafting-overlay" @OptIn(ExpensiveItemCacheApi::class) diff --git a/src/main/kotlin/features/inventory/ItemHotkeys.kt b/src/main/kotlin/features/inventory/ItemHotkeys.kt index c6b5ca6..e9d0631 100644 --- a/src/main/kotlin/features/inventory/ItemHotkeys.kt +++ b/src/main/kotlin/features/inventory/ItemHotkeys.kt @@ -2,16 +2,15 @@ package moe.nea.firmament.features.inventory import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.HandledScreenKeyPressedEvent -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.repo.ExpensiveItemCacheApi import moe.nea.firmament.repo.HypixelStaticData -import moe.nea.firmament.repo.ItemCache import moe.nea.firmament.repo.ItemCache.asItemStack import moe.nea.firmament.repo.ItemCache.isBroken import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.MC import moe.nea.firmament.util.asBazaarStock import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.focusedItemStack import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyblock.SBItemUtil.getSearchName diff --git a/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt b/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt index 196f948..7a474f9 100644 --- a/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt +++ b/src/main/kotlin/features/inventory/ItemRarityCosmetics.kt @@ -3,24 +3,17 @@ package moe.nea.firmament.features.inventory import java.awt.Color import net.minecraft.client.gl.RenderPipelines import net.minecraft.client.gui.DrawContext -import net.minecraft.client.render.RenderLayer import net.minecraft.item.ItemStack -import net.minecraft.util.Formatting import net.minecraft.util.Identifier import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.HotbarItemRenderEvent import moe.nea.firmament.events.SlotRenderEvents -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig -import moe.nea.firmament.util.collections.lastNotNullOfOrNull -import moe.nea.firmament.util.collections.memoizeIdentity import moe.nea.firmament.util.data.Config -import moe.nea.firmament.util.mc.loreAccordingToNbt +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.skyblock.Rarity -import moe.nea.firmament.util.unformattedString -object ItemRarityCosmetics : FirmamentFeature { - override val identifier: String +object ItemRarityCosmetics { + val identifier: String get() = "item-rarity-cosmetics" @Config @@ -29,9 +22,6 @@ object ItemRarityCosmetics : FirmamentFeature { val showItemRarityInHotbar by toggle("background-hotbar") { false } } - override val config: ManagedConfig - get() = TConfig - private val rarityToColor = Rarity.colourMap.mapValues { val c = Color(it.value.colorValue!!) c.rgb diff --git a/src/main/kotlin/features/inventory/JunkHighlighter.kt b/src/main/kotlin/features/inventory/JunkHighlighter.kt index e5ab036..45d265e 100644 --- a/src/main/kotlin/features/inventory/JunkHighlighter.kt +++ b/src/main/kotlin/features/inventory/JunkHighlighter.kt @@ -3,14 +3,13 @@ package moe.nea.firmament.features.inventory import org.lwjgl.glfw.GLFW import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.SlotRenderEvents -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.skyblock.SBItemUtil.getSearchName import moe.nea.firmament.util.useMatch -object JunkHighlighter : FirmamentFeature { - override val identifier: String +object JunkHighlighter { + val identifier: String get() = "junk-highlighter" @Config @@ -21,7 +20,7 @@ object JunkHighlighter : FirmamentFeature { @Subscribe fun onDrawSlot(event: SlotRenderEvents.After) { - if(!TConfig.highlightBind.isPressed() || TConfig.junkRegex.isEmpty()) return + if (!TConfig.highlightBind.isPressed() || TConfig.junkRegex.isEmpty()) return val junkRegex = TConfig.junkRegex.toPattern() val slot = event.slot junkRegex.useMatch(slot.stack.getSearchName()) { diff --git a/src/main/kotlin/features/inventory/PetFeatures.kt b/src/main/kotlin/features/inventory/PetFeatures.kt index 5df4bc4..965e705 100644 --- a/src/main/kotlin/features/inventory/PetFeatures.kt +++ b/src/main/kotlin/features/inventory/PetFeatures.kt @@ -8,14 +8,13 @@ import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.HudRenderEvent import moe.nea.firmament.events.SlotRenderEvents -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.jarvis.JarvisIntegration import moe.nea.firmament.util.FirmFormatters.formatPercent import moe.nea.firmament.util.FirmFormatters.shortFormat 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.petData import moe.nea.firmament.util.render.drawGuiTexture import moe.nea.firmament.util.skyblock.Rarity @@ -23,13 +22,10 @@ import moe.nea.firmament.util.titleCase import moe.nea.firmament.util.useMatch import moe.nea.firmament.util.withColor -object PetFeatures : FirmamentFeature { - override val identifier: String +object PetFeatures { + val identifier: String get() = "pets" - override val config: ManagedConfig? - get() = TConfig - @Config object TConfig : ManagedConfig(identifier, Category.INVENTORY) { val highlightEquippedPet by toggle("highlight-pet") { true } diff --git a/src/main/kotlin/features/inventory/PriceData.kt b/src/main/kotlin/features/inventory/PriceData.kt index ce5c7ea..5f9268e 100644 --- a/src/main/kotlin/features/inventory/PriceData.kt +++ b/src/main/kotlin/features/inventory/PriceData.kt @@ -5,22 +5,21 @@ import net.minecraft.text.Text import net.minecraft.util.StringIdentifiable import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ItemTooltipEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.repo.HypixelStaticData import moe.nea.firmament.util.FirmFormatters.formatCommas import moe.nea.firmament.util.asBazaarStock import moe.nea.firmament.util.bold import moe.nea.firmament.util.darkGrey import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.getLogicalStackSize import moe.nea.firmament.util.gold import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.tr import moe.nea.firmament.util.yellow -object PriceData : FirmamentFeature { - override val identifier: String +object PriceData { + val identifier: String get() = "price-data" @Config @@ -46,8 +45,6 @@ object PriceData : FirmamentFeature { } } - override val config get() = TConfig - fun formatPrice(label: Text, price: Double): Text { return Text.literal("") .yellow() diff --git a/src/main/kotlin/features/inventory/REIDependencyWarner.kt b/src/main/kotlin/features/inventory/REIDependencyWarner.kt index 4bb93ee..9e8a4db 100644 --- a/src/main/kotlin/features/inventory/REIDependencyWarner.kt +++ b/src/main/kotlin/features/inventory/REIDependencyWarner.kt @@ -52,7 +52,7 @@ object REIDependencyWarner { @Subscribe fun checkREIDependency(event: SkyblockServerUpdateEvent) { if (!SBData.isOnSkyblock) return - if (!RepoManager.Config.warnForMissingItemListMod) return + if (!RepoManager.TConfig.warnForMissingItemListMod) return if (hasREI) return if (sentWarning) return sentWarning = true @@ -76,8 +76,8 @@ object REIDependencyWarner { if (hasREI) return event.subcommand("disablereiwarning") { thenExecute { - RepoManager.Config.warnForMissingItemListMod = false - RepoManager.Config.markDirty() + RepoManager.TConfig.warnForMissingItemListMod = false + RepoManager.TConfig.markDirty() MC.sendChat(Text.translatable("firmament.reiwarning.disabled").yellow()) } } diff --git a/src/main/kotlin/features/inventory/SaveCursorPosition.kt b/src/main/kotlin/features/inventory/SaveCursorPosition.kt index 2a08730..3e55d02 100644 --- a/src/main/kotlin/features/inventory/SaveCursorPosition.kt +++ b/src/main/kotlin/features/inventory/SaveCursorPosition.kt @@ -1,64 +1,57 @@ - - package moe.nea.firmament.features.inventory import org.lwjgl.glfw.GLFW import kotlin.math.absoluteValue import kotlin.time.Duration.Companion.milliseconds -import net.minecraft.client.util.InputUtil -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.TimeMark import moe.nea.firmament.util.assertNotNullOr import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig -object SaveCursorPosition : FirmamentFeature { - override val identifier: String - get() = "save-cursor-position" +object SaveCursorPosition { + val identifier: String + get() = "save-cursor-position" @Config - object TConfig : ManagedConfig(identifier, Category.INVENTORY) { - val enable by toggle("enable") { true } - val tolerance by duration("tolerance", 10.milliseconds, 5000.milliseconds) { 500.milliseconds } - } - - override val config: TConfig - get() = TConfig - - var savedPositionedP1: Pair<Double, Double>? = null - var savedPosition: SavedPosition? = null - - data class SavedPosition( - val middle: Pair<Double, Double>, - val cursor: Pair<Double, Double>, - val savedAt: TimeMark = TimeMark.now() - ) - - @JvmStatic - fun saveCursorOriginal(positionedX: Double, positionedY: Double) { - savedPositionedP1 = Pair(positionedX, positionedY) - } - - @JvmStatic - fun loadCursor(middleX: Double, middleY: Double): Pair<Double, Double>? { - if (!TConfig.enable) return null - val lastPosition = savedPosition?.takeIf { it.savedAt.passedTime() < TConfig.tolerance } - savedPosition = null - if (lastPosition != null && - (lastPosition.middle.first - middleX).absoluteValue < 1 && - (lastPosition.middle.second - middleY).absoluteValue < 1 - ) { + object TConfig : ManagedConfig(identifier, Category.INVENTORY) { + val enable by toggle("enable") { true } + val tolerance by duration("tolerance", 10.milliseconds, 5000.milliseconds) { 500.milliseconds } + } + + var savedPositionedP1: Pair<Double, Double>? = null + var savedPosition: SavedPosition? = null + + data class SavedPosition( + val middle: Pair<Double, Double>, + val cursor: Pair<Double, Double>, + val savedAt: TimeMark = TimeMark.now() + ) + + @JvmStatic + fun saveCursorOriginal(positionedX: Double, positionedY: Double) { + savedPositionedP1 = Pair(positionedX, positionedY) + } + + @JvmStatic + fun loadCursor(middleX: Double, middleY: Double): Pair<Double, Double>? { + if (!TConfig.enable) return null + val lastPosition = savedPosition?.takeIf { it.savedAt.passedTime() < TConfig.tolerance } + savedPosition = null + if (lastPosition != null && + (lastPosition.middle.first - middleX).absoluteValue < 1 && + (lastPosition.middle.second - middleY).absoluteValue < 1 + ) { GLFW.glfwSetCursorPos(MC.window.handle, lastPosition.cursor.first, lastPosition.cursor.second); - return lastPosition.cursor - } - return null - } - - @JvmStatic - fun saveCursorMiddle(middleX: Double, middleY: Double) { - if (!TConfig.enable) return - val cursorPos = assertNotNullOr(savedPositionedP1) { return } - savedPosition = SavedPosition(Pair(middleX, middleY), cursorPos) - } + return lastPosition.cursor + } + return null + } + + @JvmStatic + fun saveCursorMiddle(middleX: Double, middleY: Double) { + if (!TConfig.enable) return + val cursorPos = assertNotNullOr(savedPositionedP1) { return } + savedPosition = SavedPosition(Pair(middleX, middleY), cursorPos) + } } diff --git a/src/main/kotlin/features/inventory/SlotLocking.kt b/src/main/kotlin/features/inventory/SlotLocking.kt index 8be7bdb..bae6a5e 100644 --- a/src/main/kotlin/features/inventory/SlotLocking.kt +++ b/src/main/kotlin/features/inventory/SlotLocking.kt @@ -26,15 +26,13 @@ import net.minecraft.screen.slot.SlotActionType import net.minecraft.util.Identifier import net.minecraft.util.StringIdentifiable import moe.nea.firmament.annotations.Subscribe -import moe.nea.firmament.events.FeaturesInitializedEvent +import moe.nea.firmament.events.ClientInitEvent import moe.nea.firmament.events.HandledScreenForegroundEvent import moe.nea.firmament.events.HandledScreenKeyPressedEvent import moe.nea.firmament.events.HandledScreenKeyReleasedEvent import moe.nea.firmament.events.IsSlotProtectedEvent import moe.nea.firmament.events.ScreenChangeEvent import moe.nea.firmament.events.SlotRenderEvents -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.keybindings.InputModifiers import moe.nea.firmament.keybindings.SavedKeyBinding import moe.nea.firmament.mixins.accessor.AccessorHandledScreen @@ -43,6 +41,7 @@ import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SkyBlockIsland import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.data.ProfileSpecificDataHolder import moe.nea.firmament.util.extraAttributes import moe.nea.firmament.util.json.DashlessUUIDSerializer @@ -60,8 +59,8 @@ import moe.nea.firmament.util.skyblockUUID import moe.nea.firmament.util.tr import moe.nea.firmament.util.unformattedString -object SlotLocking : FirmamentFeature { - override val identifier: String +object SlotLocking { + val identifier: String get() = "slot-locking" @Serializable @@ -166,15 +165,14 @@ object SlotLocking : FirmamentFeature { } } - override val config: TConfig - get() = TConfig - + @Config object DConfig : ProfileSpecificDataHolder<Data>(serializer(), "locked-slots", ::Data) val lockedUUIDs get() = DConfig.data?.lockedUUIDs val lockedSlots get() = currentWorldData?.lockedSlots + fun isSalvageScreen(screen: HandledScreen<*>?): Boolean { if (screen == null) return false return screen.title.unformattedString.contains("Salvage Item") @@ -259,7 +257,7 @@ object SlotLocking : FirmamentFeature { } @Subscribe - fun onEvent(event: FeaturesInitializedEvent) { + fun onEvent(event: ClientInitEvent) { IsSlotProtectedEvent.subscribe(receivesCancelled = true, "SlotLocking:unlockInDungeons") { if (it.isProtected && it.origin == IsSlotProtectedEvent.MoveOrigin.DROP_FROM_HOTBAR diff --git a/src/main/kotlin/features/inventory/TimerInLore.kt b/src/main/kotlin/features/inventory/TimerInLore.kt index eb1463b..d8eebda 100644 --- a/src/main/kotlin/features/inventory/TimerInLore.kt +++ b/src/main/kotlin/features/inventory/TimerInLore.kt @@ -11,10 +11,10 @@ import net.minecraft.text.Text import net.minecraft.util.StringIdentifiable import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ItemTooltipEvent -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.SBData import moe.nea.firmament.util.aqua 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.mc.displayNameAccordingToNbt import moe.nea.firmament.util.timestamp diff --git a/src/main/kotlin/features/inventory/WardrobeKeybinds.kt b/src/main/kotlin/features/inventory/WardrobeKeybinds.kt index ca5ff3a..cdd646e 100644 --- a/src/main/kotlin/features/inventory/WardrobeKeybinds.kt +++ b/src/main/kotlin/features/inventory/WardrobeKeybinds.kt @@ -4,10 +4,9 @@ import org.lwjgl.glfw.GLFW import net.minecraft.item.Items import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.HandledScreenKeyPressedEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig 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.mc.SlotUtils.clickLeftMouseButton object WardrobeKeybinds { diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtonTemplates.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtonTemplates.kt index d282157..082673e 100644 --- a/src/main/kotlin/features/inventory/buttons/InventoryButtonTemplates.kt +++ b/src/main/kotlin/features/inventory/buttons/InventoryButtonTemplates.kt @@ -1,6 +1,5 @@ package moe.nea.firmament.features.inventory.buttons -import kotlinx.serialization.encodeToString import net.minecraft.text.Text import moe.nea.firmament.Firmament import moe.nea.firmament.util.ErrorUtil diff --git a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt index f49e6ab..47fdbe9 100644 --- a/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt +++ b/src/main/kotlin/features/inventory/buttons/InventoryButtons.kt @@ -1,5 +1,3 @@ - - package moe.nea.firmament.features.inventory.buttons import me.shedaniel.math.Rectangle @@ -13,32 +11,33 @@ import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.HandledScreenClickEvent import moe.nea.firmament.events.HandledScreenForegroundEvent import moe.nea.firmament.events.HandledScreenPushREIEvent -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.ScreenUtil import moe.nea.firmament.util.TimeMark -import moe.nea.firmament.util.data.DataHolder import moe.nea.firmament.util.accessors.getRectangle import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.DataHolder +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.gold object InventoryButtons { @Config - object TConfig : ManagedConfig("inventory-buttons-config", Category.INVENTORY) { - val _openEditor by button("open-editor") { - openEditor() - } + object TConfig : ManagedConfig("inventory-buttons-config", Category.INVENTORY) { + val _openEditor by button("open-editor") { + openEditor() + } val hoverText by toggle("hover-text") { true } val onlyInv by toggle("only-inv") { false } - } + } - object DConfig : DataHolder<Data>(serializer(), "inventory-buttons", ::Data) + @Config + object DConfig : DataHolder<Data>(serializer(), "inventory-buttons", ::Data) - @Serializable - data class Data( - var buttons: MutableList<InventoryButton> = mutableListOf() - ) + @Serializable + data class Data( + var buttons: MutableList<InventoryButton> = mutableListOf() + ) fun getValidButtons(screen: HandledScreen<*>): Sequence<InventoryButton> { return DConfig.data.buttons.asSequence().filter { button -> @@ -47,41 +46,41 @@ object InventoryButtons { } - @Subscribe - fun onRectangles(it: HandledScreenPushREIEvent) { - val bounds = it.screen.getRectangle() - for (button in getValidButtons(it.screen)) { - val buttonBounds = button.getBounds(bounds) - it.block(buttonBounds) - } - } + @Subscribe + fun onRectangles(it: HandledScreenPushREIEvent) { + val bounds = it.screen.getRectangle() + for (button in getValidButtons(it.screen)) { + val buttonBounds = button.getBounds(bounds) + it.block(buttonBounds) + } + } - @Subscribe - fun onClickScreen(it: HandledScreenClickEvent) { - val bounds = it.screen.getRectangle() - for (button in getValidButtons(it.screen)) { - val buttonBounds = button.getBounds(bounds) - if (buttonBounds.contains(it.mouseX, it.mouseY)) { - MC.sendCommand(button.command!! /* non null invariant covered by getValidButtons */) - break - } - } - } + @Subscribe + fun onClickScreen(it: HandledScreenClickEvent) { + val bounds = it.screen.getRectangle() + for (button in getValidButtons(it.screen)) { + val buttonBounds = button.getBounds(bounds) + if (buttonBounds.contains(it.mouseX, it.mouseY)) { + MC.sendCommand(button.command!! /* non null invariant covered by getValidButtons */) + break + } + } + } var lastHoveredComponent: InventoryButton? = null var lastMouseMove = TimeMark.farPast() - @Subscribe - fun onRenderForeground(it: HandledScreenForegroundEvent) { + @Subscribe + fun onRenderForeground(it: HandledScreenForegroundEvent) { val bounds = it.screen.getRectangle() var hoveredComponent: InventoryButton? = null for (button in getValidButtons(it.screen)) { - val buttonBounds = button.getBounds(bounds) - it.context.matrices.pushMatrix() - it.context.matrices.translate(buttonBounds.minX.toFloat(), buttonBounds.minY.toFloat()) - button.render(it.context) - it.context.matrices.popMatrix() + val buttonBounds = button.getBounds(bounds) + it.context.matrices.pushMatrix() + it.context.matrices.translate(buttonBounds.minX.toFloat(), buttonBounds.minY.toFloat()) + button.render(it.context) + it.context.matrices.popMatrix() if (buttonBounds.contains(it.mouseX, it.mouseY) && TConfig.hoverText && hoveredComponent == null) { hoveredComponent = button @@ -94,23 +93,23 @@ object InventoryButtons { ) } } - } + } if (hoveredComponent !== lastHoveredComponent) lastMouseMove = TimeMark.now() lastHoveredComponent = hoveredComponent - lastRectangle = bounds - } + lastRectangle = bounds + } - var lastRectangle: Rectangle? = null - fun openEditor() { - ScreenUtil.setScreenLater( - InventoryButtonEditor( - lastRectangle ?: Rectangle( - MC.window.scaledWidth / 2 - 88, - MC.window.scaledHeight / 2 - 83, - 176, 166, - ) - ) - ) - } + var lastRectangle: Rectangle? = null + fun openEditor() { + ScreenUtil.setScreenLater( + InventoryButtonEditor( + lastRectangle ?: Rectangle( + MC.window.scaledWidth / 2 - 88, + MC.window.scaledHeight / 2 - 83, + 176, 166, + ) + ) + ) + } } diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt index 3734024..6043335 100644 --- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt +++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverlay.kt @@ -13,19 +13,18 @@ import moe.nea.firmament.events.ScreenChangeEvent import moe.nea.firmament.events.SlotClickEvent import moe.nea.firmament.events.SlotRenderEvents import moe.nea.firmament.events.TickEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.customgui.customGui import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.data.ProfileSpecificDataHolder -object StorageOverlay : FirmamentFeature { - +object StorageOverlay { + @Config object Data : ProfileSpecificDataHolder<StorageData>(serializer(), "storage-data", ::StorageData) - override val identifier: String + val identifier: String get() = "storage-overlay" @Config @@ -86,9 +85,6 @@ object StorageOverlay : FirmamentFeature { return amount * TConfig.scrollSpeed * (if (TConfig.inverseScroll) 1 else -1) } - override val config: TConfig - get() = TConfig - var lastStorageOverlay: StorageOverviewScreen? = null var skipNextStorageOverlayBackflip = false var currentHandler: StorageBackingHandle? = null diff --git a/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt b/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt index e383d29..65d7e8c 100644 --- a/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt +++ b/src/main/kotlin/features/inventory/storageoverlay/StorageOverviewScreen.kt @@ -53,18 +53,18 @@ class StorageOverviewScreen() : Screen(Text.empty()) { inline fun layoutedForEach(onEach: (data: Pair<StoragePageSlot, StorageData.StorageInventory>, offsetX: Int, offsetY: Int) -> Unit) { var offsetY = 0 - var currentMaxHeight = StorageOverlay.config.margin - StorageOverlay.config.padding - scroll + var currentMaxHeight = StorageOverlay.TConfig.margin - StorageOverlay.TConfig.padding - scroll var totalHeight = -currentMaxHeight content.storageInventories.onEachIndexed { index, (key, value) -> - val pageX = (index % StorageOverlay.config.columns) + val pageX = (index % StorageOverlay.TConfig.columns) if (pageX == 0) { - currentMaxHeight += StorageOverlay.config.padding + currentMaxHeight += StorageOverlay.TConfig.padding offsetY += currentMaxHeight totalHeight += currentMaxHeight currentMaxHeight = 0 } val xPosition = - width / 2 - (StorageOverlay.config.columns * (pageWidth + StorageOverlay.config.padding) - StorageOverlay.config.padding) / 2 + pageX * (pageWidth + StorageOverlay.config.padding) + width / 2 - (StorageOverlay.TConfig.columns * (pageWidth + StorageOverlay.TConfig.padding) - StorageOverlay.TConfig.padding) / 2 + pageX * (pageWidth + StorageOverlay.TConfig.padding) onEach(Pair(key, value), xPosition, offsetY) val height = getStorePageHeight(value) currentMaxHeight = max(currentMaxHeight, height) @@ -102,7 +102,7 @@ class StorageOverviewScreen() : Screen(Text.empty()) { return true } - private fun getMaxScroll() = lastRenderedHeight - height + 2 * StorageOverlay.config.margin + private fun getMaxScroll() = lastRenderedHeight - height + 2 * StorageOverlay.TConfig.margin private fun renderStoragePage(context: DrawContext, page: StorageData.StorageInventory, mouseX: Int, mouseY: Int) { context.drawText(MC.font, page.title, 2, 2, -1, true) diff --git a/src/main/kotlin/features/inventory/storageoverlay/VirtualInventory.kt b/src/main/kotlin/features/inventory/storageoverlay/VirtualInventory.kt index d99acd7..83e0d19 100644 --- a/src/main/kotlin/features/inventory/storageoverlay/VirtualInventory.kt +++ b/src/main/kotlin/features/inventory/storageoverlay/VirtualInventory.kt @@ -18,7 +18,6 @@ import net.minecraft.nbt.NbtIo import net.minecraft.nbt.NbtList import net.minecraft.nbt.NbtOps import net.minecraft.nbt.NbtSizeTracker -import net.minecraft.registry.RegistryOps import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.MC import moe.nea.firmament.util.mc.TolerantRegistriesOps diff --git a/src/main/kotlin/features/items/BlockZapperOverlay.kt b/src/main/kotlin/features/items/BlockZapperOverlay.kt index ad96b8e..a853012 100644 --- a/src/main/kotlin/features/items/BlockZapperOverlay.kt +++ b/src/main/kotlin/features/items/BlockZapperOverlay.kt @@ -9,19 +9,17 @@ import net.minecraft.util.hit.BlockHitResult import net.minecraft.util.hit.HitResult import net.minecraft.util.math.BlockPos import moe.nea.firmament.annotations.Subscribe -import moe.nea.firmament.events.ClientStartedEvent import moe.nea.firmament.events.WorldKeyboardEvent import moe.nea.firmament.events.WorldRenderLastEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig 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.RenderInWorldContext import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyblock.SkyBlockItems -object BlockZapperOverlay : FirmamentFeature { - override val identifier: String +object BlockZapperOverlay { + val identifier: String get() = "block-zapper-overlay" @Config @@ -31,13 +29,6 @@ object BlockZapperOverlay : FirmamentFeature { var undoKey by keyBindingWithDefaultUnbound("undo-key") } - @Subscribe - fun onInit(event: ClientStartedEvent) { - } - - override val config: ManagedConfig - get() = TConfig - val bannedZapper: List<Block> = listOf<Block>( Blocks.WHEAT, Blocks.CARROTS, diff --git a/src/main/kotlin/features/items/BonemerangOverlay.kt b/src/main/kotlin/features/items/BonemerangOverlay.kt index 80019c0..1310154 100644 --- a/src/main/kotlin/features/items/BonemerangOverlay.kt +++ b/src/main/kotlin/features/items/BonemerangOverlay.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.features.items import me.shedaniel.math.Color -import moe.nea.jarvis.api.Point import org.joml.Vector2i import net.minecraft.entity.LivingEntity import net.minecraft.entity.decoration.ArmorStandEntity @@ -9,20 +8,18 @@ import net.minecraft.entity.player.PlayerEntity import net.minecraft.util.Formatting import net.minecraft.util.math.Box import moe.nea.firmament.annotations.Subscribe -import moe.nea.firmament.events.ClientStartedEvent import moe.nea.firmament.events.EntityRenderTintEvent import moe.nea.firmament.events.HudRenderEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig 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.TintedOverlayTexture import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyblock.SkyBlockItems import moe.nea.firmament.util.tr -object BonemerangOverlay : FirmamentFeature { - override val identifier: String +object BonemerangOverlay { + val identifier: String get() = "bonemerang-overlay" @Config @@ -32,13 +29,6 @@ object BonemerangOverlay : FirmamentFeature { var highlightHitEntities by toggle("highlight-hit-entities") { false } } - @Subscribe - fun onInit(event: ClientStartedEvent) { - } - - override val config: ManagedConfig - get() = TConfig - fun getEntities(): MutableSet<LivingEntity> { val entities = mutableSetOf<LivingEntity>() val camera = MC.camera as? PlayerEntity ?: return entities diff --git a/src/main/kotlin/features/items/EtherwarpOverlay.kt b/src/main/kotlin/features/items/EtherwarpOverlay.kt index 640c8f5..ba712b3 100644 --- a/src/main/kotlin/features/items/EtherwarpOverlay.kt +++ b/src/main/kotlin/features/items/EtherwarpOverlay.kt @@ -13,19 +13,18 @@ import net.minecraft.util.math.Vec3d import net.minecraft.world.BlockView import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.WorldRenderLastEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig 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.extraAttributes import moe.nea.firmament.util.render.RenderInWorldContext import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyblock.SkyBlockItems import moe.nea.firmament.util.tr -object EtherwarpOverlay : FirmamentFeature { - override val identifier: String +object EtherwarpOverlay { + val identifier: String get() = "etherwarp-overlay" @Config @@ -41,9 +40,6 @@ object EtherwarpOverlay : FirmamentFeature { var failureText by toggle("failure-text") { false } } - override val config: ManagedConfig - get() = TConfig - enum class EtherwarpResult(val label: Text?, val color: () -> ChromaColour) { SUCCESS(null, TConfig::cubeColour), INTERACTION_BLOCKED( diff --git a/src/main/kotlin/features/macros/ComboProcessor.kt b/src/main/kotlin/features/macros/ComboProcessor.kt index 2b979c3..a01f8b7 100644 --- a/src/main/kotlin/features/macros/ComboProcessor.kt +++ b/src/main/kotlin/features/macros/ComboProcessor.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.features.macros import kotlin.time.Duration.Companion.seconds -import net.minecraft.client.util.InputUtil import net.minecraft.text.Text import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.HudRenderEvent diff --git a/src/main/kotlin/features/macros/MacroData.kt b/src/main/kotlin/features/macros/MacroData.kt index 447516e..af1b0e8 100644 --- a/src/main/kotlin/features/macros/MacroData.kt +++ b/src/main/kotlin/features/macros/MacroData.kt @@ -1,6 +1,7 @@ package moe.nea.firmament.features.macros import kotlinx.serialization.Serializable +import moe.nea.firmament.util.data.Config import moe.nea.firmament.util.data.DataHolder @Serializable @@ -8,6 +9,7 @@ data class MacroData( var comboActions: List<ComboKeyAction> = listOf(), var wheels: List<MacroWheel> = listOf(), ) { + @Config object DConfig : DataHolder<MacroData>(kotlinx.serialization.serializer(), "macros", ::MacroData) { override fun onLoad() { ComboProcessor.setActions(data.comboActions) diff --git a/src/main/kotlin/features/mining/CommissionFeatures.kt b/src/main/kotlin/features/mining/CommissionFeatures.kt index 05658cc..1041ae5 100644 --- a/src/main/kotlin/features/mining/CommissionFeatures.kt +++ b/src/main/kotlin/features/mining/CommissionFeatures.kt @@ -3,9 +3,9 @@ package moe.nea.firmament.features.mining import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.SlotRenderEvents -import moe.nea.firmament.util.data.ManagedConfig 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.mc.loreAccordingToNbt import moe.nea.firmament.util.unformattedString diff --git a/src/main/kotlin/features/mining/Histogram.kt b/src/main/kotlin/features/mining/Histogram.kt index ed48437..08ee893 100644 --- a/src/main/kotlin/features/mining/Histogram.kt +++ b/src/main/kotlin/features/mining/Histogram.kt @@ -1,7 +1,8 @@ package moe.nea.firmament.features.mining -import java.util.* +import java.util.NavigableMap +import java.util.TreeMap import kotlin.time.Duration import moe.nea.firmament.util.TimeMark diff --git a/src/main/kotlin/features/mining/HotmPresets.kt b/src/main/kotlin/features/mining/HotmPresets.kt index 763364e..aa45d82 100644 --- a/src/main/kotlin/features/mining/HotmPresets.kt +++ b/src/main/kotlin/features/mining/HotmPresets.kt @@ -18,7 +18,6 @@ import moe.nea.firmament.events.ChestInventoryUpdateEvent import moe.nea.firmament.events.CommandEvent import moe.nea.firmament.events.ScreenChangeEvent import moe.nea.firmament.events.SlotRenderEvents -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.mixins.accessor.AccessorHandledScreen import moe.nea.firmament.util.ClipboardUtils import moe.nea.firmament.util.MC diff --git a/src/main/kotlin/features/mining/MiningBlockInfoUi.kt b/src/main/kotlin/features/mining/MiningBlockInfoUi.kt index 5b58d4f..f4def44 100644 --- a/src/main/kotlin/features/mining/MiningBlockInfoUi.kt +++ b/src/main/kotlin/features/mining/MiningBlockInfoUi.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.features.mining import io.github.notenoughupdates.moulconfig.observer.ObservableList -import io.github.notenoughupdates.moulconfig.observer.Property import io.github.notenoughupdates.moulconfig.platform.MoulConfigPlatform import io.github.notenoughupdates.moulconfig.xml.Bind import net.minecraft.client.gui.screen.Screen diff --git a/src/main/kotlin/features/mining/PickaxeAbility.kt b/src/main/kotlin/features/mining/PickaxeAbility.kt index 3acdcc3..5bd85c5 100644 --- a/src/main/kotlin/features/mining/PickaxeAbility.kt +++ b/src/main/kotlin/features/mining/PickaxeAbility.kt @@ -18,8 +18,6 @@ import moe.nea.firmament.events.ProfileSwitchEvent import moe.nea.firmament.events.SlotClickEvent import moe.nea.firmament.events.UseItemEvent import moe.nea.firmament.events.WorldReadyEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.DurabilityBarEvent import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData @@ -28,6 +26,7 @@ import moe.nea.firmament.util.SkyBlockIsland import moe.nea.firmament.util.TIME_PATTERN 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.extraAttributes import moe.nea.firmament.util.mc.displayNameAccordingToNbt import moe.nea.firmament.util.mc.loreAccordingToNbt @@ -44,8 +43,8 @@ import moe.nea.firmament.util.tr import moe.nea.firmament.util.unformattedString import moe.nea.firmament.util.useMatch -object PickaxeAbility : FirmamentFeature { - override val identifier: String +object PickaxeAbility { + val identifier: String get() = "pickaxe-info" enum class ShowOnTools(val label: String, val items: Set<ItemType>) : StringIdentifiable { @@ -102,9 +101,6 @@ object PickaxeAbility : FirmamentFeature { val destructiveAbilities = setOf("Pickobulus") val pickaxeTypes = setOf(ItemType.PICKAXE, ItemType.DRILL, ItemType.GAUNTLET) - override val config: ManagedConfig - get() = TConfig - fun getCooldownPercentage(name: String, cooldown: Duration): Double { val sinceLastUsage = lastUsage[name]?.passedTime() ?: Duration.INFINITE val sinceLobbyJoin = lobbyJoinTime.passedTime() diff --git a/src/main/kotlin/features/mining/PristineProfitTracker.kt b/src/main/kotlin/features/mining/PristineProfitTracker.kt index e63a107..ad864c1 100644 --- a/src/main/kotlin/features/mining/PristineProfitTracker.kt +++ b/src/main/kotlin/features/mining/PristineProfitTracker.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.features.mining import io.github.notenoughupdates.moulconfig.xml.Bind -import moe.nea.jarvis.api.Point import org.joml.Vector2i import kotlinx.serialization.Serializable import kotlinx.serialization.serializer @@ -9,20 +8,19 @@ import kotlin.time.Duration.Companion.seconds import net.minecraft.text.Text import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ProcessChatEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.gui.hud.MoulConfigHud import moe.nea.firmament.util.BazaarPriceStrategy import moe.nea.firmament.util.FirmFormatters.formatCommas import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.StringUtil.parseIntWithComma import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.data.ProfileSpecificDataHolder import moe.nea.firmament.util.formattedString import moe.nea.firmament.util.useMatch -object PristineProfitTracker : FirmamentFeature { - override val identifier: String +object PristineProfitTracker { + val identifier: String get() = "pristine-profit" enum class GemstoneKind( @@ -52,11 +50,9 @@ object PristineProfitTracker : FirmamentFeature { var maxCollectionPerSecond: Double = 1.0, ) + @Config object DConfig : ProfileSpecificDataHolder<Data>(serializer(), identifier, ::Data) - override val config: ManagedConfig? - get() = TConfig - @Config object TConfig : ManagedConfig(identifier, Category.MINING) { val timeout by duration("timeout", 0.seconds, 120.seconds) { 30.seconds } @@ -117,20 +113,18 @@ object PristineProfitTracker : FirmamentFeature { formatCommas(moneyPerSecond * SECONDS_PER_HOUR, 1)) .formattedString() val data = DConfig.data - if (data != null) { - if (data.maxCollectionPerSecond < collectionPerSecond && collectionHistogram.oldestUpdate() - .passedTime() > 30.seconds - ) { - data.maxCollectionPerSecond = collectionPerSecond - DConfig.markDirty() - } - if (data.maxMoneyPerSecond < moneyPerSecond && moneyHistogram.oldestUpdate().passedTime() > 30.seconds) { - data.maxMoneyPerSecond = moneyPerSecond - DConfig.markDirty() - } - ProfitHud.collectionMax = maxOf(data.maxCollectionPerSecond, collectionPerSecond) - ProfitHud.moneyMax = maxOf(data.maxMoneyPerSecond, moneyPerSecond) + if (data.maxCollectionPerSecond < collectionPerSecond && collectionHistogram.oldestUpdate() + .passedTime() > 30.seconds + ) { + data.maxCollectionPerSecond = collectionPerSecond + DConfig.markDirty() + } + if (data.maxMoneyPerSecond < moneyPerSecond && moneyHistogram.oldestUpdate().passedTime() > 30.seconds) { + data.maxMoneyPerSecond = moneyPerSecond + DConfig.markDirty() } + ProfitHud.collectionMax = maxOf(data.maxCollectionPerSecond, collectionPerSecond) + ProfitHud.moneyMax = maxOf(data.maxMoneyPerSecond, moneyPerSecond) } diff --git a/src/main/kotlin/features/misc/CustomCapes.kt b/src/main/kotlin/features/misc/CustomCapes.kt index f59f715..086f2fb 100644 --- a/src/main/kotlin/features/misc/CustomCapes.kt +++ b/src/main/kotlin/features/misc/CustomCapes.kt @@ -1,36 +1,25 @@ package moe.nea.firmament.features.misc -import com.mojang.blaze3d.buffers.GpuBuffer -import com.mojang.blaze3d.buffers.Std140Builder -import com.mojang.blaze3d.systems.RenderSystem -import java.nio.ByteBuffer -import java.nio.ByteOrder -import java.util.OptionalDouble -import java.util.OptionalInt -import org.joml.Vector4f import util.render.CustomRenderPipelines import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds import net.minecraft.client.network.AbstractClientPlayerEntity -import net.minecraft.client.render.BufferBuilder import net.minecraft.client.render.RenderLayer import net.minecraft.client.render.VertexConsumer import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.entity.state.PlayerEntityRenderState -import net.minecraft.client.util.BufferAllocator import net.minecraft.client.util.SkinTextures import net.minecraft.client.util.math.MatrixStack import net.minecraft.util.Identifier import moe.nea.firmament.Firmament -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig 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.mc.CustomRenderPassHelper -object CustomCapes : FirmamentFeature { - override val identifier: String +object CustomCapes { + val identifier: String get() = "developer-capes" @Config @@ -38,9 +27,6 @@ object CustomCapes : FirmamentFeature { val showCapes by toggle("show-cape") { true } } - override val config: ManagedConfig - get() = TConfig - interface CustomCapeRenderer { fun replaceRender( renderLayer: RenderLayer, diff --git a/src/main/kotlin/features/misc/Hud.kt b/src/main/kotlin/features/misc/Hud.kt index 272c349..fb7c6cd 100644 --- a/src/main/kotlin/features/misc/Hud.kt +++ b/src/main/kotlin/features/misc/Hud.kt @@ -1,19 +1,17 @@ package moe.nea.firmament.features.misc -import moe.nea.firmament.annotations.Subscribe -import moe.nea.firmament.events.HudRenderEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig -import moe.nea.firmament.util.MC -import moe.nea.firmament.util.tr -import moe.nea.jarvis.api.Point import org.joml.Vector2i import net.minecraft.client.network.PlayerListEntry import net.minecraft.text.Text +import moe.nea.firmament.annotations.Subscribe +import moe.nea.firmament.events.HudRenderEvent +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.tr -object Hud : FirmamentFeature { - override val identifier: String +object Hud { + val identifier: String get() = "hud" @Config @@ -26,9 +24,6 @@ object Hud : FirmamentFeature { val pingCountHud by position("ping-count-hud", 80, 10) { Vector2i() } } - override val config: ManagedConfig - get() = TConfig - @Subscribe fun onRenderHud(it: HudRenderEvent) { if (TConfig.dayCount) { diff --git a/src/main/kotlin/features/misc/ModAnnouncer.kt b/src/main/kotlin/features/misc/ModAnnouncer.kt index 0eae9d7..1047353 100644 --- a/src/main/kotlin/features/misc/ModAnnouncer.kt +++ b/src/main/kotlin/features/misc/ModAnnouncer.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.features.misc import io.netty.buffer.ByteBuf -import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents import net.fabricmc.fabric.api.networking.v1.PacketByteBufs import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry import net.fabricmc.loader.api.FabricLoader diff --git a/src/main/kotlin/features/notifications/Notifications.kt b/src/main/kotlin/features/notifications/Notifications.kt deleted file mode 100644 index 8d912d1..0000000 --- a/src/main/kotlin/features/notifications/Notifications.kt +++ /dev/null @@ -1,7 +0,0 @@ - -package moe.nea.firmament.features.notifications - -import moe.nea.firmament.features.FirmamentFeature - -object Notifications { -} diff --git a/src/main/kotlin/features/world/FairySouls.kt b/src/main/kotlin/features/world/FairySouls.kt index 477fbe6..9191a80 100644 --- a/src/main/kotlin/features/world/FairySouls.kt +++ b/src/main/kotlin/features/world/FairySouls.kt @@ -1,133 +1,123 @@ - - package moe.nea.firmament.features.world import io.github.moulberry.repo.data.Coordinate import me.shedaniel.math.Color import kotlinx.serialization.Serializable import kotlinx.serialization.serializer -import net.minecraft.text.Text -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Vec3d import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.ProcessChatEvent import moe.nea.firmament.events.SkyblockServerUpdateEvent import moe.nea.firmament.events.WorldRenderLastEvent -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.SBData import moe.nea.firmament.util.SkyBlockIsland import moe.nea.firmament.util.blockPos import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.data.ProfileSpecificDataHolder -import moe.nea.firmament.util.render.RenderInWorldContext import moe.nea.firmament.util.render.RenderInWorldContext.Companion.renderInWorld import moe.nea.firmament.util.unformattedString -object FairySouls : FirmamentFeature { - +object FairySouls { - @Serializable - data class Data( - val foundSouls: MutableMap<SkyBlockIsland, MutableSet<Int>> = mutableMapOf() - ) - override val config: ManagedConfig - get() = TConfig + @Serializable + data class Data( + val foundSouls: MutableMap<SkyBlockIsland, MutableSet<Int>> = mutableMapOf() + ) @Config - object DConfig : ProfileSpecificDataHolder<Data>(serializer(), "found-fairysouls", ::Data) + object DConfig : ProfileSpecificDataHolder<Data>(serializer(), "found-fairysouls", ::Data) @Config - object TConfig : ManagedConfig("fairy-souls", Category.MISC) { - val displaySouls by toggle("show") { false } - val resetSouls by button("reset") { - DConfig.data?.foundSouls?.clear() != null - updateMissingSouls() - } - } - - - override val identifier: String get() = "fairy-souls" - - val playerReach = 5 - val playerReachSquared = playerReach * playerReach - - var currentLocationName: SkyBlockIsland? = null - var currentLocationSouls: List<Coordinate> = emptyList() - var currentMissingSouls: List<Coordinate> = emptyList() - - fun updateMissingSouls() { - currentMissingSouls = emptyList() - val c = DConfig.data ?: return - val fi = c.foundSouls[currentLocationName] ?: setOf() - val cms = currentLocationSouls.toMutableList() - fi.asSequence().sortedDescending().filter { it in cms.indices }.forEach { cms.removeAt(it) } - currentMissingSouls = cms - } - - fun updateWorldSouls() { - currentLocationSouls = emptyList() - val loc = currentLocationName ?: return - currentLocationSouls = RepoManager.neuRepo.constants.fairySouls.soulLocations[loc.locrawMode] ?: return - } - - fun findNearestClickableSoul(): Coordinate? { - val player = MC.player ?: return null - val pos = player.pos - val location = SBData.skyblockLocation ?: return null - val soulLocations: List<Coordinate> = - RepoManager.neuRepo.constants.fairySouls.soulLocations[location.locrawMode] ?: return null - return soulLocations - .map { it to it.blockPos.getSquaredDistance(pos) } - .filter { it.second < playerReachSquared } - .minByOrNull { it.second } - ?.first - } - - private fun markNearestSoul() { - val nearestSoul = findNearestClickableSoul() ?: return - val c = DConfig.data ?: return - val loc = currentLocationName ?: return - val idx = currentLocationSouls.indexOf(nearestSoul) - c.foundSouls.computeIfAbsent(loc) { mutableSetOf() }.add(idx) - DConfig.markDirty() - updateMissingSouls() - } - - @Subscribe - fun onWorldRender(it: WorldRenderLastEvent) { - if (!TConfig.displaySouls) return - renderInWorld(it) { - currentMissingSouls.forEach { - block(it.blockPos, Color.ofRGBA(176, 0, 255, 128).color) - } - currentLocationSouls.forEach { - wireframeCube(it.blockPos) - } - } - } - - @Subscribe - fun onProcessChat(it: ProcessChatEvent) { - when (it.text.unformattedString) { - "You have already found that Fairy Soul!" -> { - markNearestSoul() - } - - "SOUL! You found a Fairy Soul!" -> { - markNearestSoul() - } - } - } - - @Subscribe - fun onLocationChange(it: SkyblockServerUpdateEvent) { - currentLocationName = it.newLocraw?.skyblockLocation - updateWorldSouls() - updateMissingSouls() - } + object TConfig : ManagedConfig("fairy-souls", Category.MISC) { + val displaySouls by toggle("show") { false } + val resetSouls by button("reset") { + DConfig.data?.foundSouls?.clear() != null + updateMissingSouls() + } + } + + + val identifier: String get() = "fairy-souls" + + val playerReach = 5 + val playerReachSquared = playerReach * playerReach + + var currentLocationName: SkyBlockIsland? = null + var currentLocationSouls: List<Coordinate> = emptyList() + var currentMissingSouls: List<Coordinate> = emptyList() + + fun updateMissingSouls() { + currentMissingSouls = emptyList() + val c = DConfig.data ?: return + val fi = c.foundSouls[currentLocationName] ?: setOf() + val cms = currentLocationSouls.toMutableList() + fi.asSequence().sortedDescending().filter { it in cms.indices }.forEach { cms.removeAt(it) } + currentMissingSouls = cms + } + + fun updateWorldSouls() { + currentLocationSouls = emptyList() + val loc = currentLocationName ?: return + currentLocationSouls = RepoManager.neuRepo.constants.fairySouls.soulLocations[loc.locrawMode] ?: return + } + + fun findNearestClickableSoul(): Coordinate? { + val player = MC.player ?: return null + val pos = player.pos + val location = SBData.skyblockLocation ?: return null + val soulLocations: List<Coordinate> = + RepoManager.neuRepo.constants.fairySouls.soulLocations[location.locrawMode] ?: return null + return soulLocations + .map { it to it.blockPos.getSquaredDistance(pos) } + .filter { it.second < playerReachSquared } + .minByOrNull { it.second } + ?.first + } + + private fun markNearestSoul() { + val nearestSoul = findNearestClickableSoul() ?: return + val c = DConfig.data ?: return + val loc = currentLocationName ?: return + val idx = currentLocationSouls.indexOf(nearestSoul) + c.foundSouls.computeIfAbsent(loc) { mutableSetOf() }.add(idx) + DConfig.markDirty() + updateMissingSouls() + } + + @Subscribe + fun onWorldRender(it: WorldRenderLastEvent) { + if (!TConfig.displaySouls) return + renderInWorld(it) { + currentMissingSouls.forEach { + block(it.blockPos, Color.ofRGBA(176, 0, 255, 128).color) + } + currentLocationSouls.forEach { + wireframeCube(it.blockPos) + } + } + } + + @Subscribe + fun onProcessChat(it: ProcessChatEvent) { + when (it.text.unformattedString) { + "You have already found that Fairy Soul!" -> { + markNearestSoul() + } + + "SOUL! You found a Fairy Soul!" -> { + markNearestSoul() + } + } + } + + @Subscribe + fun onLocationChange(it: SkyblockServerUpdateEvent) { + currentLocationName = it.newLocraw?.skyblockLocation + updateWorldSouls() + updateMissingSouls() + } } diff --git a/src/main/kotlin/features/world/TemporaryWaypoints.kt b/src/main/kotlin/features/world/TemporaryWaypoints.kt index 3c8e895..f5653ad 100644 --- a/src/main/kotlin/features/world/TemporaryWaypoints.kt +++ b/src/main/kotlin/features/world/TemporaryWaypoints.kt @@ -1,8 +1,6 @@ package moe.nea.firmament.features.world import me.shedaniel.math.Color -import kotlin.compareTo -import kotlin.text.clear import kotlin.time.Duration.Companion.seconds import net.minecraft.text.Text import net.minecraft.util.math.BlockPos diff --git a/src/main/kotlin/features/world/Waypoints.kt b/src/main/kotlin/features/world/Waypoints.kt index 72bd9e8..318b6c2 100644 --- a/src/main/kotlin/features/world/Waypoints.kt +++ b/src/main/kotlin/features/world/Waypoints.kt @@ -16,16 +16,15 @@ import moe.nea.firmament.events.CommandEvent import moe.nea.firmament.events.TickEvent import moe.nea.firmament.events.WorldReadyEvent import moe.nea.firmament.events.WorldRenderLastEvent -import moe.nea.firmament.features.FirmamentFeature -import moe.nea.firmament.util.data.ManagedConfig 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.mc.asFakeServer import moe.nea.firmament.util.render.RenderInWorldContext import moe.nea.firmament.util.tr -object Waypoints : FirmamentFeature { - override val identifier: String +object Waypoints { + val identifier: String get() = "waypoints" @Config @@ -37,7 +36,6 @@ object Waypoints : FirmamentFeature { // TODO: look ahead size } - override val config get() = TConfig var waypoints: FirmWaypoints? = null var orderedIndex = 0 @@ -56,11 +54,13 @@ object Waypoints : FirmamentFeature { orderedIndex %= w.waypoints.size val firstColor = Color.ofRGBA(0, 200, 40, 180) tracer(w.waypoints[orderedIndex].blockPos.toCenterPos(), color = firstColor.color, lineWidth = 3f) - w.waypoints.withIndex().toList().wrappingWindow(orderedIndex, 3).zip(listOf( - firstColor, - Color.ofRGBA(180, 200, 40, 150), - Color.ofRGBA(180, 80, 20, 140), - )).reversed().forEach { (waypoint, col) -> + w.waypoints.withIndex().toList().wrappingWindow(orderedIndex, 3).zip( + listOf( + firstColor, + Color.ofRGBA(180, 200, 40, 150), + Color.ofRGBA(180, 80, 20, 140), + ) + ).reversed().forEach { (waypoint, col) -> val (index, pos) = waypoint block(pos.blockPos, col.color) if (TConfig.showIndex) withFacingThePlayer(pos.blockPos.toCenterPos()) { @@ -123,10 +123,14 @@ object Waypoints : FirmamentFeature { val position = pos.get(this).toAbsoluteBlockPos(source.asFakeServer()) val w = useEditableWaypoints() w.waypoints.add(FirmWaypoints.Waypoint.from(position)) - source.sendFeedback(Text.stringifiedTranslatable("firmament.command.waypoint.added", - position.x, - position.y, - position.z)) + source.sendFeedback( + Text.stringifiedTranslatable( + "firmament.command.waypoint.added", + position.x, + position.y, + position.z + ) + ) } } } @@ -134,9 +138,12 @@ object Waypoints : FirmamentFeature { thenLiteral("reset") { thenExecute { orderedIndex = 0 - source.sendFeedback(tr( - "firmament.command.waypoint.reset", - "Reset your ordered waypoint index back to 0. If you want to delete all waypoints use /firm waypoints clear instead.")) + source.sendFeedback( + tr( + "firmament.command.waypoint.reset", + "Reset your ordered waypoint index back to 0. If you want to delete all waypoints use /firm waypoints clear instead." + ) + ) } } thenLiteral("changeindex") { @@ -158,10 +165,13 @@ object Waypoints : FirmamentFeature { w.waypoints.add( if (toIndex > fromIndex) toIndex - 1 else toIndex, - waypoint) + waypoint + ) source.sendFeedback( - tr("firmament.command.waypoint.indexchange", - "Moved waypoint from index $fromIndex to $toIndex. Note that this only matters for ordered waypoints.") + tr( + "firmament.command.waypoint.indexchange", + "Moved waypoint from index $fromIndex to $toIndex. Note that this only matters for ordered waypoints." + ) ) } } @@ -203,8 +213,12 @@ object Waypoints : FirmamentFeature { val w = useNonEmptyWaypoints() if (w != null && index in w.waypoints.indices) { w.waypoints.removeAt(index) - source.sendFeedback(Text.stringifiedTranslatable("firmament.command.waypoint.remove", - index)) + source.sendFeedback( + Text.stringifiedTranslatable( + "firmament.command.waypoint.remove", + index + ) + ) } else { source.sendError(Text.stringifiedTranslatable("firmament.command.waypoint.remove.error")) } @@ -215,12 +229,16 @@ object Waypoints : FirmamentFeature { } fun textInvalidIndex(index: Int) = - tr("firmament.command.waypoint.invalid-index", - "Invalid index $index provided.") + tr( + "firmament.command.waypoint.invalid-index", + "Invalid index $index provided." + ) fun textNothingToExport(): Text = - tr("firmament.command.waypoint.export.nowaypoints", - "No waypoints to export found. Add some with /firm waypoint ~ ~ ~.") + tr( + "firmament.command.waypoint.export.nowaypoints", + "No waypoints to export found. Add some with /firm waypoint ~ ~ ~." + ) } fun <E> List<E>.wrappingWindow(startIndex: Int, windowSize: Int): List<E> { diff --git a/src/main/kotlin/gui/BarComponent.kt b/src/main/kotlin/gui/BarComponent.kt index 751ea39..b144e0d 100644 --- a/src/main/kotlin/gui/BarComponent.kt +++ b/src/main/kotlin/gui/BarComponent.kt @@ -1,17 +1,13 @@ package moe.nea.firmament.gui -import com.mojang.blaze3d.systems.RenderSystem import io.github.notenoughupdates.moulconfig.common.MyResourceLocation -import io.github.notenoughupdates.moulconfig.common.RenderContext import io.github.notenoughupdates.moulconfig.gui.GuiComponent import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext import io.github.notenoughupdates.moulconfig.observer.GetSetter -import io.github.notenoughupdates.moulconfig.platform.MoulConfigPlatform import io.github.notenoughupdates.moulconfig.platform.MoulConfigRenderContext import me.shedaniel.math.Color import net.minecraft.client.gl.RenderPipelines import net.minecraft.client.gui.DrawContext -import net.minecraft.client.render.RenderLayer import net.minecraft.util.Identifier import moe.nea.firmament.Firmament diff --git a/src/main/kotlin/gui/CheckboxComponent.kt b/src/main/kotlin/gui/CheckboxComponent.kt index 7a9f2ef..4d29a96 100644 --- a/src/main/kotlin/gui/CheckboxComponent.kt +++ b/src/main/kotlin/gui/CheckboxComponent.kt @@ -6,7 +6,6 @@ import io.github.notenoughupdates.moulconfig.gui.MouseEvent import io.github.notenoughupdates.moulconfig.observer.GetSetter import io.github.notenoughupdates.moulconfig.platform.MoulConfigRenderContext import net.minecraft.client.gl.RenderPipelines -import net.minecraft.client.render.RenderLayer import moe.nea.firmament.Firmament class CheckboxComponent<T>( diff --git a/src/main/kotlin/gui/config/AllConfigsGui.kt b/src/main/kotlin/gui/config/AllConfigsGui.kt index 0add10f..345269d 100644 --- a/src/main/kotlin/gui/config/AllConfigsGui.kt +++ b/src/main/kotlin/gui/config/AllConfigsGui.kt @@ -10,11 +10,11 @@ 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.util.data.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.MoulConfigUtils import moe.nea.firmament.util.ScreenUtil.setScreenLater import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig object AllConfigsGui { // diff --git a/src/main/kotlin/gui/config/ChoiceHandler.kt b/src/main/kotlin/gui/config/ChoiceHandler.kt index 9c3dda2..321b40d 100644 --- a/src/main/kotlin/gui/config/ChoiceHandler.kt +++ b/src/main/kotlin/gui/config/ChoiceHandler.kt @@ -9,8 +9,8 @@ import kotlinx.serialization.json.JsonElement import kotlin.jvm.optionals.getOrNull import net.minecraft.util.StringIdentifiable import moe.nea.firmament.gui.CheckboxComponent -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.ErrorUtil +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.json.KJsonOps class ChoiceHandler<E>( diff --git a/src/main/kotlin/gui/config/DurationHandler.kt b/src/main/kotlin/gui/config/DurationHandler.kt index 4800bf6..0fc945f 100644 --- a/src/main/kotlin/gui/config/DurationHandler.kt +++ b/src/main/kotlin/gui/config/DurationHandler.kt @@ -12,12 +12,11 @@ import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.long -import moe.nea.firmament.util.data.ManagedConfig import kotlin.time.Duration import kotlin.time.DurationUnit import kotlin.time.toDuration -import net.minecraft.text.Text import moe.nea.firmament.util.FirmFormatters +import moe.nea.firmament.util.data.ManagedConfig class DurationHandler(val config: ManagedConfig, val min: Duration, val max: Duration) : ManagedConfig.OptionHandler<Duration> { diff --git a/src/main/kotlin/gui/config/HudMetaHandler.kt b/src/main/kotlin/gui/config/HudMetaHandler.kt index dcf5d8f..fae827d 100644 --- a/src/main/kotlin/gui/config/HudMetaHandler.kt +++ b/src/main/kotlin/gui/config/HudMetaHandler.kt @@ -10,9 +10,9 @@ import net.minecraft.text.MutableText import net.minecraft.text.Text import moe.nea.firmament.Firmament import moe.nea.firmament.gui.FirmButtonComponent -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.ManagedConfig class HudMetaHandler( val config: ManagedConfig, diff --git a/src/main/kotlin/gui/config/IntegerHandler.kt b/src/main/kotlin/gui/config/IntegerHandler.kt index 3e7be57..ab0237a 100644 --- a/src/main/kotlin/gui/config/IntegerHandler.kt +++ b/src/main/kotlin/gui/config/IntegerHandler.kt @@ -12,8 +12,8 @@ import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.int import kotlinx.serialization.json.jsonPrimitive -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.FirmFormatters +import moe.nea.firmament.util.data.ManagedConfig class IntegerHandler(val config: ManagedConfig, val min: Int, val max: Int) : ManagedConfig.OptionHandler<Int> { override fun toJson(element: Int): JsonElement? { diff --git a/src/main/kotlin/gui/config/KeyBindingHandler.kt b/src/main/kotlin/gui/config/KeyBindingHandler.kt index a5e626d..3c08da2 100644 --- a/src/main/kotlin/gui/config/KeyBindingHandler.kt +++ b/src/main/kotlin/gui/config/KeyBindingHandler.kt @@ -1,19 +1,13 @@ package moe.nea.firmament.gui.config -import io.github.notenoughupdates.moulconfig.common.IMinecraft -import io.github.notenoughupdates.moulconfig.common.MyResourceLocation -import io.github.notenoughupdates.moulconfig.deps.libninepatch.NinePatch -import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext -import io.github.notenoughupdates.moulconfig.gui.KeyboardEvent -import io.github.notenoughupdates.moulconfig.gui.component.TextComponent import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.encodeToJsonElement import moe.nea.firmament.gui.FirmButtonComponent -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.keybindings.FirmamentKeyBindings import moe.nea.firmament.keybindings.SavedKeyBinding +import moe.nea.firmament.util.data.ManagedConfig class KeyBindingHandler(val name: String, val managedConfig: ManagedConfig) : ManagedConfig.OptionHandler<SavedKeyBinding> { diff --git a/src/main/kotlin/gui/config/ManagedOption.kt b/src/main/kotlin/gui/config/ManagedOption.kt index 888b3f1..1f742a7 100644 --- a/src/main/kotlin/gui/config/ManagedOption.kt +++ b/src/main/kotlin/gui/config/ManagedOption.kt @@ -3,11 +3,11 @@ package moe.nea.firmament.gui.config import io.github.notenoughupdates.moulconfig.observer.GetSetter import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonObject -import moe.nea.firmament.util.data.ManagedConfig import kotlin.properties.ReadWriteProperty import kotlin.reflect.KProperty import net.minecraft.text.Text import moe.nea.firmament.util.ErrorUtil +import moe.nea.firmament.util.data.ManagedConfig class ManagedOption<T : Any>( val element: ManagedConfig, diff --git a/src/main/kotlin/gui/config/StringHandler.kt b/src/main/kotlin/gui/config/StringHandler.kt index da14d4b..f1eacab 100644 --- a/src/main/kotlin/gui/config/StringHandler.kt +++ b/src/main/kotlin/gui/config/StringHandler.kt @@ -7,8 +7,8 @@ import io.github.notenoughupdates.moulconfig.observer.GetSetter import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonPrimitive import kotlinx.serialization.json.jsonPrimitive -import moe.nea.firmament.util.data.ManagedConfig import net.minecraft.text.Text +import moe.nea.firmament.util.data.ManagedConfig class StringHandler(val config: ManagedConfig) : ManagedConfig.OptionHandler<String> { override fun toJson(element: String): JsonElement? { diff --git a/src/main/kotlin/gui/config/storage/ConfigLoadContext.kt b/src/main/kotlin/gui/config/storage/ConfigLoadContext.kt index 59afaa1..59ca71e 100644 --- a/src/main/kotlin/gui/config/storage/ConfigLoadContext.kt +++ b/src/main/kotlin/gui/config/storage/ConfigLoadContext.kt @@ -27,13 +27,15 @@ data class ConfigLoadContext( } fun logInfo(message: String) { - Firmament.logger.info("[ConfigUpgrade] $message") + if (Firmament.DEBUG) + Firmament.logger.info("[ConfigUpgrade] $message") logBuffer.append("[INFO] ").append(message).appendLine() } fun logError(message: String, exception: Throwable) { markShouldSaveLogBuffer() - Firmament.logger.error("[ConfigUpgrade] $message", exception) + if (Firmament.DEBUG) + Firmament.logger.error("[ConfigUpgrade] $message", exception) logBuffer.append("[ERROR] ").append(message).appendLine() PrintWriter(StringBuilderWriter(logBuffer)).use { exception.printStackTrace(it) @@ -51,6 +53,16 @@ data class ConfigLoadContext( path.createParentDirectories() } + fun use(block: (ConfigLoadContext) -> Unit) { + try { + block(this) + } catch (ex: Exception) { + logError("Caught exception on CLC", ex) + } finally { + close() + } + } + override fun close() { logInfo("Closing out config load.") if (shouldSaveLogBuffer) { diff --git a/src/main/kotlin/gui/config/storage/FirmamentConfigLoader.kt b/src/main/kotlin/gui/config/storage/FirmamentConfigLoader.kt index 22cba2c..f8e3104 100644 --- a/src/main/kotlin/gui/config/storage/FirmamentConfigLoader.kt +++ b/src/main/kotlin/gui/config/storage/FirmamentConfigLoader.kt @@ -102,7 +102,7 @@ object FirmamentConfigLoader { } fun saveAll() { - ConfigLoadContext("load-${System.currentTimeMillis()}").use { context -> + ConfigLoadContext("save-${System.currentTimeMillis()}").use { context -> saveStorage( ConfigStorageClass.CONFIG, Unit, @@ -198,7 +198,7 @@ object FirmamentConfigLoader { } fun markDirty(holder: IDataHolder<*>) { - TODO("Not yet implemented") + saveAll() } } diff --git a/src/main/kotlin/gui/config/storage/LegacyImporter.kt b/src/main/kotlin/gui/config/storage/LegacyImporter.kt index 8915c17..942fd2a 100644 --- a/src/main/kotlin/gui/config/storage/LegacyImporter.kt +++ b/src/main/kotlin/gui/config/storage/LegacyImporter.kt @@ -1,10 +1,7 @@ package moe.nea.firmament.gui.config.storage import java.nio.file.Path -import javax.xml.namespace.QName -import kotlin.io.path.Path import kotlin.io.path.copyTo -import kotlin.io.path.copyToRecursively import kotlin.io.path.createDirectories import kotlin.io.path.createParentDirectories import kotlin.io.path.exists diff --git a/src/main/kotlin/gui/entity/GuiPlayer.kt b/src/main/kotlin/gui/entity/GuiPlayer.kt index cc6580d..e7f2e45 100644 --- a/src/main/kotlin/gui/entity/GuiPlayer.kt +++ b/src/main/kotlin/gui/entity/GuiPlayer.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.gui.entity import com.mojang.authlib.GameProfile -import com.mojang.authlib.GameProfileRepository import java.util.UUID import net.minecraft.client.network.AbstractClientPlayerEntity import net.minecraft.client.util.DefaultSkinHelper @@ -9,7 +8,6 @@ import net.minecraft.client.util.SkinTextures import net.minecraft.client.util.SkinTextures.Model import net.minecraft.client.world.ClientWorld import net.minecraft.util.Identifier -import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import net.minecraft.world.World diff --git a/src/main/kotlin/gui/entity/ModifyEquipment.kt b/src/main/kotlin/gui/entity/ModifyEquipment.kt index 2ef5007..b2c6e5b 100644 --- a/src/main/kotlin/gui/entity/ModifyEquipment.kt +++ b/src/main/kotlin/gui/entity/ModifyEquipment.kt @@ -11,8 +11,8 @@ import net.minecraft.item.Items import moe.nea.firmament.repo.ExpensiveItemCacheApi import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.util.SkyblockId -import moe.nea.firmament.util.mc.setEncodedSkullOwner import moe.nea.firmament.util.mc.arbitraryUUID +import moe.nea.firmament.util.mc.setEncodedSkullOwner object ModifyEquipment : EntityModifier { val names = mapOf( diff --git a/src/main/kotlin/gui/entity/ModifyHorse.kt b/src/main/kotlin/gui/entity/ModifyHorse.kt index 7c8baa7..c797f14 100644 --- a/src/main/kotlin/gui/entity/ModifyHorse.kt +++ b/src/main/kotlin/gui/entity/ModifyHorse.kt @@ -2,9 +2,6 @@ package moe.nea.firmament.gui.entity import com.google.gson.JsonNull import com.google.gson.JsonObject -import kotlin.experimental.and -import kotlin.experimental.inv -import kotlin.experimental.or import net.minecraft.entity.EntityType import net.minecraft.entity.EquipmentSlot import net.minecraft.entity.LivingEntity diff --git a/src/main/kotlin/jarvis/JarvisIntegration.kt b/src/main/kotlin/jarvis/JarvisIntegration.kt index 0dc75e4..18c46c9 100644 --- a/src/main/kotlin/jarvis/JarvisIntegration.kt +++ b/src/main/kotlin/jarvis/JarvisIntegration.kt @@ -9,10 +9,10 @@ import moe.nea.jarvis.api.JarvisPlugin import net.minecraft.client.gui.screen.Screen import net.minecraft.text.Text import moe.nea.firmament.Firmament -import moe.nea.firmament.features.FeatureManager import moe.nea.firmament.gui.config.HudMeta import moe.nea.firmament.gui.config.HudMetaHandler -import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.gui.config.storage.FirmamentConfigLoader +import moe.nea.firmament.util.data.ManagedConfig class JarvisIntegration : JarvisPlugin { override fun getModId(): String = @@ -27,9 +27,7 @@ class JarvisIntegration : JarvisPlugin { } val configs - get() = listOf( - RepoManager.Config - ) + FeatureManager.allFeatures.mapNotNull { it.config } + get() = FirmamentConfigLoader.allConfigs.filterIsInstance<ManagedConfig>() override fun getAllHuds(): List<JarvisHud> { diff --git a/src/main/kotlin/repo/ItemCache.kt b/src/main/kotlin/repo/ItemCache.kt index 72549e9..0aa4a44 100644 --- a/src/main/kotlin/repo/ItemCache.kt +++ b/src/main/kotlin/repo/ItemCache.kt @@ -39,7 +39,6 @@ import moe.nea.firmament.features.debug.ExportedTestConstantMeta import moe.nea.firmament.repo.RepoManager.initialize import moe.nea.firmament.util.LegacyFormattingCode import moe.nea.firmament.util.LegacyTagParser -import moe.nea.firmament.util.MC import moe.nea.firmament.util.MinecraftDispatcher import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.TestUtil diff --git a/src/main/kotlin/repo/MiningRepoData.kt b/src/main/kotlin/repo/MiningRepoData.kt index 055253f..a987ab1 100644 --- a/src/main/kotlin/repo/MiningRepoData.kt +++ b/src/main/kotlin/repo/MiningRepoData.kt @@ -2,14 +2,12 @@ package moe.nea.firmament.repo import io.github.moulberry.repo.IReloadable import io.github.moulberry.repo.NEURepository -import io.github.moulberry.repo.data.NEUItem import java.util.Collections import java.util.NavigableMap import java.util.TreeMap import kotlinx.serialization.Serializable import kotlinx.serialization.Transient import kotlinx.serialization.serializer -import kotlin.jvm.optionals.getOrNull import kotlin.streams.asSequence import net.minecraft.block.Block import net.minecraft.item.BlockItem @@ -17,7 +15,6 @@ import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound import net.minecraft.text.Text import moe.nea.firmament.repo.ReforgeStore.kJson -import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SkyBlockIsland import moe.nea.firmament.util.SkyblockId diff --git a/src/main/kotlin/repo/RepoDownloadManager.kt b/src/main/kotlin/repo/RepoDownloadManager.kt index 888248d..150a9ca 100644 --- a/src/main/kotlin/repo/RepoDownloadManager.kt +++ b/src/main/kotlin/repo/RepoDownloadManager.kt @@ -21,6 +21,7 @@ import kotlin.io.path.readText import kotlin.io.path.writeText import moe.nea.firmament.Firmament import moe.nea.firmament.Firmament.logger +import moe.nea.firmament.repo.RepoDownloadManager.latestSavedVersionHash import moe.nea.firmament.util.iterate @@ -54,11 +55,11 @@ object RepoDownloadManager { private class GithubCommitsResponse(val sha: String) private suspend fun requestLatestGithubSha(branchOverride: String?): String? { - if (RepoManager.Config.branch == "prerelease") { - RepoManager.Config.branch = "master" + if (RepoManager.TConfig.branch == "prerelease") { + RepoManager.TConfig.branch = "master" } val response = - Firmament.httpClient.get("https://api.github.com/repos/${RepoManager.Config.username}/${RepoManager.Config.reponame}/commits/${branchOverride ?: RepoManager.Config.branch}") + Firmament.httpClient.get("https://api.github.com/repos/${RepoManager.TConfig.username}/${RepoManager.TConfig.reponame}/commits/${branchOverride ?: RepoManager.TConfig.branch}") if (response.status.value != 200) { return null } @@ -87,7 +88,7 @@ object RepoDownloadManager { val currentSha = loadSavedVersionHash() if (latestSha != currentSha || force) { val requestUrl = - "https://github.com/${RepoManager.Config.username}/${RepoManager.Config.reponame}/archive/$latestSha.zip" + "https://github.com/${RepoManager.TConfig.username}/${RepoManager.TConfig.reponame}/archive/$latestSha.zip" logger.info("Planning to upgrade repository from $currentSha to $latestSha from $requestUrl") val zipFile = downloadGithubArchive(requestUrl) logger.info("Download repository zip file to $zipFile. Deleting old repository") diff --git a/src/main/kotlin/repo/RepoManager.kt b/src/main/kotlin/repo/RepoManager.kt index d25494f..43d6db8 100644 --- a/src/main/kotlin/repo/RepoManager.kt +++ b/src/main/kotlin/repo/RepoManager.kt @@ -17,16 +17,18 @@ import net.minecraft.util.StringIdentifiable import moe.nea.firmament.Firmament import moe.nea.firmament.Firmament.logger import moe.nea.firmament.events.ReloadRegistrationEvent -import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.MC import moe.nea.firmament.util.MinecraftDispatcher import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.TestUtil +import moe.nea.firmament.util.data.Config +import moe.nea.firmament.util.data.ManagedConfig import moe.nea.firmament.util.tr object RepoManager { - object Config : ManagedConfig("repo", Category.META) { + @Config + object TConfig : ManagedConfig("repo", Category.META) { var username by string("username") { "NotEnoughUpdates" } var reponame by string("reponame") { "NotEnoughUpdates-REPO" } var branch by string("branch") { "master" } @@ -173,7 +175,7 @@ object RepoManager { return } neuRepo = makeNEURepository(RepoDownloadManager.repoSavedLocation) - if (Config.autoUpdate) { + if (TConfig.autoUpdate) { launchAsyncUpdate() } else { Firmament.coroutineScope.launch { @@ -204,8 +206,8 @@ object RepoManager { } fun getRepoRef(): String { - return "${Config.username}/${Config.reponame}#${Config.branch}" + return "${TConfig.username}/${TConfig.reponame}#${TConfig.branch}" } - fun shouldLoadREI(): Boolean = Config.enableREI + fun shouldLoadREI(): Boolean = TConfig.enableREI } diff --git a/src/main/kotlin/repo/RepoModResourcePack.kt b/src/main/kotlin/repo/RepoModResourcePack.kt index 4fec14a..6868711 100644 --- a/src/main/kotlin/repo/RepoModResourcePack.kt +++ b/src/main/kotlin/repo/RepoModResourcePack.kt @@ -3,7 +3,7 @@ package moe.nea.firmament.repo import java.io.InputStream import java.nio.file.Files import java.nio.file.Path -import java.util.* +import java.util.Optional import net.fabricmc.fabric.api.resource.ModResourcePack import net.fabricmc.fabric.impl.resource.loader.ModResourcePackSorter import net.fabricmc.loader.api.FabricLoader diff --git a/src/main/kotlin/repo/recipes/SBEssenceUpgradeRecipeRenderer.kt b/src/main/kotlin/repo/recipes/SBEssenceUpgradeRecipeRenderer.kt index d358e6a..90a6de4 100644 --- a/src/main/kotlin/repo/recipes/SBEssenceUpgradeRecipeRenderer.kt +++ b/src/main/kotlin/repo/recipes/SBEssenceUpgradeRecipeRenderer.kt @@ -1,8 +1,6 @@ package moe.nea.firmament.repo.recipes import io.github.moulberry.repo.NEURepository -import io.github.moulberry.repo.data.NEUForgeRecipe -import me.shedaniel.math.Point import me.shedaniel.math.Rectangle import net.minecraft.item.ItemStack import net.minecraft.text.Text diff --git a/src/main/kotlin/util/LegacyTagParser.kt b/src/main/kotlin/util/LegacyTagParser.kt index 4e08da1..5a26335 100644 --- a/src/main/kotlin/util/LegacyTagParser.kt +++ b/src/main/kotlin/util/LegacyTagParser.kt @@ -2,7 +2,7 @@ package moe.nea.firmament.util -import java.util.* +import java.util.Stack import net.minecraft.nbt.AbstractNbtNumber import net.minecraft.nbt.NbtByte import net.minecraft.nbt.NbtCompound diff --git a/src/main/kotlin/util/MoulConfigUtils.kt b/src/main/kotlin/util/MoulConfigUtils.kt index 2f2fd5c..fb955ae 100644 --- a/src/main/kotlin/util/MoulConfigUtils.kt +++ b/src/main/kotlin/util/MoulConfigUtils.kt @@ -9,7 +9,6 @@ import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext import io.github.notenoughupdates.moulconfig.gui.KeyboardEvent import io.github.notenoughupdates.moulconfig.gui.MouseEvent import io.github.notenoughupdates.moulconfig.observer.GetSetter -import io.github.notenoughupdates.moulconfig.platform.MoulConfigPlatform import io.github.notenoughupdates.moulconfig.platform.MoulConfigRenderContext import io.github.notenoughupdates.moulconfig.platform.MoulConfigScreenComponent import io.github.notenoughupdates.moulconfig.xml.ChildCount diff --git a/src/main/kotlin/util/TemplateUtil.kt b/src/main/kotlin/util/TemplateUtil.kt index f4ff37c..44d9ccd 100644 --- a/src/main/kotlin/util/TemplateUtil.kt +++ b/src/main/kotlin/util/TemplateUtil.kt @@ -2,10 +2,9 @@ package moe.nea.firmament.util -import java.util.* +import java.util.Base64 import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerializationStrategy -import kotlinx.serialization.json.Json import kotlinx.serialization.serializer import moe.nea.firmament.Firmament diff --git a/src/main/kotlin/util/WarpUtil.kt b/src/main/kotlin/util/WarpUtil.kt index f733af7..1943edb 100644 --- a/src/main/kotlin/util/WarpUtil.kt +++ b/src/main/kotlin/util/WarpUtil.kt @@ -13,84 +13,87 @@ import moe.nea.firmament.commands.thenExecute import moe.nea.firmament.events.CommandEvent import moe.nea.firmament.events.ProcessChatEvent import moe.nea.firmament.repo.RepoManager +import moe.nea.firmament.util.data.Config import moe.nea.firmament.util.data.ProfileSpecificDataHolder object WarpUtil { - val warps: Sequence<Islands.Warp> get() = RepoManager.neuRepo.constants.islands.warps - .asSequence() - .filter { it.warp !in ignoredWarps } + val warps: Sequence<Islands.Warp> + get() = RepoManager.neuRepo.constants.islands.warps + .asSequence() + .filter { it.warp !in ignoredWarps } - val ignoredWarps = setOf("carnival", "") + val ignoredWarps = setOf("carnival", "") - @Serializable - data class Data( - val excludedWarps: MutableSet<String> = mutableSetOf(), - ) + @Serializable + data class Data( + val excludedWarps: MutableSet<String> = mutableSetOf(), + ) - object DConfig : ProfileSpecificDataHolder<Data>(serializer(), "warp-util", ::Data) + @Config + object DConfig : ProfileSpecificDataHolder<Data>(serializer(), "warp-util", ::Data) - private var lastAttemptedWarp = "" - private var lastWarpAttempt = TimeMark.farPast() - fun findNearestWarp(island: SkyBlockIsland, pos: Position): Islands.Warp? { - return warps.asSequence().filter { it.mode == island.locrawMode }.minByOrNull { - if (DConfig.data?.excludedWarps?.contains(it.warp) == true) { - return@minByOrNull Double.MAX_VALUE - } else { - return@minByOrNull squaredDist(pos, it) - } - } - } + private var lastAttemptedWarp = "" + private var lastWarpAttempt = TimeMark.farPast() + fun findNearestWarp(island: SkyBlockIsland, pos: Position): Islands.Warp? { + return warps.asSequence().filter { it.mode == island.locrawMode }.minByOrNull { + if (DConfig.data?.excludedWarps?.contains(it.warp) == true) { + return@minByOrNull Double.MAX_VALUE + } else { + return@minByOrNull squaredDist(pos, it) + } + } + } - private fun squaredDist(pos: Position, warp: Warp): Double { - val dx = pos.x - warp.x - val dy = pos.y - warp.y - val dz = pos.z - warp.z - return dx * dx + dy * dy + dz * dz - } + private fun squaredDist(pos: Position, warp: Warp): Double { + val dx = pos.x - warp.x + val dy = pos.y - warp.y + val dz = pos.z - warp.z + return dx * dx + dy * dy + dz * dz + } - fun teleportToNearestWarp(island: SkyBlockIsland, pos: Position) { - val nearestWarp = findNearestWarp(island, pos) - if (nearestWarp == null) { - MC.sendChat(Text.translatable("firmament.warp-util.no-warp-found", island.userFriendlyName)) - return - } - if (island == SBData.skyblockLocation - && sqrt(squaredDist(pos, nearestWarp)) > 1.1 * sqrt(squaredDist((MC.player ?: return).pos, nearestWarp)) - ) { - MC.sendChat(Text.translatable("firmament.warp-util.already-close", nearestWarp.warp)) - return - } - MC.sendChat(Text.translatable("firmament.warp-util.attempting-to-warp", nearestWarp.warp)) - lastWarpAttempt = TimeMark.now() - lastAttemptedWarp = nearestWarp.warp - MC.sendServerCommand("warp ${nearestWarp.warp}") - } + fun teleportToNearestWarp(island: SkyBlockIsland, pos: Position) { + val nearestWarp = findNearestWarp(island, pos) + if (nearestWarp == null) { + MC.sendChat(Text.translatable("firmament.warp-util.no-warp-found", island.userFriendlyName)) + return + } + if (island == SBData.skyblockLocation + && sqrt(squaredDist(pos, nearestWarp)) > 1.1 * sqrt(squaredDist((MC.player ?: return).pos, nearestWarp)) + ) { + MC.sendChat(Text.translatable("firmament.warp-util.already-close", nearestWarp.warp)) + return + } + MC.sendChat(Text.translatable("firmament.warp-util.attempting-to-warp", nearestWarp.warp)) + lastWarpAttempt = TimeMark.now() + lastAttemptedWarp = nearestWarp.warp + MC.sendServerCommand("warp ${nearestWarp.warp}") + } - @Subscribe - fun clearUnlockedWarpsCommand(event: CommandEvent.SubCommand) { - event.subcommand("clearwarps") { - thenExecute { - DConfig.data?.excludedWarps?.clear() - DConfig.markDirty() - source.sendFeedback(Text.translatable("firmament.warp-util.clear-excluded")) - } - } - } + @Subscribe + fun clearUnlockedWarpsCommand(event: CommandEvent.SubCommand) { + event.subcommand("clearwarps") { + thenExecute { + DConfig.data?.excludedWarps?.clear() + DConfig.markDirty() + source.sendFeedback(Text.translatable("firmament.warp-util.clear-excluded")) + } + } + } - init { - ProcessChatEvent.subscribe("WarpUtil:processChat") { - if (it.unformattedString == "You haven't unlocked this fast travel destination!" - && lastWarpAttempt.passedTime() < 2.seconds - ) { - DConfig.data?.excludedWarps?.add(lastAttemptedWarp) - DConfig.markDirty() - MC.sendChat(Text.stringifiedTranslatable("firmament.warp-util.mark-excluded", lastAttemptedWarp)) - lastWarpAttempt = TimeMark.farPast() - } - if (it.unformattedString.startsWith("You may now fast travel to")) { - DConfig.data?.excludedWarps?.clear() - DConfig.markDirty() - } - } - } + init { + ProcessChatEvent.subscribe("WarpUtil:processChat") { + if (it.unformattedString == "You haven't unlocked this fast travel destination!" + && lastWarpAttempt.passedTime() < 2.seconds + ) { + DConfig.data?.excludedWarps?.add(lastAttemptedWarp) + DConfig.markDirty() + MC.sendChat(Text.stringifiedTranslatable("firmament.warp-util.mark-excluded", lastAttemptedWarp)) + lastWarpAttempt = TimeMark.farPast() + } + if (it.unformattedString.startsWith("You may now fast travel to")) { + DConfig.data?.excludedWarps?.clear() + DConfig.markDirty() + } + } + } } diff --git a/src/main/kotlin/util/accessors/GetRectangle.kt b/src/main/kotlin/util/accessors/GetRectangle.kt index 37acfd9..56f420c 100644 --- a/src/main/kotlin/util/accessors/GetRectangle.kt +++ b/src/main/kotlin/util/accessors/GetRectangle.kt @@ -3,8 +3,8 @@ package moe.nea.firmament.util.accessors import me.shedaniel.math.Rectangle -import moe.nea.firmament.mixins.accessor.AccessorHandledScreen import net.minecraft.client.gui.screen.ingame.HandledScreen +import moe.nea.firmament.mixins.accessor.AccessorHandledScreen fun HandledScreen<*>.getRectangle(): Rectangle { this as AccessorHandledScreen diff --git a/src/main/kotlin/util/data/DataHolder.kt b/src/main/kotlin/util/data/DataHolder.kt index 9f21125..c138d78 100644 --- a/src/main/kotlin/util/data/DataHolder.kt +++ b/src/main/kotlin/util/data/DataHolder.kt @@ -1,11 +1,6 @@ package moe.nea.firmament.util.data -import java.nio.file.Path import kotlinx.serialization.KSerializer -import kotlin.io.path.exists -import kotlin.io.path.readText -import kotlin.io.path.writeText -import moe.nea.firmament.Firmament import moe.nea.firmament.gui.config.storage.ConfigStorageClass abstract class DataHolder<T>( diff --git a/src/main/kotlin/util/data/IDataHolder.kt b/src/main/kotlin/util/data/IDataHolder.kt index 81198ee..541fc1b 100644 --- a/src/main/kotlin/util/data/IDataHolder.kt +++ b/src/main/kotlin/util/data/IDataHolder.kt @@ -9,23 +9,27 @@ import moe.nea.firmament.gui.config.storage.ConfigStorageClass import moe.nea.firmament.gui.config.storage.FirmamentConfigLoader import moe.nea.firmament.util.SBData -sealed interface IDataHolder<T> { +sealed class IDataHolder<T> { fun markDirty() { FirmamentConfigLoader.markDirty(this) } - fun keys(): Collection<T> - fun saveTo(key: T): JsonObject - fun loadFrom(key: T, jsonObject: JsonObject) - fun clear() - val storageClass: ConfigStorageClass + init { + require(this.javaClass.getAnnotation(Config::class.java) != null) + } + + abstract fun keys(): Collection<T> + abstract fun saveTo(key: T): JsonObject + abstract fun loadFrom(key: T, jsonObject: JsonObject) + abstract fun clear() + abstract val storageClass: ConfigStorageClass } open class ProfileKeyedConfig<T>( val prefix: String, val serializer: KSerializer<T>, val default: () -> T, -) : IDataHolder<UUID> { +) : IDataHolder<UUID>() { override val storageClass: ConfigStorageClass get() = ConfigStorageClass.PROFILE @@ -65,7 +69,7 @@ abstract class GenericConfig<T>( val prefix: String, val serializer: KSerializer<T>, val default: () -> T, -) : IDataHolder<Unit> { +) : IDataHolder<Unit>() { private var _data: T? = null diff --git a/src/main/kotlin/util/json/DashlessUUIDSerializer.kt b/src/main/kotlin/util/json/DashlessUUIDSerializer.kt index 6bafebe..f4b073a 100644 --- a/src/main/kotlin/util/json/DashlessUUIDSerializer.kt +++ b/src/main/kotlin/util/json/DashlessUUIDSerializer.kt @@ -9,7 +9,6 @@ import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor import kotlinx.serialization.descriptors.SerialDescriptor import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder -import moe.nea.firmament.util.parseDashlessUUID import moe.nea.firmament.util.parsePotentiallyDashlessUUID object DashlessUUIDSerializer : KSerializer<UUID> { diff --git a/src/main/kotlin/util/json/jsonConversion.kt b/src/main/kotlin/util/json/jsonConversion.kt index 899ae11..f921f7b 100644 --- a/src/main/kotlin/util/json/jsonConversion.kt +++ b/src/main/kotlin/util/json/jsonConversion.kt @@ -6,7 +6,6 @@ import com.google.gson.JsonNull import com.google.gson.JsonObject import com.google.gson.JsonPrimitive import com.google.gson.internal.LazilyParsedNumber -import kotlin.collections.map fun JsonElement.intoKotlinJson(): kotlinx.serialization.json.JsonElement { diff --git a/src/main/kotlin/util/mc/NbtPrism.kt b/src/main/kotlin/util/mc/NbtPrism.kt index f034210..f13fad5 100644 --- a/src/main/kotlin/util/mc/NbtPrism.kt +++ b/src/main/kotlin/util/mc/NbtPrism.kt @@ -7,13 +7,7 @@ import com.google.gson.JsonPrimitive import com.mojang.brigadier.StringReader import com.mojang.brigadier.arguments.ArgumentType import com.mojang.brigadier.arguments.StringArgumentType -import com.mojang.brigadier.context.CommandContext -import com.mojang.brigadier.suggestion.Suggestions -import com.mojang.brigadier.suggestion.SuggestionsBuilder import com.mojang.serialization.JsonOps -import java.util.concurrent.CompletableFuture -import kotlin.collections.indices -import kotlin.collections.map import kotlin.jvm.optionals.getOrNull import net.minecraft.nbt.NbtCompound import net.minecraft.nbt.NbtElement diff --git a/src/main/kotlin/util/render/DrawContextExt.kt b/src/main/kotlin/util/render/DrawContextExt.kt index e63bf5f..e96fab9 100644 --- a/src/main/kotlin/util/render/DrawContextExt.kt +++ b/src/main/kotlin/util/render/DrawContextExt.kt @@ -2,7 +2,6 @@ package moe.nea.firmament.util.render import com.mojang.blaze3d.systems.RenderSystem import me.shedaniel.math.Color -import org.joml.Vector2f import org.joml.Vector3f import util.render.CustomRenderLayers import kotlin.math.abs diff --git a/src/main/kotlin/util/render/FacingThePlayerContext.kt b/src/main/kotlin/util/render/FacingThePlayerContext.kt index 76270c5..e5cb78a 100644 --- a/src/main/kotlin/util/render/FacingThePlayerContext.kt +++ b/src/main/kotlin/util/render/FacingThePlayerContext.kt @@ -6,8 +6,6 @@ import util.render.CustomRenderLayers import net.minecraft.client.font.TextRenderer import net.minecraft.client.render.LightmapTextureManager import net.minecraft.client.render.RenderLayer -import net.minecraft.client.render.RenderLayers -import net.minecraft.client.render.TexturedRenderLayers import net.minecraft.client.render.VertexConsumer import net.minecraft.text.Text import net.minecraft.util.Identifier diff --git a/src/main/kotlin/util/render/FirmamentShaders.kt b/src/main/kotlin/util/render/FirmamentShaders.kt index cc6cd49..53afdf5 100644 --- a/src/main/kotlin/util/render/FirmamentShaders.kt +++ b/src/main/kotlin/util/render/FirmamentShaders.kt @@ -1,15 +1,7 @@ package moe.nea.firmament.util.render -import com.mojang.blaze3d.vertex.VertexFormat -import net.minecraft.client.gl.CompiledShader -import net.minecraft.client.gl.Defines -import net.minecraft.client.gl.ShaderProgram -import net.minecraft.client.render.RenderPhase -import net.minecraft.client.render.VertexFormats -import moe.nea.firmament.Firmament import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.DebugInstantiateEvent -import moe.nea.firmament.util.MC object FirmamentShaders { diff --git a/src/main/kotlin/util/render/MultiSpecialGuiRenderState.kt b/src/main/kotlin/util/render/MultiSpecialGuiRenderState.kt index ce56df3..d05e71e 100644 --- a/src/main/kotlin/util/render/MultiSpecialGuiRenderState.kt +++ b/src/main/kotlin/util/render/MultiSpecialGuiRenderState.kt @@ -1,6 +1,5 @@ package moe.nea.firmament.util.render -import org.joml.Matrix3x2f import net.minecraft.client.gui.ScreenRect import net.minecraft.client.gui.render.SpecialGuiElementRenderer import net.minecraft.client.gui.render.state.GuiRenderState diff --git a/src/main/kotlin/util/render/RenderCircleProgress.kt b/src/main/kotlin/util/render/RenderCircleProgress.kt index 301eec4..7ea4ca8 100644 --- a/src/main/kotlin/util/render/RenderCircleProgress.kt +++ b/src/main/kotlin/util/render/RenderCircleProgress.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.util.render import com.mojang.blaze3d.vertex.VertexFormat -import org.joml.Matrix3x2f import util.render.CustomRenderLayers import net.minecraft.client.gui.DrawContext import net.minecraft.client.gui.ScreenRect diff --git a/src/main/kotlin/util/render/RenderInWorldContext.kt b/src/main/kotlin/util/render/RenderInWorldContext.kt index 154c413..12a061d 100644 --- a/src/main/kotlin/util/render/RenderInWorldContext.kt +++ b/src/main/kotlin/util/render/RenderInWorldContext.kt @@ -1,7 +1,6 @@ package moe.nea.firmament.util.render import com.mojang.blaze3d.systems.RenderSystem -import java.lang.Math.pow import org.joml.Matrix4f import org.joml.Vector3f import util.render.CustomRenderLayers diff --git a/src/main/kotlin/util/render/TranslatedScissors.kt b/src/main/kotlin/util/render/TranslatedScissors.kt index a091648..ee90a2d 100644 --- a/src/main/kotlin/util/render/TranslatedScissors.kt +++ b/src/main/kotlin/util/render/TranslatedScissors.kt @@ -2,7 +2,6 @@ package moe.nea.firmament.util.render import org.joml.Matrix3x2f import org.joml.Vector3f -import org.joml.Vector4f import net.minecraft.client.gui.DrawContext fun DrawContext.enableScissorWithTranslation(x1: Float, y1: Float, x2: Float, y2: Float) { diff --git a/src/main/kotlin/util/skyblock/SackUtil.kt b/src/main/kotlin/util/skyblock/SackUtil.kt index 8c82022..af03363 100644 --- a/src/main/kotlin/util/skyblock/SackUtil.kt +++ b/src/main/kotlin/util/skyblock/SackUtil.kt @@ -13,6 +13,7 @@ import moe.nea.firmament.gui.config.storage.ConfigStorageClass import moe.nea.firmament.repo.ItemNameLookup import moe.nea.firmament.util.SHORT_NUMBER_FORMAT import moe.nea.firmament.util.SkyblockId +import moe.nea.firmament.util.data.Config import moe.nea.firmament.util.data.ProfileSpecificDataHolder import moe.nea.firmament.util.mc.displayNameAccordingToNbt import moe.nea.firmament.util.mc.iterableView @@ -30,6 +31,7 @@ object SackUtil { // val sackTypes: ) + @Config object Store : ProfileSpecificDataHolder<SackContents>(serializer(), "sacks", ::SackContents) @Subscribe |
