aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/mc
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-07-17 11:52:28 +0200
committerLinnea Gräf <nea@nea.moe>2025-07-17 11:52:28 +0200
commit25f0e7fd62db22036969120843165f4759530b8f (patch)
tree262ed44e0e68464ba99f7650fed8df102c982fe5 /src/main/kotlin/util/mc
parent13d64762bbf110fbc52719fb9d93490648199dd2 (diff)
downloadFirmament-25f0e7fd62db22036969120843165f4759530b8f.tar.gz
Firmament-25f0e7fd62db22036969120843165f4759530b8f.tar.bz2
Firmament-25f0e7fd62db22036969120843165f4759530b8f.zip
feat: Launch on 1.21.7
Diffstat (limited to 'src/main/kotlin/util/mc')
-rw-r--r--src/main/kotlin/util/mc/ItemUtil.kt30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/main/kotlin/util/mc/ItemUtil.kt b/src/main/kotlin/util/mc/ItemUtil.kt
index 13519cf..3cabb8e 100644
--- a/src/main/kotlin/util/mc/ItemUtil.kt
+++ b/src/main/kotlin/util/mc/ItemUtil.kt
@@ -1,20 +1,30 @@
package moe.nea.firmament.util.mc
+import kotlin.jvm.optionals.getOrNull
import net.minecraft.item.ItemStack
+import net.minecraft.nbt.NbtCompound
+import net.minecraft.nbt.NbtOps
+import net.minecraft.registry.RegistryOps
+import net.minecraft.registry.RegistryWrapper
import net.minecraft.text.Text
+import moe.nea.firmament.util.MC
fun ItemStack.appendLore(args: List<Text>) {
- if (args.isEmpty()) return
- modifyLore {
- val loreList = loreAccordingToNbt.toMutableList()
- for (arg in args) {
- loreList.add(arg)
- }
- loreList
- }
+ if (args.isEmpty()) return
+ modifyLore {
+ val loreList = loreAccordingToNbt.toMutableList()
+ for (arg in args) {
+ loreList.add(arg)
+ }
+ loreList
+ }
}
fun ItemStack.modifyLore(update: (List<Text>) -> List<Text>) {
- val loreList = loreAccordingToNbt
- loreAccordingToNbt = update(loreList)
+ val loreList = loreAccordingToNbt
+ loreAccordingToNbt = update(loreList)
+}
+
+fun loadItemFromNbt(nbt: NbtCompound, registries: RegistryWrapper.WrapperLookup = MC.defaultRegistries): ItemStack? {
+ return ItemStack.CODEC.decode(RegistryOps.of(NbtOps.INSTANCE, registries), nbt).result().getOrNull()?.first
}