feat: Load mining islands from repo

This commit is contained in:
Linnea Gräf
2025-03-06 20:24:25 +01:00
parent 877edf7539
commit ebd2f270c3
7 changed files with 115 additions and 41 deletions

View File

@@ -1,13 +1,11 @@
package moe.nea.firmament.compat.jade package moe.nea.firmament.compat.jade
import snownee.jade.api.IWailaClientRegistration
import snownee.jade.api.ui.IElement import snownee.jade.api.ui.IElement
import snownee.jade.api.ui.IElementHelper import snownee.jade.api.ui.IElementHelper
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import net.minecraft.item.Items import net.minecraft.item.Items
import net.minecraft.util.Identifier import net.minecraft.util.Identifier
import moe.nea.firmament.util.SBData import moe.nea.firmament.util.SBData
import moe.nea.firmament.util.SkyBlockIsland
import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.setSkyBlockId import moe.nea.firmament.util.setSkyBlockId
@@ -17,16 +15,6 @@ fun String.jadeId(): Identifier = Identifier.of("firmament", this)
// This drill icon should work for CIT resource packs // This drill icon should work for CIT resource packs
val drillItem: ItemStack = Items.PRISMARINE_SHARD.defaultStack.setSkyBlockId(SkyblockId("TITANIUM_DRILL_1")) val drillItem: ItemStack = Items.PRISMARINE_SHARD.defaultStack.setSkyBlockId(SkyblockId("TITANIUM_DRILL_1"))
val drillIcon: IElement = IElementHelper.get().item(drillItem, 0.5f).message(null) val drillIcon: IElement = IElementHelper.get().item(drillItem, 0.5f).message(null)
fun IWailaClientRegistration.registerGemstone(type: String) {
} fun isOnMiningIsland(): Boolean =
SBData.skyblockLocation?.hasCustomMining ?: false
fun isOnMiningIsland(): Boolean {
if (!SBData.isOnSkyblock) return false
// how does a when loop work
if (SBData.skyblockLocation == SkyBlockIsland.forMode("dwarven_mines")) return true
if (SBData.skyblockLocation == SkyBlockIsland.MINESHAFT) return true
if (SBData.skyblockLocation == SkyBlockIsland.forMode("crystal_hollows")) return true
if (SBData.skyblockLocation == SkyBlockIsland.forMode("crimson_isle")) return true
return false
}

View File

@@ -246,6 +246,7 @@ fun firmamentCommand() = literal("firmament") {
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.gametype", locrawInfo.gametype)) source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.gametype", locrawInfo.gametype))
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.mode", locrawInfo.mode)) source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.mode", locrawInfo.mode))
source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.map", locrawInfo.map)) source.sendFeedback(Text.stringifiedTranslatable("firmament.sbinfo.map", locrawInfo.map))
source.sendFeedback(tr("firmament.sbinfo.custommining", "Custom Mining: ${formatBool(locrawInfo.skyblockLocation?.hasCustomMining ?: false)}"))
} }
} }
} }

View File

