aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-07-06 00:11:30 +0200
committerLinnea Gräf <nea@nea.moe>2025-07-06 00:11:30 +0200
commit4140a24a0b15b9d3a112ebe934ed7929ce5ffd04 (patch)
treea5c485742e90bdb36ee88c40473044641d0109a9
parent2cf4ff06ff8293e5fe4958a12738d851a2fcd74a (diff)
downloadFirmament-4140a24a0b15b9d3a112ebe934ed7929ce5ffd04.tar.gz
Firmament-4140a24a0b15b9d3a112ebe934ed7929ce5ffd04.tar.bz2
Firmament-4140a24a0b15b9d3a112ebe934ed7929ce5ffd04.zip
fix: export color in item exporter
-rw-r--r--src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt b/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt
index 3cd1ce8..c35a892 100644
--- a/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt
+++ b/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt
@@ -11,6 +11,7 @@ import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtElement
import net.minecraft.nbt.NbtInt
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
@@ -36,8 +37,9 @@ import moe.nea.firmament.util.unformattedString
class LegacyItemExporter private constructor(var itemStack: ItemStack) {
init {
- require(!itemStack.isEmpty)
+ require(!itemStack.isEmpty)
}
+
var lore = itemStack.loreAccordingToNbt
var name = itemStack.displayNameAccordingToNbt
val extraAttribs = itemStack.extraAttributes.copy()
@@ -136,21 +138,33 @@ class LegacyItemExporter private constructor(var itemStack: ItemStack) {
copyExtraAttributes()
copyLegacySkullNbt()
copyDisplay()
+ copyColour()
copyEnchantments()
copyEnchantGlint()
// TODO: copyDisplay
}
+ fun NbtCompound.getOrPutCompound(name: String): NbtCompound {
+ val compound = getCompoundOrEmpty(name)
+ put(name, compound)
+ return compound
+ }
+
+ private fun copyColour() {
+ val leatherTint = itemStack.get(DataComponentTypes.DYED_COLOR) ?: return
+ legacyNbt.getOrPutCompound("display").put("color", NbtInt.of(leatherTint.rgb))
+ }
+
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 {
+ legacyNbt.getOrPutCompound("display").apply {
put("Lore", lore.map { NbtString.of(it.getLegacyFormatString(trimmed = true)) }.toNbtList())
putString("Name", name.getLegacyFormatString(trimmed = true))
- })
+ }
}
fun exportModernSnbt(): NbtElement {