aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/repo
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-11-17 19:55:02 +0100
committerLinnea Gräf <nea@nea.moe>2025-11-17 19:55:02 +0100
commitc93a04a001b0f66b2724d46b04b6d1ed49a08d07 (patch)
tree5869ca70acc482ef0362f27785c3d3f1cbb9ffae /src/main/kotlin/repo
parentaf9893b59407c69d31ebd2ed513f0396ab4d2dc9 (diff)
downloadFirmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.gz
Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.bz2
Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.zip
refactor: port to mojmaps
Diffstat (limited to 'src/main/kotlin/repo')
-rw-r--r--src/main/kotlin/repo/ItemCache.kt82
-rw-r--r--src/main/kotlin/repo/MiningRepoData.kt14
-rw-r--r--src/main/kotlin/repo/Reforge.kt18
-rw-r--r--src/main/kotlin/repo/ReforgeStore.kt8
-rw-r--r--src/main/kotlin/repo/RepoManager.kt16
-rw-r--r--src/main/kotlin/repo/RepoModResourcePack.kt74
-rw-r--r--src/main/kotlin/repo/SBItemStack.kt146
-rw-r--r--src/main/kotlin/repo/recipes/GenericRecipeRenderer.kt10
-rw-r--r--src/main/kotlin/repo/recipes/RecipeLayouter.kt6
-rw-r--r--src/main/kotlin/repo/recipes/SBCraftingRecipeRenderer.kt14
-rw-r--r--src/main/kotlin/repo/recipes/SBEssenceUpgradeRecipeRenderer.kt10
-rw-r--r--src/main/kotlin/repo/recipes/SBForgeRecipeRenderer.kt20
12 files changed, 209 insertions, 209 deletions
diff --git a/src/main/kotlin/repo/ItemCache.kt b/src/main/kotlin/repo/ItemCache.kt
index 0aa4a44..be07042 100644
--- a/src/main/kotlin/repo/ItemCache.kt
+++ b/src/main/kotlin/repo/ItemCache.kt
@@ -19,21 +19,21 @@ import kotlinx.coroutines.withContext
import kotlin.io.path.readText
import kotlin.jvm.optionals.getOrNull
import net.minecraft.SharedConstants
-import net.minecraft.component.DataComponentTypes
-import net.minecraft.component.type.NbtComponent
-import net.minecraft.datafixer.Schemas
-import net.minecraft.datafixer.TypeReferences
-import net.minecraft.item.ItemStack
-import net.minecraft.item.Items
-import net.minecraft.nbt.NbtCompound
-import net.minecraft.nbt.NbtElement
+import net.minecraft.core.component.DataComponents
+import net.minecraft.nbt.CompoundTag
import net.minecraft.nbt.NbtOps
-import net.minecraft.nbt.NbtString
-import net.minecraft.nbt.StringNbtReader
-import net.minecraft.text.MutableText
-import net.minecraft.text.Style
-import net.minecraft.text.Text
-import net.minecraft.util.Identifier
+import net.minecraft.nbt.StringTag
+import net.minecraft.nbt.Tag
+import net.minecraft.nbt.TagParser
+import net.minecraft.network.chat.Component
+import net.minecraft.network.chat.MutableComponent
+import net.minecraft.network.chat.Style
+import net.minecraft.resources.ResourceLocation
+import net.minecraft.util.datafix.DataFixers
+import net.minecraft.util.datafix.fixes.References
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.item.Items
+import net.minecraft.world.item.component.CustomData
import moe.nea.firmament.Firmament
import moe.nea.firmament.features.debug.ExportedTestConstantMeta
import moe.nea.firmament.repo.RepoManager.initialize
@@ -56,12 +56,12 @@ import moe.nea.firmament.util.transformEachRecursively
object ItemCache : IReloadable {
private val cache: MutableMap<String, ItemStack> = ConcurrentHashMap()
- private val df = Schemas.getFixer()
+ private val df = DataFixers.getDataFixer()
val logger = LogManager.getLogger("${Firmament.logger.name}.ItemCache")
var isFlawless = true
private set
- private fun NEUItem.get10809CompoundTag(): NbtCompound = NbtCompound().apply {
+ private fun NEUItem.get10809CompoundTag(): CompoundTag = CompoundTag().apply {
put("tag", LegacyTagParser.parse(nbttag))
putString("id", minecraftItemId)
putByte("Count", 1)
@@ -69,18 +69,18 @@ object ItemCache : IReloadable {
}
@ExpensiveItemCacheApi
- private fun NbtCompound.transformFrom10809ToModern() = convert189ToModern(this@transformFrom10809ToModern)
- val currentSaveVersion = SharedConstants.getGameVersion().dataVersion().id
+ private fun CompoundTag.transformFrom10809ToModern() = convert189ToModern(this@transformFrom10809ToModern)
+ val currentSaveVersion = SharedConstants.getCurrentVersion().dataVersion().version
@ExpensiveItemCacheApi
- fun convert189ToModern(nbtComponent: NbtCompound): NbtCompound? =
+ fun convert189ToModern(nbtComponent: CompoundTag): CompoundTag? =
try {
df.update(
- TypeReferences.ITEM_STACK,
+ References.ITEM_STACK,
Dynamic(NbtOps.INSTANCE, nbtComponent),
-1,
currentSaveVersion
- ).value as NbtCompound
+ ).value as CompoundTag
} catch (e: Exception) {
isFlawless = false
logger.error("Could not data fix up $this", e)
@@ -97,24 +97,24 @@ object ItemCache : IReloadable {
fun brokenItemStack(neuItem: NEUItem?, idHint: SkyblockId? = null): ItemStack {
return ItemStack(Items.PAINTING).apply {
- setCustomName(Text.literal(neuItem?.displayName ?: idHint?.neuItem ?: "null"))
+ setCustomName(Component.literal(neuItem?.displayName ?: idHint?.neuItem ?: "null"))
appendLore(
listOf(
- Text.stringifiedTranslatable(
+ Component.translatableEscape(
"firmament.repo.brokenitem",
(neuItem?.skyblockItemId ?: idHint)
)
)
)
- set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(NbtCompound().apply {
- put("ID", NbtString.of(neuItem?.skyblockItemId ?: idHint?.neuItem ?: "null"))
+ set(DataComponents.CUSTOM_DATA, CustomData.of(CompoundTag().apply {
+ put("ID", StringTag.valueOf(neuItem?.skyblockItemId ?: idHint?.neuItem ?: "null"))
}))
set(FirmamentDataComponentTypes.IS_BROKEN, true)
}
}
- fun un189Lore(lore: String): MutableText {
- val base = Text.literal("")
+ fun un189Lore(lore: String): MutableComponent {
+ val base = Component.literal("")
base.setStyle(Style.EMPTY.withItalic(false))
var lastColorCode = Style.EMPTY
var readOffset = 0
@@ -125,7 +125,7 @@ object ItemCache : IReloadable {
}
val text = lore.substring(readOffset, nextCode)
if (text.isNotEmpty()) {
- base.append(Text.literal(text).setStyle(lastColorCode))
+ base.append(Component.literal(text).setStyle(lastColorCode))
}
readOffset = nextCode + 2
if (nextCode + 1 < lore.length) {
@@ -135,27 +135,27 @@ object ItemCache : IReloadable {
if (modernFormatting.isColor) {
lastColorCode = Style.EMPTY.withColor(modernFormatting)
} else {
- lastColorCode = lastColorCode.withFormatting(modernFormatting)
+ lastColorCode = lastColorCode.applyFormat(modernFormatting)
}
}
}
return base
}
- fun tryFindFromModernFormat(skyblockId: SkyblockId): NbtCompound? {
+ fun tryFindFromModernFormat(skyblockId: SkyblockId): CompoundTag? {
val overlayFile =
RepoManager.overlayData.getMostModernReadableOverlay(skyblockId, currentSaveVersion) ?: return null
- val overlay = StringNbtReader.readCompound(overlayFile.path.readText())
+ val overlay = TagParser.parseCompoundFully(overlayFile.path.readText())
val result = ExportedTestConstantMeta.SOURCE_CODEC.decode(
NbtOps.INSTANCE, overlay
).result().getOrNull() ?: return null
val meta = result.first
return df.update(
- TypeReferences.ITEM_STACK,
+ References.ITEM_STACK,
Dynamic(NbtOps.INSTANCE, result.second),
meta.dataVersion,
currentSaveVersion
- ).value as NbtCompound
+ ).value as CompoundTag
}
@ExpensiveItemCacheApi
@@ -177,10 +177,10 @@ object ItemCache : IReloadable {
val extraAttributes = tag.flatMap { it.getCompound("ExtraAttributes") }
.getOrNull()
if (extraAttributes != null)
- itemInstance.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(extraAttributes))
+ itemInstance.set(DataComponents.CUSTOM_DATA, CustomData.of(extraAttributes))
val itemModel = tag.flatMap { it.getString("ItemModel") }.getOrNull()
if (itemModel != null)
- itemInstance.set(DataComponentTypes.ITEM_MODEL, Identifier.of(itemModel))
+ itemInstance.set(DataComponents.ITEM_MODEL, ResourceLocation.parse(itemModel))
}
itemInstance.loreAccordingToNbt = lore.map { un189Lore(it) }
itemInstance.displayNameAccordingToNbt = un189Lore(displayName)
@@ -206,7 +206,7 @@ object ItemCache : IReloadable {
if (!loreReplacements.isNullOrEmpty()) {
s = s.copy()!!
s.applyLoreReplacements(loreReplacements)
- s.setCustomName(s.name.applyLoreReplacements(loreReplacements))
+ s.setCustomName(s.hoverName.applyLoreReplacements(loreReplacements))
}
return s
}
@@ -219,13 +219,13 @@ object ItemCache : IReloadable {
}
}
- fun Text.applyLoreReplacements(loreReplacements: Map<String, String>): Text {
+ fun Component.applyLoreReplacements(loreReplacements: Map<String, String>): Component {
return this.transformEachRecursively {
var string = it.directLiteralStringContent ?: return@transformEachRecursively it
loreReplacements.forEach { (find, replace) ->
string = string.replace("{$find}", replace)
}
- Text.literal(string).setStyle(it.style)
+ Component.literal(string).setStyle(it.style)
}
}
@@ -289,7 +289,7 @@ object ItemCache : IReloadable {
"http://textures.minecraft.net/texture/7b951fed6a7b2cbc2036916dec7a46c4a56481564d14f945b6ebc03382766d3b"
}
val itemStack = ItemStack(Items.PLAYER_HEAD)
- itemStack.setCustomName(Text.literal("§r§6" + NumberFormat.getInstance().format(coinAmount) + " Coins"))
+ itemStack.setCustomName(Component.literal("§r§6" + NumberFormat.getInstance().format(coinAmount) + " Coins"))
itemStack.setSkullOwner(uuid, texture)
return itemStack
}
@@ -303,10 +303,10 @@ object ItemCache : IReloadable {
}
-operator fun NbtCompound.set(key: String, value: String) {
+operator fun CompoundTag.set(key: String, value: String) {
putString(key, value)
}
-operator fun NbtCompound.set(key: String, value: NbtElement) {
+operator fun CompoundTag.set(key: String, value: Tag) {
put(key, value)
}
diff --git a/src/main/kotlin/repo/MiningRepoData.kt b/src/main/kotlin/repo/MiningRepoData.kt
index a987ab1..5b5b016 100644
--- a/src/main/kotlin/repo/MiningRepoData.kt
+++ b/src/main/kotlin/repo/MiningRepoData.kt
@@ -9,11 +9,11 @@ import kotlinx.serialization.Serializable
import kotlinx.serialization.Transient
import kotlinx.serialization.serializer
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 net.minecraft.text.Text
+import net.minecraft.world.level.block.Block
+import net.minecraft.world.item.BlockItem
+import net.minecraft.world.item.ItemStack
+import net.minecraft.nbt.CompoundTag
+import net.minecraft.network.chat.Component
import moe.nea.firmament.repo.ReforgeStore.kJson
import moe.nea.firmament.util.SBData
import moe.nea.firmament.util.SkyBlockIsland
@@ -87,7 +87,7 @@ class MiningRepoData : IReloadable {
private fun markItemStack(itemStack: ItemStack) {
itemStack.set(FirmamentDataComponentTypes.CUSTOM_MINING_BLOCK_DATA, this)
if (name != null)
- itemStack.displayNameAccordingToNbt = Text.literal(name)
+ itemStack.displayNameAccordingToNbt = Component.literal(name)
}
fun getDisplayItem(block: Block): ItemStack {
@@ -112,7 +112,7 @@ class MiningRepoData : IReloadable {
@OptIn(ExpensiveItemCacheApi::class)
private fun convertToModernBlock(): Block? {
// TODO: this should be in a shared util, really
- val newCompound = ItemCache.convert189ToModern(NbtCompound().apply {
+ val newCompound = ItemCache.convert189ToModern(CompoundTag().apply {
putString("id", itemId)
putShort("Damage", damage)
}) ?: return null
diff --git a/src/main/kotlin/repo/Reforge.kt b/src/main/kotlin/repo/Reforge.kt
index dc0d93d..5f6506f 100644
--- a/src/main/kotlin/repo/Reforge.kt
+++ b/src/main/kotlin/repo/Reforge.kt
@@ -13,10 +13,10 @@ import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.serializer
-import net.minecraft.item.Item
-import net.minecraft.registry.RegistryKey
-import net.minecraft.registry.RegistryKeys
-import net.minecraft.util.Identifier
+import net.minecraft.world.item.Item
+import net.minecraft.resources.ResourceKey
+import net.minecraft.core.registries.Registries
+import net.minecraft.resources.ResourceLocation
import moe.nea.firmament.util.ReforgeId
import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.skyblock.ItemType
@@ -64,9 +64,9 @@ data class Reforge(
}
jsonElement["itemId"]?.let {
decoder.json.decodeFromJsonElement(serializer<List<String>>(), it).forEach {
- val ident = Identifier.tryParse(it)
+ val ident = ResourceLocation.tryParse(it)
if (ident != null)
- filters.add(AllowsVanillaItemType(RegistryKey.of(RegistryKeys.ITEM, ident)))
+ filters.add(AllowsVanillaItemType(ResourceKey.create(Registries.ITEM, ident)))
}
}
return filters
@@ -90,8 +90,8 @@ data class Reforge(
return AllowsItemType(ItemType.ofName((it as JsonPrimitive).content))
}
jsonObject["minecraftId"]?.let {
- return AllowsVanillaItemType(RegistryKey.of(RegistryKeys.ITEM,
- Identifier.of((it as JsonPrimitive).content)))
+ return AllowsVanillaItemType(ResourceKey.create(Registries.ITEM,
+ ResourceLocation.parse((it as JsonPrimitive).content)))
}
error("Unknown item type")
}
@@ -104,7 +104,7 @@ data class Reforge(
data class AllowsItemType(val itemType: ItemType) : ReforgeEligibilityFilter
data class AllowsInternalName(val internalName: SkyblockId) : ReforgeEligibilityFilter
- data class AllowsVanillaItemType(val minecraftId: RegistryKey<Item>) : ReforgeEligibilityFilter
+ data class AllowsVanillaItemType(val minecraftId: ResourceKey<Item>) : ReforgeEligibilityFilter
}
diff --git a/src/main/kotlin/repo/ReforgeStore.kt b/src/main/kotlin/repo/ReforgeStore.kt
index 4c01974..cf8b434 100644
--- a/src/main/kotlin/repo/ReforgeStore.kt
+++ b/src/main/kotlin/repo/ReforgeStore.kt
@@ -9,8 +9,8 @@ import io.github.moulberry.repo.NEURepositoryException
import io.github.moulberry.repo.data.NEURecipe
import kotlinx.serialization.KSerializer
import kotlinx.serialization.serializer
-import net.minecraft.item.Item
-import net.minecraft.registry.RegistryKey
+import net.minecraft.world.item.Item
+import net.minecraft.resources.ResourceKey
import moe.nea.firmament.Firmament
import moe.nea.firmament.util.ReforgeId
import moe.nea.firmament.util.SkyblockId
@@ -23,7 +23,7 @@ object ReforgeStore : ExtraRecipeProvider, IReloadable {
}
var byType: Map<ItemType, List<Reforge>> = mapOf()
- var byVanilla: Map<RegistryKey<Item>, List<Reforge>> = mapOf()
+ var byVanilla: Map<ResourceKey<Item>, List<Reforge>> = mapOf()
var byInternalName: Map<SkyblockId, List<Reforge>> = mapOf()
var modifierLut = mapOf<ReforgeId, Reforge>()
var byReforgeStone = mapOf<SkyblockId, Reforge>()
@@ -52,7 +52,7 @@ object ReforgeStore : ExtraRecipeProvider, IReloadable {
byReforgeStone = allReforges.filter { it.reforgeStone != null }
.associateBy { it.reforgeStone!! }
val byType = mutableMapOf<ItemType, MutableList<Reforge>>()
- val byVanilla = mutableMapOf<RegistryKey<Item>, MutableList<Reforge>>()
+ val byVanilla = mutableMapOf<ResourceKey<Item>, MutableList<Reforge>>()
val byInternalName = mutableMapOf<SkyblockId, MutableList<Reforge>>()
this.byType = byType
this.byVanilla = byVanilla
diff --git a/src/main/kotlin/repo/RepoManager.kt b/src/main/kotlin/repo/RepoManager.kt
index 3a245b6..c8da6a7 100644
--- a/src/main/kotlin/repo/RepoManager.kt
+++ b/src/main/kotlin/repo/RepoManager.kt
@@ -10,10 +10,10 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
-import net.minecraft.client.MinecraftClient
-import net.minecraft.network.packet.s2c.play.SynchronizeRecipesS2CPacket
-import net.minecraft.recipe.display.CuttingRecipeDisplay
-import net.minecraft.util.StringIdentifiable
+import net.minecraft.client.Minecraft
+import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket
+import net.minecraft.world.item.crafting.SelectableRecipe
+import net.minecraft.util.StringRepresentable
import moe.nea.firmament.Firmament
import moe.nea.firmament.Firmament.logger
import moe.nea.firmament.events.ReloadRegistrationEvent
@@ -56,7 +56,7 @@ object RepoManager {
val perfectRenders by choice("perfect-renders") { PerfectRender.RENDER }
}
- enum class PerfectRender(val label: String) : StringIdentifiable {
+ enum class PerfectRender(val label: String) : StringRepresentable {
NOTHING("nothing"),
RENDER("render"),
RENDER_AND_TEXT("text"),
@@ -65,7 +65,7 @@ object RepoManager {
fun rendersPerfectText() = this == RENDER_AND_TEXT
fun rendersPerfectVisuals() = this == RENDER || this == RENDER_AND_TEXT
- override fun asString(): String? = label
+ override fun getSerializedName(): String? = label
}
val currentDownloadedSha by RepoDownloadManager::latestSavedVersionHash
@@ -112,8 +112,8 @@ object RepoManager {
fun getUsagesFor(skyblockId: SkyblockId): Set<NEURecipe> = recipeCache.usages[skyblockId] ?: setOf()
private fun trySendClientboundUpdateRecipesPacket(): Boolean {
- return MinecraftClient.getInstance().world != null && MinecraftClient.getInstance().networkHandler?.onSynchronizeRecipes(
- SynchronizeRecipesS2CPacket(mutableMapOf(), CuttingRecipeDisplay.Grouping.empty())
+ return Minecraft.getInstance().level != null && Minecraft.getInstance().connection?.handleUpdateRecipes(
+ ClientboundUpdateRecipesPacket(mutableMapOf(), SelectableRecipe.SingleInputSet.empty())
) != null
}
diff --git a/src/main/kotlin/repo/RepoModResourcePack.kt b/src/main/kotlin/repo/RepoModResourcePack.kt
index 8b201af..cd0bc63 100644
--- a/src/main/kotlin/repo/RepoModResourcePack.kt
+++ b/src/main/kotlin/repo/RepoModResourcePack.kt
@@ -12,19 +12,19 @@ import kotlin.io.path.exists
import kotlin.io.path.isRegularFile
import kotlin.io.path.relativeTo
import kotlin.streams.asSequence
-import net.minecraft.resource.AbstractFileResourcePack
-import net.minecraft.resource.InputSupplier
-import net.minecraft.resource.NamespaceResourceManager
-import net.minecraft.resource.Resource
-import net.minecraft.resource.ResourcePack
-import net.minecraft.resource.ResourcePackInfo
-import net.minecraft.resource.ResourcePackSource
-import net.minecraft.resource.ResourceType
-import net.minecraft.resource.metadata.ResourceMetadata
-import net.minecraft.resource.metadata.ResourceMetadataSerializer
-import net.minecraft.text.Text
-import net.minecraft.util.Identifier
-import net.minecraft.util.path.PathUtil
+import net.minecraft.server.packs.AbstractPackResources
+import net.minecraft.server.packs.resources.IoSupplier
+import net.minecraft.server.packs.resources.FallbackResourceManager
+import net.minecraft.server.packs.resources.Resource
+import net.minecraft.server.packs.PackResources
+import net.minecraft.server.packs.PackLocationInfo
+import net.minecraft.server.packs.repository.PackSource
+import net.minecraft.server.packs.PackType
+import net.minecraft.server.packs.resources.ResourceMetadata
+import net.minecraft.server.packs.metadata.MetadataSectionType
+import net.minecraft.network.chat.Component
+import net.minecraft.resources.ResourceLocation
+import net.minecraft.FileUtil
import moe.nea.firmament.Firmament
class RepoModResourcePack(val basePath: Path) : ModResourcePack {
@@ -34,19 +34,19 @@ class RepoModResourcePack(val basePath: Path) : ModResourcePack {
packs.addPack(RepoModResourcePack(RepoDownloadManager.repoSavedLocation))
}
- fun createResourceDirectly(identifier: Identifier): Optional<Resource> {
+ fun createResourceDirectly(identifier: ResourceLocation): Optional<Resource> {
val pack = RepoModResourcePack(RepoDownloadManager.repoSavedLocation)
return Optional.of(
Resource(
pack,
- pack.open(ResourceType.CLIENT_RESOURCES, identifier) ?: return Optional.empty()
+ pack.getResource(PackType.CLIENT_RESOURCES, identifier) ?: return Optional.empty()
) {
val base =
- pack.open(ResourceType.CLIENT_RESOURCES, identifier.withPath(identifier.path + ".mcmeta"))
+ pack.getResource(PackType.CLIENT_RESOURCES, identifier.withPath(identifier.path + ".mcmeta"))
if (base == null)
- ResourceMetadata.NONE
+ ResourceMetadata.EMPTY
else
- NamespaceResourceManager.loadMetadata(base)
+ FallbackResourceManager.parseMetadata(base)
}
)
}
@@ -55,32 +55,32 @@ class RepoModResourcePack(val basePath: Path) : ModResourcePack {
override fun close() {
}
- override fun openRoot(vararg segments: String): InputSupplier<InputStream>? {
- return getFile(segments)?.let { InputSupplier.create(it) }
+ override fun getRootResource(vararg segments: String): IoSupplier<InputStream>? {
+ return getFile(segments)?.let { IoSupplier.create(it) }
}
fun getFile(segments: Array<out String>): Path? {
- PathUtil.validatePath(*segments)
+ FileUtil.validatePath(*segments)
val path = segments.fold(basePath, Path::resolve)
if (!path.isRegularFile()) return null
return path
}
- override fun open(type: ResourceType?, id: Identifier): InputSupplier<InputStream>? {
- if (type != ResourceType.CLIENT_RESOURCES) return null
+ override fun getResource(type: PackType?, id: ResourceLocation): IoSupplier<InputStream>? {
+ if (type != PackType.CLIENT_RESOURCES) return null
if (id.namespace != "neurepo") return null
val file = getFile(id.path.split("/").toTypedArray())
- return file?.let { InputSupplier.create(it) }
+ return file?.let { IoSupplier.create(it) }
}
- override fun findResources(
- type: ResourceType?,
+ override fun listResources(
+ type: PackType?,
namespace: String,
prefix: String,
- consumer: ResourcePack.ResultConsumer
+ consumer: PackResources.ResourceOutput
) {
if (namespace != "neurepo") return
- if (type != ResourceType.CLIENT_RESOURCES) return
+ if (type != PackType.CLIENT_RESOURCES) return
val prefixPath = basePath.resolve(prefix)
if (!prefixPath.exists())
@@ -90,19 +90,19 @@ class RepoModResourcePack(val basePath: Path) : ModResourcePack {
.map { it.relativeTo(basePath) }
.forEach {
consumer.accept(
- Identifier.tryParse("neurepo", it.toString()) ?: return@forEach,
- InputSupplier.create(it)
+ ResourceLocation.tryBuild("neurepo", it.toString()) ?: return@forEach,
+ IoSupplier.create(it)
)
}
}
- override fun getNamespaces(type: ResourceType?): Set<String> {
- if (type != ResourceType.CLIENT_RESOURCES) return emptySet()
+ override fun getNamespaces(type: PackType?): Set<String> {
+ if (type != PackType.CLIENT_RESOURCES) return emptySet()
return setOf("neurepo")
}
- override fun <T : Any?> parseMetadata(metadataSerializer: ResourceMetadataSerializer<T>?): T? {
- return AbstractFileResourcePack.parseMetadata(
+ override fun <T : Any?> getMetadataSection(metadataSerializer: MetadataSectionType<T>?): T? {
+ return AbstractPackResources.getMetadataFromStream(
metadataSerializer, """
{
"pack": {
@@ -110,13 +110,13 @@ class RepoModResourcePack(val basePath: Path) : ModResourcePack {
"description": "NEU Repo Resources"
}
}
-""".trimIndent().byteInputStream(), info
+""".trimIndent().byteInputStream(), location()
)
}
- override fun getInfo(): ResourcePackInfo {
- return ResourcePackInfo("neurepo", Text.literal("NEU Repo"), ResourcePackSource.BUILTIN, Optional.empty())
+ override fun location(): PackLocationInfo {
+ return PackLocationInfo("neurepo", Component.literal("NEU Repo"), PackSource.BUILT_IN, Optional.empty())
}
override fun getFabricModMetadata(): ModMetadata {
diff --git a/src/main/kotlin/repo/SBItemStack.kt b/src/main/kotlin/repo/SBItemStack.kt
index 01d1c4d..80cd5d7 100644
--- a/src/main/kotlin/repo/SBItemStack.kt
+++ b/src/main/kotlin/repo/SBItemStack.kt
@@ -5,14 +5,14 @@ import com.mojang.serialization.codecs.RecordCodecBuilder
import io.github.moulberry.repo.constants.PetNumbers
import io.github.moulberry.repo.data.NEUIngredient
import io.github.moulberry.repo.data.NEUItem
-import net.minecraft.item.ItemStack
-import net.minecraft.network.RegistryByteBuf
-import net.minecraft.network.codec.PacketCodec
-import net.minecraft.network.codec.PacketCodecs
-import net.minecraft.text.Style
-import net.minecraft.text.Text
-import net.minecraft.text.TextColor
-import net.minecraft.util.Formatting
+import net.minecraft.world.item.ItemStack
+import net.minecraft.network.RegistryFriendlyByteBuf
+import net.minecraft.network.codec.StreamCodec
+import net.minecraft.network.codec.ByteBufCodecs
+import net.minecraft.network.chat.Style
+import net.minecraft.network.chat.Component
+import net.minecraft.network.chat.TextColor
+import net.minecraft.ChatFormatting
import moe.nea.firmament.repo.ItemCache.asItemStack
import moe.nea.firmament.repo.ItemCache.withFallback
import moe.nea.firmament.util.FirmFormatters
@@ -48,7 +48,7 @@ data class SBItemStack constructor(
val neuItem: NEUItem?,
private var stackSize: Int,
private var petData: PetData?,
- val extraLore: List<Text> = emptyList(),
+ val extraLore: List<Component> = emptyList(),
val stars: Int = 0,
val fallback: ItemStack? = null,
val reforge: ReforgeId? = null,
@@ -67,9 +67,9 @@ data class SBItemStack constructor(
}
companion object {
- val PACKET_CODEC: PacketCodec<in RegistryByteBuf, SBItemStack> = PacketCodec.tuple(
+ val PACKET_CODEC: StreamCodec<in RegistryFriendlyByteBuf, SBItemStack> = StreamCodec.composite(
SkyblockId.PACKET_CODEC, { it.skyblockId },
- PacketCodecs.VAR_INT, { it.stackSize },
+ ByteBufCodecs.VAR_INT, { it.stackSize },
{ id, count -> SBItemStack(id, count) }
)
val CODEC: Codec<SBItemStack> = RecordCodecBuilder.create {
@@ -136,7 +136,7 @@ data class SBItemStack constructor(
loreMut[i] = statLine.addStat(statBuff, buffKind).reconstitute()
}
if (namedReforgeStats.isNotEmpty() && statBlockLastIndex == -1) {
- loreMut.add(0, Text.literal(""))
+ loreMut.add(0, Component.literal(""))
}
// If there is no stat block the statBlockLastIndex falls through to -1
// TODO: this is good enough for some items. some other items might have their stats at a different place.
@@ -149,47 +149,47 @@ data class SBItemStack constructor(
data class StatFormatting(
val postFix: String,
- val color: Formatting,
+ val color: ChatFormatting,
val isStarAffected: Boolean = true,
)
val formattingOverrides = mapOf(
- "Sea Creature Chance" to StatFormatting("%", Formatting.RED),
- "Strength" to StatFormatting("", Formatting.RED),
- "Damage" to StatFormatting("", Formatting.RED),
- "Bonus Attack Speed" to StatFormatting("%", Formatting.RED),
- "Shot Cooldown" to StatFormatting("s", Formatting.GREEN, false),
- "Ability Damage" to StatFormatting("%", Formatting.RED),
- "Crit Damage" to StatFormatting("%", Formatting.RED),
- "Crit Chance" to StatFormatting("%", Formatting.RED),
- "Ability Damage" to StatFormatting("%", Formatting.RED),
- "Trophy Fish Chance" to StatFormatting("%", Formatting.GREEN),
- "Health" to StatFormatting("", Formatting.GREEN),
- "Defense" to StatFormatting("", Formatting.GREEN),
- "Fishing Speed" to StatFormatting("", Formatting.GREEN),
- "Double Hook Chance" to StatFormatting("%", Formatting.GREEN),
- "Mining Speed" to StatFormatting("", Formatting.GREEN),
- "Mining Fortune" to StatFormatting("", Formatting.GREEN),
- "Heat Resistance" to StatFormatting("", Formatting.GREEN),
- "Swing Range" to StatFormatting("", Formatting.GREEN),
- "Rift Time" to StatFormatting("", Formatting.GREEN),
- "Speed" to StatFormatting("", Formatting.GREEN),
- "Farming Fortune" to StatFormatting("", Formatting.GREEN),
- "True Defense" to StatFormatting("", Formatting.GREEN),
- "Mending" to StatFormatting("", Formatting.GREEN),
- "Foraging Wisdom" to StatFormatting("", Formatting.GREEN),
- "Farming Wisdom" to StatFormatting("", Formatting.GREEN),
- "Foraging Fortune" to StatFormatting("", Formatting.GREEN),
- "Magic Find" to StatFormatting("", Formatting.GREEN),
- "Ferocity" to StatFormatting("", Formatting.GREEN),
- "Bonus Pest Chance" to StatFormatting("%", Formatting.GREEN),
- "Cold Resistance" to StatFormatting("", Formatting.GREEN),
- "Pet Luck" to StatFormatting("", Formatting.GREEN),
- "Fear" to StatFormatting("", Formatting.GREEN),
- "Mana Regen" to StatFormatting("%", Formatting.GREEN),
- "Rift Damage" to StatFormatting("", Formatting.GREEN),
- "Hearts" to StatFormatting("", Formatting.GREEN),
- "Vitality" to StatFormatting("", Formatting.GREEN),
+ "Sea Creature Chance" to StatFormatting("%", ChatFormatting.RED),
+ "Strength" to StatFormatting("", ChatFormatting.RED),
+ "Damage" to StatFormatting("", ChatFormatting.RED),
+ "Bonus Attack Speed" to StatFormatting("%", ChatFormatting.RED),
+ "Shot Cooldown" to StatFormatting("s", ChatFormatting.GREEN, false),
+ "Ability Damage" to StatFormatting("%", ChatFormatting.RED),
+ "Crit Damage" to StatFormatting("%", ChatFormatting.RED),
+ "Crit Chance" to StatFormatting("%", ChatFormatting.RED),
+ "Ability Damage" to StatFormatting("%", ChatFormatting.RED),
+ "Trophy Fish Chance" to StatFormatting("%", ChatFormatting.GREEN),
+ "Health" to StatFormatting("", ChatFormatting.GREEN),
+ "Defense" to StatFormatting("", ChatFormatting.GREEN),
+ "Fishing Speed" to StatFormatting("", ChatFormatting.GREEN),
+ "Double Hook Chance" to StatFormatting("%", ChatFormatting.GREEN),
+ "Mining Speed" to StatFormatting("", ChatFormatting.GREEN),
+ "Mining Fortune" to StatFormatting("", ChatFormatting.GREEN),
+ "Heat Resistance" to StatFormatting("", ChatFormatting.GREEN),
+ "Swing Range" to StatFormatting("", ChatFormatting.GREEN),
+ "Rift Time" to StatFormatting("", ChatFormatting.GREEN),
+ "Speed" to StatFormatting("", ChatFormatting.GREEN),
+ "Farming Fortune" to StatFormatting("", ChatFormatting.GREEN),
+ "True Defense" to StatFormatting("", ChatFormatting.GREEN),
+ "Mending" to StatFormatting("", ChatFormatting.GREEN),
+ "Foraging Wisdom" to StatFormatting("", ChatFormatting.GREEN),
+ "Farming Wisdom" to StatFormatting("", ChatFormatting.GREEN),
+ "Foraging Fortune" to StatFormatting("", ChatFormatting.GREEN),
+ "Magic Find" to StatFormatting("", ChatFormatting.GREEN),
+ "Ferocity" to StatFormatting("", ChatFormatting.GREEN),
+ "Bonus Pest Chance" to StatFormatting("%", ChatFormatting.GREEN),
+ "Cold Resistance" to StatFormatting("", ChatFormatting.GREEN),
+ "Pet Luck" to StatFormatting("", ChatFormatting.GREEN),
+ "Fear" to StatFormatting("", ChatFormatting.GREEN),
+ "Mana Regen" to StatFormatting("%", ChatFormatting.GREEN),
+ "Rift Damage" to StatFormatting("", ChatFormatting.GREEN),
+ "Hearts" to StatFormatting("", ChatFormatting.GREEN),
+ "Vitality" to StatFormatting("", ChatFormatting.GREEN),
// TODO: make this a repo json
)
@@ -197,21 +197,21 @@ data class SBItemStack constructor(
private val statLabelRegex = "(?<statName>.*): ".toPattern()
enum class BuffKind(
- val color: Formatting,
+ val color: ChatFormatting,
val prefix: String,
val postFix: String,
val isHidden: Boolean,
) {
- REFORGE(Formatting.BLUE, "(", ")", false),
- STAR_BUFF(Formatting.RESET, "", "", true),
- CATA_STAR_BUFF(Formatting.DARK_GRAY, "(", ")", false),
+ REFORGE(ChatFormatting.BLUE, "(", ")", false),
+ STAR_BUFF(ChatFormatting.RESET, "", "", true),
+ CATA_STAR_BUFF(ChatFormatting.DARK_GRAY, "(", ")", false),
;
}
data class StatLine(
val statName: String,
- val value: Text?,
- val rest: List<Text> = listOf(),
+ val value: Component?,
+ val rest: List<Component> = listOf(),
val valueNum: Double? = value?.directLiteralStringContent?.trim(' ', 's', '%', '+')?.toDoubleOrNull()
) {
fun addStat(amount: Double, buffKind: BuffKind): StatLine {
@@ -222,7 +222,7 @@ data class SBItemStack constructor(
rest = rest +
if (buffKind.isHidden) emptyList()
else listOf(
- Text.literal(
+ Component.literal(
buffKind.prefix + formattedAmount +
statFormatting.postFix +
buffKind.postFix + " "
@@ -233,7 +233,7 @@ data class SBItemStack constructor(
}
fun formatValue() =
- Text.literal(
+ Component.literal(
FirmFormatters.formatCommas(
valueNum ?: 0.0,
1,
@@ -242,7 +242,7 @@ data class SBItemStack constructor(
)
.setStyle(Style.EMPTY.withColor(statFormatting.color))
- val statFormatting = formattingOverrides[statName] ?: StatFormatting("", Formatting.GREEN)
+ val statFormatting = formattingOverrides[statName] ?: StatFormatting("", ChatFormatting.GREEN)
private fun abbreviate(abbreviateTo: Int): String {
if (abbreviateTo >= statName.length) return statName
val segments = statName.split(" ")
@@ -251,9 +251,9 @@ data class SBItemStack constructor(
}
}
- fun reconstitute(abbreviateTo: Int = Int.MAX_VALUE): Text =
- Text.literal("").setStyle(Style.EMPTY.withItalic(false))
- .append(Text.literal("${abbreviate(abbreviateTo)}: ").grey())
+ fun reconstitute(abbreviateTo: Int = Int.MAX_VALUE): Component =
+ Component.literal("").setStyle(Style.EMPTY.withItalic(false))
+ .append(Component.literal("${abbreviate(abbreviateTo)}: ").grey())
.append(value ?: formatValue())
.also { rest.forEach(it::append) }
}
@@ -263,10 +263,10 @@ data class SBItemStack constructor(
return segments.joinToString(" ") { it.replaceFirstChar { it.uppercaseChar() } }
}
- fun parseStatLine(line: Text): StatLine? {
+ fun parseStatLine(line: Component): StatLine? {
val sibs = line.siblings
val stat = sibs.firstOrNull() ?: return null
- if (stat.style.color != TextColor.fromFormatting(Formatting.GRAY)) return null
+ if (stat.style.color != TextColor.fromLegacyFormat(ChatFormatting.GRAY)) return null
val statLabel = stat.directLiteralStringContent ?: return null
val statName = statLabelRegex.useMatch(statLabel) { group("statName") } ?: return null
return StatLine(statName, sibs[1], sibs.subList(2, sibs.size))
@@ -329,7 +329,7 @@ data class SBItemStack constructor(
val reforge = ReforgeStore.modifierLut[reforgeId] ?: return
val reforgeStats = reforge.reforgeStats?.get(rarity) ?: mapOf()
itemStack.displayNameAccordingToNbt = itemStack.displayNameAccordingToNbt.copy()
- .prepend(Text.literal(reforge.reforgeName + " ").formatted(Rarity.colourMap[rarity] ?: Formatting.WHITE))
+ .prepend(Component.literal(reforge.reforgeName + " ").withStyle(Rarity.colourMap[rarity] ?: ChatFormatting.WHITE))
val data = itemStack.extraAttributes.copy()
data.putString("modifier", reforgeId.id)
itemStack.extraAttributes = data
@@ -339,11 +339,11 @@ data class SBItemStack constructor(
.grey()
itemStack.modifyLore {
val lastBlank = it.indexOfLa