aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-02-22 00:30:05 +0100
committerLinnea Gräf <nea@nea.moe>2024-02-26 15:37:12 +0100
commit602112724d8236c1ec6671e1893128862c9f5815 (patch)
treefd0695839af0b2a8296e8d3009432644212638ce /src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt
parent2e571210c948d90a7d0ea8b07184102ceb401962 (diff)
downloadfirmament-602112724d8236c1ec6671e1893128862c9f5815.tar.gz
firmament-602112724d8236c1ec6671e1893128862c9f5815.tar.bz2
firmament-602112724d8236c1ec6671e1893128862c9f5815.zip
Add custom model predicates
Add regex support Add and and or predicates
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt')
-rw-r--r--src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt
new file mode 100644
index 0000000..ac62eaa
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt
@@ -0,0 +1,48 @@
+/*
+ * 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.JsonObject
+import net.minecraft.util.Identifier
+
+object CustomModelOverrideParser {
+
+ val predicateParsers = mutableMapOf<Identifier, FirmamentModelPredicateParser>()
+
+
+ fun registerPredicateParser(name: String, parser: FirmamentModelPredicateParser) {
+ predicateParsers[Identifier("firmament", name)] = parser
+ }
+
+ init {
+ registerPredicateParser("display_name", DisplayNamePredicate.Parser)
+ registerPredicateParser("lore", LorePredicate.Parser)
+ registerPredicateParser("all", AndPredicate.Parser)
+ registerPredicateParser("any", OrPredicate.Parser)
+ }
+
+ fun parsePredicates(predicates: JsonObject): List<FirmamentModelPredicate> {
+ val parsedPredicates = mutableListOf<FirmamentModelPredicate>()
+ for (predicateName in predicates.keySet()) {
+ if (!predicateName.startsWith("firmament:")) continue
+ val identifier = Identifier(predicateName)
+ val parser = predicateParsers[identifier] ?: continue
+ val parsedPredicate = parser.parse(predicates[predicateName])
+ parsedPredicates.add(parsedPredicate)
+ }
+ return parsedPredicates
+ }
+
+ @JvmStatic
+ fun parseCustomModelOverrides(jsonObject: JsonObject): Array<FirmamentModelPredicate>? {
+ val predicates = (jsonObject["predicate"] as? JsonObject) ?: return null
+ val parsedPredicates = parsePredicates(predicates)
+ if (parsedPredicates.isEmpty())
+ return null
+ return parsedPredicates.toTypedArray()
+ }
+}