From 7e0151569477df63601be50c82177ecfd21e5deb Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Fri, 26 Apr 2024 18:04:45 +0200 Subject: Bump to 1.20.5 --- src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt | 29 +++++++--------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt') diff --git a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt index 5a7a116..4ae226e 100644 --- a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt +++ b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt @@ -10,33 +10,22 @@ package moe.nea.firmament.util import net.minecraft.item.ItemStack import net.minecraft.nbt.NbtCompound import net.minecraft.nbt.NbtList -import net.minecraft.nbt.NbtString import net.minecraft.text.Text +import moe.nea.firmament.util.item.loreAccordingToNbt fun ItemStack.appendLore(args: List) { if (args.isEmpty()) return - val compoundTag = getOrCreateSubNbt("display") - val loreList = compoundTag.getOrCreateList("Lore", NbtString.STRING_TYPE) - for (arg in args) { - loreList.add(NbtString.of(Text.Serialization.toJsonString(arg))) + modifyLore { + val loreList = loreAccordingToNbt.toMutableList() + for (arg in args) { + loreList.add(arg) + } + loreList } } fun ItemStack.modifyLore(update: (List) -> List) { - val compoundTag = getOrCreateSubNbt("display") - val loreList = compoundTag.getOrCreateList("Lore", NbtString.STRING_TYPE) - val parsed = loreList.map { Text.Serialization.fromJson(it.asString())!! } - val updated = update(parsed) - loreList.clear() - loreList.addAll(updated.map { NbtString.of(Text.Serialization.toJsonString(it)) }) -} - - -fun NbtCompound.getOrCreateList(label: String, tag: Byte): NbtList = getList(label, tag.toInt()).also { - put(label, it) -} - -fun NbtCompound.getOrCreateCompoundTag(label: String): NbtCompound = getCompound(label).also { - put(label, it) + val loreList = loreAccordingToNbt + loreAccordingToNbt = update(loreList) } -- cgit