diff options
author | Linnea Gräf <nea@nea.moe> | 2024-04-26 18:04:45 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-04-26 18:15:54 +0200 |
commit | 7e0151569477df63601be50c82177ecfd21e5deb (patch) | |
tree | f30e5440a1855de92d2b424ef79339d3d6cf5f34 /src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt | |
parent | 041da7c7d179df01c4048a81ddf40a9f13c3ce77 (diff) | |
download | Firmament-7e0151569477df63601be50c82177ecfd21e5deb.tar.gz Firmament-7e0151569477df63601be50c82177ecfd21e5deb.tar.bz2 Firmament-7e0151569477df63601be50c82177ecfd21e5deb.zip |
Bump to 1.20.5
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt | 29 |
1 files changed, 9 insertions, 20 deletions
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<Text>) { 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<Text>) -> List<Text>) { - 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) } |