From a36c8f1c0eae969dcee8cf690f12d9121350212d Mon Sep 17 00:00:00 2001 From: nea Date: Sun, 11 Jun 2023 02:43:14 +0200 Subject: Add collection info to skill page --- src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) (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 25fb7d3..78627cd 100644 --- a/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt +++ b/src/main/kotlin/moe/nea/firmament/util/ItemUtil.kt @@ -33,6 +33,16 @@ fun ItemStack.appendLore(args: List) { } } +fun ItemStack.modifyLore(update: (List) -> List) { + val compoundTag = getOrCreateSubNbt("display") + val loreList = compoundTag.getOrCreateList("Lore", NbtString.STRING_TYPE) + val parsed = loreList.map { Text.Serializer.fromJson(it.asString())!! } + val updated = update(parsed) + loreList.clear() + loreList.addAll(updated.map { NbtString.of(Text.Serializer.toJson(it)) }) +} + + fun NbtCompound.getOrCreateList(label: String, tag: Byte): NbtList = getList(label, tag.toInt()).also { put(label, it) } -- cgit