@@ -61,11 +61,12 @@ object ItemCache : IReloadable {
putShort("Damage", damage.toShort()) putShort("Damage", damage.toShort())
} }
private fun NbtCompound.transformFrom10809ToModern(): NbtCompound? = private fun NbtCompound.transformFrom10809ToModern() = convert189ToModern(this@transformFrom10809ToModern)
fun convert189ToModern(nbtComponent: NbtCompound): NbtCompound? =
try { try {
df.update( df.update(
TypeReferences.ITEM_STACK, TypeReferences.ITEM_STACK,
Dynamic(NbtOps.INSTANCE, this), Dynamic(NbtOps.INSTANCE, nbtComponent),
-1, -1,
SharedConstants.getGameVersion().saveVersion.id SharedConstants.getGameVersion().saveVersion.id
).value as NbtCompound ).value as NbtCompound

View File

@@ -0,0 +1,72 @@
package moe.nea.firmament.repo
import io.github.moulberry.repo.IReloadable
import io.github.moulberry.repo.NEURepository
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
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NbtCompound
import moe.nea.firmament.repo.ReforgeStore.kJson
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SkyBlockIsland
import moe.nea.firmament.util.SkyblockId
class MiningRepoData : IReloadable {
var customMiningAreas: Map<SkyBlockIsland, CustomMiningArea> = mapOf()
private set
var customMiningBlocks: List<CustomMiningBlock> = listOf()
private set
override fun reload(repo: NEURepository) {
customMiningAreas = repo.file("mining/custom_mining_areas.json")
?.kJson(serializer()) ?: mapOf()
customMiningBlocks = repo.tree("mining/blocks")
.asSequence()
.filter { it.path.endsWith(".json") }
.map { it.kJson(serializer<CustomMiningBlock>()) }
.toList()
}
@Serializable
data class CustomMiningBlock(
val breakingPower: Int = 0,
val blockStrength: Int = 0,
val name: String? = null,
val baseDrop: SkyblockId? = null,
val blocks189: List<Block189> = emptyList()
)
@Serializable
data class Block189(
val itemId: String,
val damage: Short = 0,
val onlyIn: List<SkyBlockIsland>? = null,
) {
@Transient
val block = convertToModernBlock()
private fun convertToModernBlock(): Block? {
// TODO: this should be in a shared util, really
val newCompound = ItemCache.convert189ToModern(NbtCompound().apply {
putString("id", itemId)
putShort("Damage", damage)
}) ?: return null
val itemStack = ItemStack.fromNbt(MC.defaultRegistries, newCompound).getOrNull() ?: return null
val blockItem = itemStack.item as? BlockItem ?: return null
return blockItem.block
}
}
@Serializable
data class CustomMiningArea(
val isSpecialMining: Boolean = true
)
}

View File

@@ -54,6 +54,7 @@ object RepoManager {
val essenceRecipeProvider = EssenceRecipeProvider() val essenceRecipeProvider = EssenceRecipeProvider()
val recipeCache = BetterRepoRecipeCache(essenceRecipeProvider, ReforgeStore) val recipeCache = BetterRepoRecipeCache(essenceRecipeProvider, ReforgeStore)
val miningData = MiningRepoData()
fun makeNEURepository(path: Path): NEURepository { fun makeNEURepository(path: Path): NEURepository {
return NEURepository.of(path).apply { return NEURepository.of(path).apply {
@@ -63,6 +64,7 @@ object RepoManager {
registerReloadListener(ItemNameLookup) registerReloadListener(ItemNameLookup)
registerReloadListener(ReforgeStore) registerReloadListener(ReforgeStore)
registerReloadListener(essenceRecipeProvider) registerReloadListener(essenceRecipeProvider)
registerReloadListener(miningData)
ReloadRegistrationEvent.publish(ReloadRegistrationEvent(this)) ReloadRegistrationEvent.publish(ReloadRegistrationEvent(this))
registerReloadListener { registerReloadListener {
if (TestUtil.isInTest) return@registerReloadListener if (TestUtil.isInTest) return@registerReloadListener

View File

@@ -31,6 +31,10 @@ object SBData {
val hypixelTimeZone = ZoneId.of("US/Eastern") val hypixelTimeZone = ZoneId.of("US/Eastern")
private var hasReceivedProfile = false private var hasReceivedProfile = false
var locraw: Locraw? = null var locraw: Locraw? = null
/**
* The current server location the player is in. This will be null outside of SkyBlock.
*/
val skyblockLocation: SkyBlockIsland? get() = locraw?.skyblockLocation val skyblockLocation: SkyBlockIsland? get() = locraw?.skyblockLocation
val hasValidLocraw get() = locraw?.server !in listOf("limbo", null) val hasValidLocraw get() = locraw?.server !in listOf("limbo", null)
val isOnSkyblock get() = locraw?.gametype == "SKYBLOCK" val isOnSkyblock get() = locraw?.gametype == "SKYBLOCK"

View File

@@ -1,4 +1,3 @@
package moe.nea.firmament.util package moe.nea.firmament.util
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
@@ -28,10 +27,14 @@ private constructor(
encoder.encodeString(value.locrawMode) encoder.encodeString(value.locrawMode)
} }
} }
companion object { companion object {
private val allIslands = mutableMapOf<String, SkyBlockIsland>() private val allIslands = mutableMapOf<String, SkyBlockIsland>()
fun forMode(mode: String): SkyBlockIsland = allIslands.computeIfAbsent(mode, ::SkyBlockIsland) fun forMode(mode: String): SkyBlockIsland = allIslands.computeIfAbsent(mode, ::SkyBlockIsland)
val HUB = forMode("hub") val HUB = forMode("hub")
val DWARVEN_MINES = forMode("dwarven_mines")
val CRYSTAL_HOLLOWS = forMode("crystal_hollows")
val CRIMSON_ISLE = forMode("crimson_isle")
val PRIVATE_ISLAND = forMode("dynamic") val PRIVATE_ISLAND = forMode("dynamic")
val RIFT = forMode("rift") val RIFT = forMode("rift")
val MINESHAFT = forMode("mineshaft") val MINESHAFT = forMode("mineshaft")
@@ -39,6 +42,9 @@ private constructor(
val DUNGEON = forMode("dungeon") val DUNGEON = forMode("dungeon")
} }
val hasCustomMining
get() = RepoManager.miningData.customMiningAreas[this]?.isSpecialMining ?: false
val userFriendlyName val userFriendlyName
get() = RepoManager.neuRepo.constants.islands.areaNames get() = RepoManager.neuRepo.constants.islands.areaNames
.getOrDefault(locrawMode, locrawMode) .getOrDefault(locrawMode, locrawMode)