diff options
Diffstat (limited to 'src/main/kotlin/features/debug')
5 files changed, 17 insertions, 25 deletions
diff --git a/src/main/kotlin/features/debug/ExportedTestConstantMeta.kt b/src/main/kotlin/features/debug/ExportedTestConstantMeta.kt index f0250dc..bdc1f9a 100644 --- a/src/main/kotlin/features/debug/ExportedTestConstantMeta.kt +++ b/src/main/kotlin/features/debug/ExportedTestConstantMeta.kt @@ -12,7 +12,7 @@ data class ExportedTestConstantMeta( ) { companion object { val current = ExportedTestConstantMeta( - SharedConstants.getGameVersion().saveVersion.id, + SharedConstants.getGameVersion().dataVersion().id, Optional.of("Firmament ${Firmament.version.friendlyString}") ) diff --git a/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt b/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt index 2a56204..386a741 100644 --- a/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt +++ b/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt @@ -51,7 +51,10 @@ object ItemExporter { nonOverlayCache.clear() val exporter = LegacyItemExporter.createExporter(itemStack) var json = exporter.exportJson() - val fileName = json.jsonObject["internalname"]!!.jsonPrimitive.content + val fileName = json.jsonObject["internalname"]?.jsonPrimitive?.takeIf { it.isString }?.content + if (fileName == null) { + return tr("firmament.repoexport.nointernalname", "Could not find internal name to export for this item (null.json)") + } val itemFile = RepoDownloadManager.repoSavedLocation.resolve("items").resolve("${fileName}.json") itemFile.createParentDirectories() if (itemFile.exists()) { diff --git a/src/main/kotlin/features/debug/itemeditor/LegacyItemData.kt b/src/main/kotlin/features/debug/itemeditor/LegacyItemData.kt index bc8c618..4b647c7 100644 --- a/src/main/kotlin/features/debug/itemeditor/LegacyItemData.kt +++ b/src/main/kotlin/features/debug/itemeditor/LegacyItemData.kt @@ -1,15 +1,13 @@ package moe.nea.firmament.features.debug.itemeditor import kotlinx.serialization.Serializable -import kotlin.jvm.optionals.getOrNull -import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound import net.minecraft.util.Identifier 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 +import moe.nea.firmament.util.mc.loadItemFromNbt /** * Load data based on [prismarine.js' 1.8 item data](https://github.com/PrismarineJS/minecraft-data/blob/master/data/pc/1.8/items.json) @@ -68,8 +66,8 @@ object LegacyItemData { putByte("Count", 1) putShort("Damage", legacyItemType.metadata) })!! - val stack = ItemStack.fromNbt(MC.defaultRegistries, nbt).getOrNull() - ?: error("Could not transform ${legacyItemType}") + nbt.remove("components") + val stack = loadItemFromNbt(nbt) ?: error("Could not transform $legacyItemType: $nbt") stack.item to legacyItemType } }.toMap() diff --git a/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt b/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt index ecf3d2c..20ab2c3 100644 --- a/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt +++ b/src/main/kotlin/features/debug/itemeditor/LegacyItemExporter.kt @@ -33,6 +33,7 @@ import moe.nea.firmament.util.json.toJsonArray import moe.nea.firmament.util.mc.displayNameAccordingToNbt import moe.nea.firmament.util.mc.loreAccordingToNbt import moe.nea.firmament.util.mc.toNbtList +import moe.nea.firmament.util.modifyExtraAttributes import moe.nea.firmament.util.skyBlockId import moe.nea.firmament.util.skyblock.Rarity import moe.nea.firmament.util.transformEachRecursively @@ -45,6 +46,7 @@ class LegacyItemExporter private constructor(var itemStack: ItemStack) { } var lore = itemStack.loreAccordingToNbt + val originalId = itemStack.extraAttributes.getString("id") var name = itemStack.displayNameAccordingToNbt val extraAttribs = itemStack.extraAttributes.copy() val legacyNbt = NbtCompound() @@ -195,8 +197,12 @@ class LegacyItemExporter private constructor(var itemStack: ItemStack) { } fun exportModernSnbt(): NbtElement { - val overlay = ItemStack.CODEC.encodeStart(NbtOps.INSTANCE, itemStack) - .orThrow + val overlay = ItemStack.CODEC.encodeStart(NbtOps.INSTANCE, itemStack.copy().also { + it.modifyExtraAttributes { attribs -> + originalId.ifPresent { attribs.putString("id", it) } + attribs + } + }).orThrow val overlayWithVersion = ExportedTestConstantMeta.SOURCE_CODEC.encode(ExportedTestConstantMeta.current, NbtOps.INSTANCE, overlay) .orThrow @@ -284,7 +290,7 @@ class LegacyItemExporter private constructor(var itemStack: ItemStack) { fun copyLegacySkullNbt() { val profile = itemStack.get(DataComponentTypes.PROFILE) ?: return legacyNbt.put("SkullOwner", NbtCompound().apply { - profile.id.ifPresent { + profile.uuid.ifPresent { putString("Id", it.toString()) } putBoolean("hypixelPopulated", true) diff --git a/src/main/kotlin/features/debug/itemeditor/PromptScreen.kt b/src/main/kotlin/features/debug/itemeditor/PromptScreen.kt deleted file mode 100644 index 187b70b..0000000 --- a/src/main/kotlin/features/debug/itemeditor/PromptScreen.kt +++ /dev/null @@ -1,15 +0,0 @@ -package moe.nea.firmament.features.debug.itemeditor - -import io.github.notenoughupdates.moulconfig.gui.CloseEventListener -import io.github.notenoughupdates.moulconfig.gui.GuiComponentWrapper -import io.github.notenoughupdates.moulconfig.gui.GuiContext -import io.github.notenoughupdates.moulconfig.gui.component.CenterComponent -import io.github.notenoughupdates.moulconfig.gui.component.ColumnComponent -import io.github.notenoughupdates.moulconfig.gui.component.PanelComponent -import io.github.notenoughupdates.moulconfig.gui.component.TextComponent -import io.github.notenoughupdates.moulconfig.gui.component.TextFieldComponent -import io.github.notenoughupdates.moulconfig.observer.GetSetter -import kotlin.reflect.KMutableProperty0 -import moe.nea.firmament.gui.FirmButtonComponent -import moe.nea.firmament.util.MoulConfigUtils - |
