diff options
author | Linnea Gräf <nea@nea.moe> | 2025-06-18 00:35:51 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-06-18 00:35:51 +0200 |
commit | 4a29d86e477c41327bc97f75c332e37e3dae9bbe (patch) | |
tree | 2b9b61bad629f160d974b8fbccb6fce21972cd8d /src/main/kotlin/util/mc | |
parent | 4b9e966ca7e8a9291f307850f715820e122d69fd (diff) | |
download | Firmament-4a29d86e477c41327bc97f75c332e37e3dae9bbe.tar.gz Firmament-4a29d86e477c41327bc97f75c332e37e3dae9bbe.tar.bz2 Firmament-4a29d86e477c41327bc97f75c332e37e3dae9bbe.zip |
feat: Add 1.8.9 item exporter
Diffstat (limited to 'src/main/kotlin/util/mc')
-rw-r--r-- | src/main/kotlin/util/mc/NbtUtil.kt | 10 | ||||
-rw-r--r-- | src/main/kotlin/util/mc/SNbtFormatter.kt | 7 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/main/kotlin/util/mc/NbtUtil.kt b/src/main/kotlin/util/mc/NbtUtil.kt new file mode 100644 index 0000000..cc98142 --- /dev/null +++ b/src/main/kotlin/util/mc/NbtUtil.kt @@ -0,0 +1,10 @@ +package moe.nea.firmament.util.mc + +import net.minecraft.nbt.NbtElement +import net.minecraft.nbt.NbtList + +fun Iterable<NbtElement>.toNbtList() = NbtList().also { + for(element in this) { + it.add(element) + } +} diff --git a/src/main/kotlin/util/mc/SNbtFormatter.kt b/src/main/kotlin/util/mc/SNbtFormatter.kt index e2c24f6..7617d17 100644 --- a/src/main/kotlin/util/mc/SNbtFormatter.kt +++ b/src/main/kotlin/util/mc/SNbtFormatter.kt @@ -110,7 +110,7 @@ class SNbtFormatter private constructor() : NbtElementVisitor { keys.forEachIndexed { index, key -> writeIndent() val element = compound[key] ?: error("Key '$key' found but not present in compound: $compound") - val escapedName = if (key.matches(SIMPLE_NAME)) key else NbtString.escape(key) + val escapedName = escapeName(key) result.append(escapedName).append(": ") element.accept(this) if (keys.size != index + 1) { @@ -134,6 +134,9 @@ class SNbtFormatter private constructor() : NbtElementVisitor { fun NbtElement.toPrettyString() = prettify(this) - private val SIMPLE_NAME = "[A-Za-z0-9._+-]+".toRegex() + fun escapeName(key: String): String = + if (key.matches(SIMPLE_NAME)) key else NbtString.escape(key) + + val SIMPLE_NAME = "[A-Za-z0-9._+-]+".toRegex() } } |