aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/Texture Pack Format.md8
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt3
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/FirmamentModelPredicateParser.kt2
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/ItemPredicate.kt37
-rw-r--r--src/main/kotlin/moe/nea/firmament/util/MC.kt2
5 files changed, 50 insertions, 2 deletions
diff --git a/docs/Texture Pack Format.md b/docs/Texture Pack Format.md
index bebcbb4..1aedde9 100644
--- a/docs/Texture Pack Format.md
+++ b/docs/Texture Pack Format.md
@@ -78,6 +78,14 @@ Tries to find at least one lore line that matches the given [string matcher](#st
}
```
+#### Item type
+
+Filter by item type:
+
+```json
+"firmament:item": "minecraft:clock"
+```
+
#### Logic Operators
Logic operators allow to combine other firmament predicates into one. This is done by building boolean operators:
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt
index d512dec..538c63f 100644
--- a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt
@@ -42,6 +42,7 @@ object CustomModelOverrideParser {
registerPredicateParser("all", AndPredicate.Parser)
registerPredicateParser("any", OrPredicate.Parser)
registerPredicateParser("not", NotPredicate.Parser)
+ registerPredicateParser("item", ItemPredicate.Parser)
}
fun parsePredicates(predicates: JsonObject): List<FirmamentModelPredicate> {
@@ -50,7 +51,7 @@ object CustomModelOverrideParser {
if (!predicateName.startsWith("firmament:")) continue
val identifier = Identifier(predicateName)
val parser = predicateParsers[identifier] ?: continue
- val parsedPredicate = parser.parse(predicates[predicateName])
+ val parsedPredicate = parser.parse(predicates[predicateName]) ?: continue
parsedPredicates.add(parsedPredicate)
}
return parsedPredicates
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/FirmamentModelPredicateParser.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/FirmamentModelPredicateParser.kt
index de7557a..e999679 100644
--- a/src/main/kotlin/moe/nea/firmament/features/texturepack/FirmamentModelPredicateParser.kt
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/FirmamentModelPredicateParser.kt
@@ -9,5 +9,5 @@ package moe.nea.firmament.features.texturepack
import com.google.gson.JsonElement
interface FirmamentModelPredicateParser {
- fun parse(jsonElement: JsonElement): FirmamentModelPredicate
+ fun parse(jsonElement: JsonElement): FirmamentModelPredicate?
}
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/ItemPredicate.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/ItemPredicate.kt
new file mode 100644
index 0000000..1464037
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/ItemPredicate.kt
@@ -0,0 +1,37 @@
+/*
+ * 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 com.google.gson.JsonPrimitive
+import kotlin.jvm.optionals.getOrNull
+import net.minecraft.item.Item
+import net.minecraft.item.ItemStack
+import net.minecraft.registry.RegistryKey
+import net.minecraft.registry.RegistryKeys
+import net.minecraft.util.Identifier
+import moe.nea.firmament.util.MC
+
+class ItemPredicate(
+ val item: Item
+) : FirmamentModelPredicate {
+ override fun test(stack: ItemStack): Boolean {
+ return stack.item == item
+ }
+
+ object Parser : FirmamentModelPredicateParser {
+ override fun parse(jsonElement: JsonElement): ItemPredicate? {
+ if (jsonElement is JsonPrimitive && jsonElement.isString) {
+ val itemKey = RegistryKey.of(RegistryKeys.ITEM,
+ Identifier.tryParse(jsonElement.asString)
+ ?: return null)
+ return ItemPredicate(MC.defaultItems.getOptional(itemKey).getOrNull()?.value() ?: return null)
+ }
+ return null
+ }
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firmament/util/MC.kt b/src/main/kotlin/moe/nea/firmament/util/MC.kt
index 2fb1c75..830934f 100644
--- a/src/main/kotlin/moe/nea/firmament/util/MC.kt
+++ b/src/main/kotlin/moe/nea/firmament/util/MC.kt
@@ -13,6 +13,7 @@ import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket
import net.minecraft.registry.BuiltinRegistries
+import net.minecraft.registry.RegistryKeys
import net.minecraft.registry.RegistryWrapper
import net.minecraft.resource.ReloadableResourceManagerImpl
import net.minecraft.text.Text
@@ -74,6 +75,7 @@ object MC {
inline val window get() = MinecraftClient.getInstance().window
inline val currentRegistries: RegistryWrapper.WrapperLookup? get() = world?.registryManager
val defaultRegistries: RegistryWrapper.WrapperLookup = BuiltinRegistries.createWrapperLookup()
+ val defaultItems = defaultRegistries.getWrapperOrThrow(RegistryKeys.ITEM)
}