aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-07-29 20:51:53 +0200
committernea <romangraef@gmail.com>2022-07-29 20:51:53 +0200
commitf4bf70032a45b4daa7805ca38f2d820645dc9a6b (patch)
treedc91fa8e13b78ac9a7fcda24a26894e430f7fc84 /src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt
parent386ee78026801bf50d9cba24de541ed087f145d6 (diff)
downloadfirmament-f4bf70032a45b4daa7805ca38f2d820645dc9a6b.tar.gz
firmament-f4bf70032a45b4daa7805ca38f2d820645dc9a6b.tar.bz2
firmament-f4bf70032a45b4daa7805ca38f2d820645dc9a6b.zip
no arch
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt')
-rw-r--r--src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt
new file mode 100644
index 0000000..d5b8881
--- /dev/null
+++ b/src/main/kotlin/moe/nea/notenoughupdates/util/ItemUtil.kt
@@ -0,0 +1,23 @@
+package moe.nea.notenoughupdates.util
+
+import net.minecraft.nbt.CompoundTag
+import net.minecraft.nbt.ListTag
+import net.minecraft.nbt.StringTag
+import net.minecraft.network.chat.Component
+import net.minecraft.world.item.ItemStack
+
+fun ItemStack.appendLore(args: List<Component>) {
+ val compoundTag = getOrCreateTagElement("display")
+ val loreList = compoundTag.getOrCreateList("Lore", StringTag.TAG_STRING)
+ for (arg in args) {
+ loreList.add(StringTag.valueOf(Component.Serializer.toJson(arg)))
+ }
+}
+
+fun CompoundTag.getOrCreateList(label: String, tag: Byte): ListTag = getList(label, tag.toInt()).also {
+ put(label, it)
+}
+
+fun CompoundTag.getOrCreateCompoundTag(label: String): CompoundTag = getCompound(label).also {
+ put(label, it)
+}