diff options
author | Linnea Gräf <nea@nea.moe> | 2025-03-06 23:36:57 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-03-08 16:01:00 +0100 |
commit | 6ad259ca405d58f1956d67d7daeb05ae8590ca62 (patch) | |
tree | f749625557c8eca45b1c7cc5f1f035f76935a7ff /src/main/kotlin/repo | |
parent | 8a4bfe24b364612e3e783ed9569082b130aa2bfc (diff) | |
download | Firmament-6ad259ca405d58f1956d67d7daeb05ae8590ca62.tar.gz Firmament-6ad259ca405d58f1956d67d7daeb05ae8590ca62.tar.bz2 Firmament-6ad259ca405d58f1956d67d7daeb05ae8590ca62.zip |
feat: Add tool/harvestability indicator
Diffstat (limited to 'src/main/kotlin/repo')
-rw-r--r-- | src/main/kotlin/repo/MiningRepoData.kt | 33 |
1 files changed, 33 insertions, 0 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 |