aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-03-06 23:36:57 +0100
committerLinnea Gräf <nea@nea.moe>2025-03-08 16:01:00 +0100
commit6ad259ca405d58f1956d67d7daeb05ae8590ca62 (patch)
treef749625557c8eca45b1c7cc5f1f035f76935a7ff /src/main/kotlin
parent8a4bfe24b364612e3e783ed9569082b130aa2bfc (diff)
downloadFirmament-6ad259ca405d58f1956d67d7daeb05ae8590ca62.tar.gz
Firmament-6ad259ca405d58f1956d67d7daeb05ae8590ca62.tar.bz2
Firmament-6ad259ca405d58f1956d67d7daeb05ae8590ca62.zip
feat: Add tool/harvestability indicator
Diffstat (limited to 'src/main/kotlin')
-rw-r--r--src/main/kotlin/repo/MiningRepoData.kt33
-rw-r--r--src/main/kotlin/util/MC.kt2
-rw-r--r--src/main/kotlin/util/SkyblockId.kt6
3 files changed, 39 insertions, 2 deletions
diff --git a/src/main/kotlin/repo/MiningRepoData.kt b/src/main/kotlin/repo/MiningRepoData.kt
index 7c4a2ef..548c3e5 100644
--- a/src/main/kotlin/repo/MiningRepoData.kt
+++ b/src/main/kotlin/repo/MiningRepoData.kt
@@ -2,6 +2,10 @@ 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
@@ -19,14 +23,31 @@ import moe.nea.firmament.util.SkyBlockIsland
import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.mc.FirmamentDataComponentTypes
import moe.nea.firmament.util.mc.displayNameAccordingToNbt
+import moe.nea.firmament.util.skyblockId
class MiningRepoData : IReloadable {
var customMiningAreas: Map<SkyBlockIsland, CustomMiningArea> = mapOf()
private set
var customMiningBlocks: List<CustomMiningBlock> = listOf()
private set
+ var toolsByBreakingPower: NavigableMap<BreakingPowerKey, NEUItem> = Collections.emptyNavigableMap()
+ private set
+ data class BreakingPowerKey(
+ val breakingPower: Int,
+ val itemId: SkyblockId? = null
+ ) {
+ companion object {
+ val COMPARATOR: Comparator<BreakingPowerKey> =
+ Comparator
+ .comparingInt<BreakingPowerKey> { it.breakingPower }
+ .thenComparing(Comparator.comparing(
+ { it.itemId },
+ nullsFirst(Comparator.naturalOrder<SkyblockId>())))
+ }
+ }
+
override fun reload(repo: NEURepository) {
customMiningAreas = repo.file("mining/custom_mining_areas.json")
?.kJson(serializer()) ?: mapOf()
@@ -35,6 +56,18 @@ class MiningRepoData : IReloadable {
.filter { it.path.endsWith(".json") }
.map { it.kJson(serializer<CustomMiningBlock>()) }
.toList()
+ toolsByBreakingPower = Collections.unmodifiableNavigableMap(
+ repo.items.items
+ .values
+ .asSequence()
+ .filter { it.breakingPower > 0 }
+ .associateTo(TreeMap<BreakingPowerKey, NEUItem>(BreakingPowerKey.COMPARATOR)) {
+ BreakingPowerKey(it.breakingPower, it.skyblockId) to it
+ })
+ }
+
+ fun getToolsThatCanBreak(breakingPower: Int): Collection<NEUItem> {
+ return toolsByBreakingPower.tailMap(BreakingPowerKey(breakingPower, null), true).values
}
@Serializable
diff --git a/src/main/kotlin/util/MC.kt b/src/main/kotlin/util/MC.kt
index ca3742d..a0d2fc0 100644
--- a/src/main/kotlin/util/MC.kt
+++ b/src/main/kotlin/util/MC.kt
@@ -99,7 +99,7 @@ object MC {
inline val soundManager get() = instance.soundManager
inline val player: ClientPlayerEntity? get() = TestUtil.unlessTesting { instance.player }
inline val camera: Entity? get() = instance.cameraEntity
- inline val stackInHand: ItemStack? get() = player?.inventory?.mainHandStack
+ inline val stackInHand: ItemStack get() = player?.inventory?.mainHandStack ?: ItemStack.EMPTY
inline val guiAtlasManager get() = instance.guiAtlasManager
inline val world: ClientWorld? get() = TestUtil.unlessTesting { instance.world }
inline val playerName: String? get() = player?.name?.unformattedString
diff --git a/src/main/kotlin/util/SkyblockId.kt b/src/main/kotlin/util/SkyblockId.kt
index a99afda..a31255c 100644
--- a/src/main/kotlin/util/SkyblockId.kt
+++ b/src/main/kotlin/util/SkyblockId.kt
@@ -34,7 +34,7 @@ import moe.nea.firmament.util.json.DashlessUUIDSerializer
*/
@JvmInline
@Serializable
-value class SkyblockId(val neuItem: String) {
+value class SkyblockId(val neuItem: String) : Comparable<SkyblockId> {
val identifier
get() = Identifier.of("skyblockitem",
neuItem.lowercase().replace(";", "__")
@@ -48,6 +48,10 @@ value class SkyblockId(val neuItem: String) {
return neuItem
}
+ override fun compareTo(other: SkyblockId): Int {
+ return neuItem.compareTo(other.neuItem)
+ }
+
/**
* A bazaar stock item id, as returned by the HyPixel bazaar api endpoint.
* These are not equivalent to the in-game ids, or the NEU repo ids, and in fact, do not refer to items, but instead