aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-06-23 00:24:56 +0200
committerLinnea Gräf <nea@nea.moe>2025-06-23 00:24:56 +0200
commitcd81fc6b189a14422e0a70324be65b6618ef04a6 (patch)
treebafa90954f1fbfe5a5dd710375cd75d1ae603265 /src
parent39e979ed221c3b05e505ad1f54db970074906420 (diff)
downloadFirmament-cd81fc6b189a14422e0a70324be65b6618ef04a6.tar.gz
Firmament-cd81fc6b189a14422e0a70324be65b6618ef04a6.tar.bz2
Firmament-cd81fc6b189a14422e0a70324be65b6618ef04a6.zip
feat: Re export lore / display name from json
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/features/debug/itemeditor/ItemExporter.kt49
-rw-r--r--src/main/kotlin/util/mc/NbtUtil.kt2
2 files changed, 50 insertions, 1 deletions
diff --git a/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt b/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt
index a800dad..5066942 100644
--- a/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt
+++ b/src/main/kotlin/features/debug/itemeditor/ItemExporter.kt
@@ -1,30 +1,43 @@
package moe.nea.firmament.features.debug.itemeditor
+import com.mojang.brigadier.arguments.StringArgumentType
import kotlinx.serialization.json.JsonArray
import kotlinx.serialization.json.JsonObject
+import kotlinx.serialization.json.JsonPrimitive
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import kotlin.io.path.createParentDirectories
import kotlin.io.path.exists
+import kotlin.io.path.notExists
import kotlin.io.path.readText
import kotlin.io.path.relativeTo
import kotlin.io.path.writeText
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
+import net.minecraft.nbt.NbtString
import net.minecraft.text.Text
import moe.nea.firmament.Firmament
import moe.nea.firmament.annotations.Subscribe
+import moe.nea.firmament.commands.get
+import moe.nea.firmament.commands.suggestsList
+import moe.nea.firmament.commands.thenArgument
+import moe.nea.firmament.commands.thenExecute
+import moe.nea.firmament.commands.thenLiteral
+import moe.nea.firmament.events.CommandEvent
import moe.nea.firmament.events.HandledScreenKeyPressedEvent
import moe.nea.firmament.features.debug.ExportedTestConstantMeta
import moe.nea.firmament.features.debug.PowerUserTools
import moe.nea.firmament.repo.RepoDownloadManager
import moe.nea.firmament.repo.RepoManager
+import moe.nea.firmament.util.LegacyTagParser
+import moe.nea.firmament.util.LegacyTagWriter.Companion.toLegacyString
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.SkyblockId
import moe.nea.firmament.util.focusedItemStack
import moe.nea.firmament.util.mc.SNbtFormatter.Companion.toPrettyString
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.setSkyBlockId
import moe.nea.firmament.util.skyBlockId
import moe.nea.firmament.util.tr
@@ -82,6 +95,42 @@ object ItemExporter {
}
@Subscribe
+ fun onCommand(event: CommandEvent.SubCommand) {
+ event.subcommand("dev") {
+ thenLiteral("reexportlore") {
+ thenArgument("itemid", StringArgumentType.string()) { itemid ->
+ suggestsList { RepoManager.neuRepo.items.items.keys }
+ thenExecute {
+ val itemid = SkyblockId(get(itemid))
+ if (pathFor(itemid).notExists()) {
+ MC.sendChat(
+ tr(
+ "firmament.repo.export.relore.fail",
+ "Could not find json file to relore for ${itemid}"
+ )
+ )
+ }
+ modifyJson(itemid) {
+ val mutJson = it.toMutableMap()
+ val legacyTag = LegacyTagParser.parse(mutJson["nbttag"]!!.jsonPrimitive.content)
+ val display = legacyTag.getCompoundOrEmpty("display")
+ legacyTag.put("display", display)
+ display.putString("Name", mutJson["displayname"]!!.jsonPrimitive.content)
+ display.put(
+ "Lore",
+ (mutJson["lore"] as JsonArray).map { NbtString.of(it.jsonPrimitive.content) }
+ .toNbtList()
+ )
+ mutJson["nbttag"] = JsonPrimitive(legacyTag.toLegacyString())
+ JsonObject(mutJson)
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Subscribe
fun onKeyBind(event: HandledScreenKeyPressedEvent) {
if (event.matches(PowerUserTools.TConfig.exportItemStackToRepo)) {
val itemStack = event.screen.focusedItemStack ?: return
diff --git a/src/main/kotlin/util/mc/NbtUtil.kt b/src/main/kotlin/util/mc/NbtUtil.kt
index cc98142..2cab1c7 100644
--- a/src/main/kotlin/util/mc/NbtUtil.kt
+++ b/src/main/kotlin/util/mc/NbtUtil.kt
@@ -4,7 +4,7 @@ import net.minecraft.nbt.NbtElement
import net.minecraft.nbt.NbtList
fun Iterable<NbtElement>.toNbtList() = NbtList().also {
- for(element in this) {
+ for (element in this) {
it.add(element)
}
}