feat: Add item model to export

This commit is contained in:
Linnea Gräf
2025-06-22 17:05:39 +02:00
parent d60276a4c1
commit 6fbdeb105a
2 changed files with 12 additions and 1 deletions

View File

@@ -106,6 +106,7 @@ class ItemExporter(var itemStack: ItemStack) {
// TODO: calculate hideflags
legacyNbt.put("HideFlags", NbtInt.of(254))
copyUnbreakable()
copyItemModel()
copyExtraAttributes()
copyLegacySkullNbt()
copyDisplay()
@@ -114,6 +115,11 @@ class ItemExporter(var itemStack: ItemStack) {
// TODO: copyDisplay
}
private fun copyItemModel() {
val itemModel = itemStack.get(DataComponentTypes.ITEM_MODEL) ?: return
legacyNbt.put("ItemModel", NbtString.of(itemModel.toString()))
}
private fun copyDisplay() {
legacyNbt.put("display", NbtCompound().apply {
put("Lore", lore.map { NbtString.of(it.getLegacyFormatString(trimmed = true)) }.toNbtList())

View File

@@ -31,6 +31,7 @@ import net.minecraft.nbt.NbtString
import net.minecraft.text.MutableText
import net.minecraft.text.Style
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import moe.nea.firmament.Firmament
import moe.nea.firmament.repo.RepoManager.initialize
import moe.nea.firmament.util.LegacyFormattingCode
@@ -147,10 +148,14 @@ object ItemCache : IReloadable {
ItemStack.fromNbt(MC.defaultRegistries, modernItemTag).getOrNull() ?: return brokenItemStack(this)
itemInstance.loreAccordingToNbt = lore.map { un189Lore(it) }
itemInstance.displayNameAccordingToNbt = un189Lore(displayName)
val extraAttributes = oldItemTag.getCompound("tag").flatMap { it.getCompound("ExtraAttributes") }
val tag = oldItemTag.getCompound("tag")
val extraAttributes = tag.flatMap { it.getCompound("ExtraAttributes") }
.getOrNull()
if (extraAttributes != null)
itemInstance.set(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(extraAttributes))
val itemModel = tag.flatMap { it.getString("ItemModel") }.getOrNull()
if (itemModel != null)
itemInstance.set(DataComponentTypes.ITEM_MODEL, Identifier.of(itemModel))
return itemInstance
} catch (e: Exception) {
e.printStackTrace()