diff options
author | Linnea Gräf <nea@nea.moe> | 2025-07-06 00:37:46 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-07-06 00:37:46 +0200 |
commit | 44b817f7b9852f8974b652c126e1e9aacc5475ac (patch) | |
tree | c4f1f4df6ebd5f8a8bf16b6eb7c741da03db1ea3 /src/main/kotlin/features/debug | |
parent | 4140a24a0b15b9d3a112ebe934ed7929ce5ffd04 (diff) | |
download | Firmament-44b817f7b9852f8974b652c126e1e9aacc5475ac.tar.gz Firmament-44b817f7b9852f8974b652c126e1e9aacc5475ac.tar.bz2 Firmament-44b817f7b9852f8974b652c126e1e9aacc5475ac.zip |
fix: potion effects in exporter
Diffstat (limited to 'src/main/kotlin/features/debug')
-rw-r--r-- | src/main/kotlin/features/debug/itemeditor/LegacyItemData.kt | 14 | ||||
-rw-r--r-- | src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt | 22 |
2 files changed, 35 insertions, 1 deletions
diff --git a/src/main/kotlin/features/debug/itemeditor/LegacyItemData.kt b/src/main/kotlin/features/debug/itemeditor/LegacyItemData.kt index c0f48ca..bc8c618 100644 --- a/src/main/kotlin/features/debug/itemeditor/LegacyItemData.kt +++ b/src/main/kotlin/features/debug/itemeditor/LegacyItemData.kt @@ -9,6 +9,7 @@ import moe.nea.firmament.Firmament import moe.nea.firmament.repo.ExpensiveItemCacheApi import moe.nea.firmament.repo.ItemCache import moe.nea.firmament.util.MC +import moe.nea.firmament.util.StringUtil.camelWords /** * Load data based on [prismarine.js' 1.8 item data](https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/items.json) @@ -58,6 +59,7 @@ object LegacyItemData { val enchantmentLut = enchantmentData.associateBy { Identifier.ofVanilla(it.name) } val itemDat = getLegacyData<List<ItemData>>("items") + @OptIn(ExpensiveItemCacheApi::class) // This is fine, we get loaded in a thread. val itemLut = itemDat.flatMap { item -> item.allVariants().map { legacyItemType -> @@ -72,4 +74,16 @@ object LegacyItemData { } }.toMap() + @Serializable + data class LegacyEffect( + val id: Int, + val name: String, + val displayName: String, + val type: String + ) + + val effectList = getLegacyData<List<LegacyEffect>>("effects") + .associateBy { + it.name.camelWords().map { it.trim().lowercase() }.joinToString("_") + } } diff --git a/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt b/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt index c35a892..ad03b16 100644 --- a/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt +++ b/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt @@ -7,11 +7,12 @@ import kotlinx.serialization.json.put import kotlin.concurrent.thread import net.minecraft.component.DataComponentTypes import net.minecraft.item.ItemStack +import net.minecraft.nbt.NbtByte import net.minecraft.nbt.NbtCompound import net.minecraft.nbt.NbtElement import net.minecraft.nbt.NbtInt +import net.minecraft.nbt.NbtList import net.minecraft.nbt.NbtOps -import net.minecraft.nbt.NbtPrimitive import net.minecraft.nbt.NbtString import net.minecraft.text.Text import net.minecraft.util.Unit @@ -135,6 +136,7 @@ class LegacyItemExporter private constructor(var itemStack: ItemStack) { legacyNbt.put("HideFlags", NbtInt.of(254)) copyUnbreakable() copyItemModel() + copyPotion() copyExtraAttributes() copyLegacySkullNbt() copyDisplay() @@ -144,6 +146,24 @@ class LegacyItemExporter private constructor(var itemStack: ItemStack) { // TODO: copyDisplay } + private fun copyPotion() { + val effects = itemStack.get(DataComponentTypes.POTION_CONTENTS) ?: return + legacyNbt.put("CustomPotionEffects", NbtList().also { + effects.effects.forEach { effect -> + val effectId = effect.effectType.key.get().value.path + val duration = effect.duration + val legacyId = LegacyItemData.effectList[effectId]!! + + it.add(NbtCompound().apply { + put("Ambient", NbtByte.of(false)) + put("Duration", NbtInt.of(duration)) + put("Id", NbtByte.of(legacyId.id.toByte())) + put("Amplifier", NbtByte.of(effect.amplifier.toByte())) + }) + } + }) + } + fun NbtCompound.getOrPutCompound(name: String): NbtCompound { val compound = getCompoundOrEmpty(name) put(name, compound) |