diff options
author | Linnea Gräf <nea@nea.moe> | 2024-08-04 21:10:08 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-08-04 21:10:08 +0200 |
commit | 9b277bd897490d13ee4549a086e8d1b5f4cd0e10 (patch) | |
tree | 8f966a8f5b981cb700becb337e43970eb0619fcc /src/main/kotlin/moe | |
parent | 95c1b75a14d41b070c4e23addb3ac4788a014365 (diff) | |
download | firmament-9b277bd897490d13ee4549a086e8d1b5f4cd0e10.tar.gz firmament-9b277bd897490d13ee4549a086e8d1b5f4cd0e10.tar.bz2 firmament-9b277bd897490d13ee4549a086e8d1b5f4cd0e10.zip |
Add SkyBlockIsland type
[no changelog]
Diffstat (limited to 'src/main/kotlin/moe')
7 files changed, 69 insertions, 19 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt b/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt index fb7e8da..21c6453 100644 --- a/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt +++ b/src/main/kotlin/moe/nea/firmament/features/diana/AncestralSpadeSolver.kt @@ -19,6 +19,7 @@ import moe.nea.firmament.events.WorldRenderLastEvent import moe.nea.firmament.events.subscription.SubscriptionOwner import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.util.SBData +import moe.nea.firmament.util.SkyBlockIsland import moe.nea.firmament.util.TimeMark import moe.nea.firmament.util.WarpUtil import moe.nea.firmament.util.render.RenderInWorldContext @@ -34,7 +35,7 @@ object AncestralSpadeSolver : SubscriptionOwner { private var lastTeleportAttempt = TimeMark.farPast() fun isEnabled() = - DianaWaypoints.TConfig.ancestralSpadeSolver && SBData.skyblockLocation == "hub" + DianaWaypoints.TConfig.ancestralSpadeSolver && SBData.skyblockLocation == SkyBlockIsland.HUB @Subscribe fun onKeyBind(event: WorldKeyboardEvent) { @@ -42,7 +43,7 @@ object AncestralSpadeSolver : SubscriptionOwner { if (!event.matches(DianaWaypoints.TConfig.ancestralSpadeTeleport)) return if (lastTeleportAttempt.passedTime() < 3.seconds) return - WarpUtil.teleportToNearestWarp("hub", nextGuess ?: return) + WarpUtil.teleportToNearestWarp(SkyBlockIsland.HUB, nextGuess ?: return) lastTeleportAttempt = TimeMark.now() } diff --git a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt index fbae4bf..14814e7 100644 --- a/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt +++ b/src/main/kotlin/moe/nea/firmament/features/inventory/SlotLocking.kt @@ -31,6 +31,7 @@ import moe.nea.firmament.mixins.accessor.AccessorHandledScreen import moe.nea.firmament.util.CommonSoundEffects import moe.nea.firmament.util.MC import moe.nea.firmament.util.SBData +import moe.nea.firmament.util.SkyBlockIsland import moe.nea.firmament.util.data.ProfileSpecificDataHolder import moe.nea.firmament.util.item.displayNameAccordingToNbt import moe.nea.firmament.util.item.loreAccordingToNbt @@ -66,7 +67,7 @@ object SlotLocking : FirmamentFeature { val lockedSlots get() = when (SBData.skyblockLocation) { - "rift" -> DConfig.data?.lockedSlotsRift + SkyBlockIsland.RIFT -> DConfig.data?.lockedSlotsRift null -> null else -> DConfig.data?.lockedSlots } diff --git a/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt b/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt index 2cce041..36ec495 100644 --- a/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt +++ b/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> * * SPDX-License-Identifier: GPL-3.0-or-later */ @@ -20,6 +21,7 @@ import moe.nea.firmament.gui.config.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.ProfileSpecificDataHolder import moe.nea.firmament.util.render.RenderInWorldContext @@ -32,7 +34,7 @@ object FairySouls : FirmamentFeature { @Serializable data class Data( - val foundSouls: MutableMap<String, MutableSet<Int>> = mutableMapOf() + val foundSouls: MutableMap<SkyBlockIsland, MutableSet<Int>> = mutableMapOf() ) override val config: ManagedConfig @@ -55,7 +57,7 @@ object FairySouls : FirmamentFeature { val playerReach = 5 val playerReachSquared = playerReach * playerReach - var currentLocationName: String? = null + var currentLocationName: SkyBlockIsland? = null var currentLocationSouls: List<Coordinate> = emptyList() var currentMissingSouls: List<Coordinate> = emptyList() @@ -71,7 +73,7 @@ object FairySouls : FirmamentFeature { fun updateWorldSouls() { currentLocationSouls = emptyList() val loc = currentLocationName ?: return - currentLocationSouls = RepoManager.neuRepo.constants.fairySouls.soulLocations[loc] ?: return + currentLocationSouls = RepoManager.neuRepo.constants.fairySouls.soulLocations[loc.locrawMode] ?: return } fun findNearestClickableSoul(): Coordinate? { @@ -79,7 +81,7 @@ object FairySouls : FirmamentFeature { val pos = player.pos val location = SBData.skyblockLocation ?: return null val soulLocations: List<Coordinate> = - RepoManager.neuRepo.constants.fairySouls.soulLocations[location] ?: return null + RepoManager.neuRepo.constants.fairySouls.soulLocations[location.locrawMode] ?: return null return soulLocations .map { it to it.blockPos.getSquaredDistance(pos) } .filter { it.second < playerReachSquared } @@ -101,11 +103,6 @@ object FairySouls : FirmamentFeature { fun onWorldRender(it: WorldRenderLastEvent) { if (!TConfig.displaySouls) return renderInWorld(it) { - text(Vec3d(0.0, 0.0, 0.0), - Text.literal("Test String"), - Text.literal("Short"), - Text.literal("just lik"), - verticalAlign = RenderInWorldContext.VerticalAlign.BOTTOM) color(1F, 1F, 0F, 0.8F) currentMissingSouls.forEach { block(it.blockPos) diff --git a/src/main/kotlin/moe/nea/firmament/util/Locraw.kt b/src/main/kotlin/moe/nea/firmament/util/Locraw.kt index f32bc5e..136d169 100644 --- a/src/main/kotlin/moe/nea/firmament/util/Locraw.kt +++ b/src/main/kotlin/moe/nea/firmament/util/Locraw.kt @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> * * SPDX-License-Identifier: GPL-3.0-or-later */ @@ -7,8 +8,10 @@ package moe.nea.firmament.util import kotlinx.serialization.Serializable +import kotlinx.serialization.Transient @Serializable data class Locraw(val server: String, val gametype: String? = null, val mode: String? = null, val map: String? = null) { - val skyblockLocation = if (gametype == "SKYBLOCK") mode else null + @Transient + val skyblockLocation = if (gametype == "SKYBLOCK") mode?.let(SkyBlockIsland::forMode) else null } diff --git a/src/main/kotlin/moe/nea/firmament/util/SBData.kt b/src/main/kotlin/moe/nea/firmament/util/SBData.kt index 1b6d180..5fd0106 100644 --- a/src/main/kotlin/moe/nea/firmament/util/SBData.kt +++ b/src/main/kotlin/moe/nea/firmament/util/SBData.kt @@ -1,5 +1,6 @@ /* * SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe> + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> * * SPDX-License-Identifier: GPL-3.0-or-later */ @@ -28,7 +29,7 @@ object SBData { private var hasReceivedProfile = false private var hasSentLocraw = false var locraw: Locraw? = null - val skyblockLocation: String? get() = locraw?.skyblockLocation + val skyblockLocation: SkyBlockIsland? get() = locraw?.skyblockLocation val hasValidLocraw get() = locraw?.server !in listOf("limbo", null) val isOnSkyblock get() = locraw?.gametype == "SKYBLOCK" diff --git a/src/main/kotlin/moe/nea/firmament/util/SkyBlockIsland.kt b/src/main/kotlin/moe/nea/firmament/util/SkyBlockIsland.kt new file mode 100644 index 0000000..6eebc2e --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/util/SkyBlockIsland.kt @@ -0,0 +1,47 @@ +/* + * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe> + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +package moe.nea.firmament.util + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.descriptors.PrimitiveKind +import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import moe.nea.firmament.repo.RepoManager + +@Serializable(with = SkyBlockIsland.Serializer::class) +class SkyBlockIsland +private constructor( + val locrawMode: String, +) { + + object Serializer : KSerializer<SkyBlockIsland> { + override val descriptor: SerialDescriptor + get() = PrimitiveSerialDescriptor("SkyBlockIsland", PrimitiveKind.STRING) + + override fun deserialize(decoder: Decoder): SkyBlockIsland { + return forMode(decoder.decodeString()) + } + + override fun serialize(encoder: Encoder, value: SkyBlockIsland) { + encoder.encodeString(value.locrawMode) + } + } + companion object { + private val allIslands = mutableMapOf<String, SkyBlockIsland>() + fun forMode(mode: String): SkyBlockIsland = allIslands.computeIfAbsent(mode, ::SkyBlockIsland) + val HUB = forMode("hub") + val PRIVATE_ISLAND = forMode("dynamic") + val RIFT = forMode("rift") + } + + val userFriendlyName + get() = RepoManager.neuRepo.constants.islands.areaNames + .getOrDefault(locrawMode, locrawMode) +} diff --git a/src/main/kotlin/moe/nea/firmament/util/WarpUtil.kt b/src/main/kotlin/moe/nea/firmament/util/WarpUtil.kt index 5a7911c..7a20346 100644 --- a/src/main/kotlin/moe/nea/firmament/util/WarpUtil.kt +++ b/src/main/kotlin/moe/nea/firmament/util/WarpUtil.kt @@ -30,9 +30,9 @@ object WarpUtil { private var lastAttemptedWarp = "" private var lastWarpAttempt = TimeMark.farPast() - fun findNearestWarp(locrawMode: String, pos: Position): Islands.Warp? { + fun findNearestWarp(island: SkyBlockIsland, pos: Position): Islands.Warp? { return warps.minByOrNull { - if (locrawMode != it.mode || (DConfig.data?.excludedWarps?.contains(it.warp) == true)) { + if (island.locrawMode != it.mode || (DConfig.data?.excludedWarps?.contains(it.warp) == true)) { return@minByOrNull Double.MAX_VALUE } else { return@minByOrNull squaredDist(pos, it) @@ -47,10 +47,10 @@ object WarpUtil { return dx * dx + dy * dy + dz * dz } - fun teleportToNearestWarp(locrawMode: String, pos: Position) { - val nearestWarp = findNearestWarp(locrawMode, pos) ?: return + fun teleportToNearestWarp(island: SkyBlockIsland, pos: Position) { + val nearestWarp = findNearestWarp(island, pos) ?: return - if (locrawMode == SBData.skyblockLocation + if (island == SBData.skyblockLocation && sqrt(squaredDist(pos, nearestWarp)) > 1.1 * sqrt(squaredDist((MC.player ?: return).pos, nearestWarp)) ) { return |