aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt
new file mode 100644
index 0000000..604d29c
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/LorePredicate.kt
@@ -0,0 +1,28 @@
+/*
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+package moe.nea.firmament.features.texturepack
+
+import com.google.gson.JsonElement
+import net.minecraft.item.ItemStack
+import net.minecraft.nbt.NbtElement
+import net.minecraft.nbt.NbtString
+
+class LorePredicate(val matcher: StringMatcher) : FirmamentModelPredicate {
+ object Parser : FirmamentModelPredicateParser {
+ override fun parse(jsonElement: JsonElement): FirmamentModelPredicate {
+ return LorePredicate(StringMatcher.parse(jsonElement))
+ }
+ }
+
+ override fun test(stack: ItemStack): Boolean {
+ val display = stack.getOrCreateSubNbt(ItemStack.DISPLAY_KEY)
+ if (!display.contains(ItemStack.LORE_KEY, NbtElement.LIST_TYPE.toInt()))
+ return false
+ val lore = display.getList(ItemStack.LORE_KEY, NbtElement.STRING_TYPE.toInt())
+ return lore.any { matcher.matches(it as NbtString)}
+ }
+}