feat: Load mining islands from repo
This commit is contained in:
@@ -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
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -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)}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
72
src/main/kotlin/repo/MiningRepoData.kt
Normal file
72
src/main/kotlin/repo/MiningRepoData.kt
Normal 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
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package moe.nea.firmament.util
|
package moe.nea.firmament.util
|
||||||
|
|
||||||
import kotlinx.serialization.KSerializer
|
import kotlinx.serialization.KSerializer
|
||||||
@@ -13,33 +12,40 @@ import moe.nea.firmament.repo.RepoManager
|
|||||||
@Serializable(with = SkyBlockIsland.Serializer::class)
|
@Serializable(with = SkyBlockIsland.Serializer::class)
|
||||||
class SkyBlockIsland
|
class SkyBlockIsland
|
||||||
private constructor(
|
private constructor(
|
||||||
val locrawMode: String,
|
val locrawMode: String,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
object Serializer : KSerializer<SkyBlockIsland> {
|
object Serializer : KSerializer<SkyBlockIsland> {
|
||||||
override val descriptor: SerialDescriptor
|
override val descriptor: SerialDescriptor
|
||||||
get() = PrimitiveSerialDescriptor("SkyBlockIsland", PrimitiveKind.STRING)
|
get() = PrimitiveSerialDescriptor("SkyBlockIsland", PrimitiveKind.STRING)
|
||||||
|
|
||||||
override fun deserialize(decoder: Decoder): SkyBlockIsland {
|
override fun deserialize(decoder: Decoder): SkyBlockIsland {
|
||||||
return forMode(decoder.decodeString())
|
return forMode(decoder.decodeString())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun serialize(encoder: Encoder, value: SkyBlockIsland) {
|
override fun serialize(encoder: Encoder, value: SkyBlockIsland) {
|
||||||
encoder.encodeString(value.locrawMode)
|
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 MINESHAFT = forMode("mineshaft")
|
|
||||||
val GARDEN = forMode("garden")
|
|
||||||
val DUNGEON = forMode("dungeon")
|
|
||||||
}
|
|
||||||
|
|
||||||
val userFriendlyName
|
companion object {
|
||||||
get() = RepoManager.neuRepo.constants.islands.areaNames
|
private val allIslands = mutableMapOf<String, SkyBlockIsland>()
|
||||||
.getOrDefault(locrawMode, locrawMode)
|
fun forMode(mode: String): SkyBlockIsland = allIslands.computeIfAbsent(mode, ::SkyBlockIsland)
|
||||||
|
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 RIFT = forMode("rift")
|
||||||
|
val MINESHAFT = forMode("mineshaft")
|
||||||
|
val GARDEN = forMode("garden")
|
||||||
|
val DUNGEON = forMode("dungeon")
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasCustomMining
|
||||||
|
get() = RepoManager.miningData.customMiningAreas[this]?.isSpecialMining ?: false
|
||||||
|
|
||||||
|
val userFriendlyName
|
||||||
|
get() = RepoManager.neuRepo.constants.islands.areaNames
|
||||||
|
.getOrDefault(locrawMode, locrawMode)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user