Add item predicate
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
Logic operators allow to combine other firmament predicates into one. This is done by building boolean operators:
|
Logic operators allow to combine other firmament predicates into one. This is done by building boolean operators:
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ object CustomModelOverrideParser {
|
|||||||
registerPredicateParser("all", AndPredicate.Parser)
|
registerPredicateParser("all", AndPredicate.Parser)
|
||||||
registerPredicateParser("any", OrPredicate.Parser)
|
registerPredicateParser("any", OrPredicate.Parser)
|
||||||
registerPredicateParser("not", NotPredicate.Parser)
|
registerPredicateParser("not", NotPredicate.Parser)
|
||||||
|
registerPredicateParser("item", ItemPredicate.Parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun parsePredicates(predicates: JsonObject): List<FirmamentModelPredicate> {
|
fun parsePredicates(predicates: JsonObject): List<FirmamentModelPredicate> {
|
||||||
@@ -50,7 +51,7 @@ object CustomModelOverrideParser {
|
|||||||
if (!predicateName.startsWith("firmament:")) continue
|
if (!predicateName.startsWith("firmament:")) continue
|
||||||
val identifier = Identifier(predicateName)
|
val identifier = Identifier(predicateName)
|
||||||
val parser = predicateParsers[identifier] ?: continue
|
val parser = predicateParsers[identifier] ?: continue
|
||||||
val parsedPredicate = parser.parse(predicates[predicateName])
|
val parsedPredicate = parser.parse(predicates[predicateName]) ?: continue
|
||||||
parsedPredicates.add(parsedPredicate)
|
parsedPredicates.add(parsedPredicate)
|
||||||
}
|
}
|
||||||
return parsedPredicates
|
return parsedPredicates
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ package moe.nea.firmament.features.texturepack
|
|||||||
import com.google.gson.JsonElement
|
import com.google.gson.JsonElement
|
||||||
|
|
||||||
interface FirmamentModelPredicateParser {
|
interface FirmamentModelPredicateParser {
|
||||||
fun parse(jsonElement: JsonElement): FirmamentModelPredicate
|
fun parse(jsonElement: JsonElement): FirmamentModelPredicate?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import net.minecraft.client.MinecraftClient
|
|||||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||||
import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket
|
import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket
|
||||||
import net.minecraft.registry.BuiltinRegistries
|
import net.minecraft.registry.BuiltinRegistries
|
||||||
|
import net.minecraft.registry.RegistryKeys
|
||||||
import net.minecraft.registry.RegistryWrapper
|
import net.minecraft.registry.RegistryWrapper
|
||||||
import net.minecraft.resource.ReloadableResourceManagerImpl
|
import net.minecraft.resource.ReloadableResourceManagerImpl
|
||||||
import net.minecraft.text.Text
|
import net.minecraft.text.Text
|
||||||
@@ -74,6 +75,7 @@ object MC {
|
|||||||
inline val window get() = MinecraftClient.getInstance().window
|
inline val window get() = MinecraftClient.getInstance().window
|
||||||
inline val currentRegistries: RegistryWrapper.WrapperLookup? get() = world?.registryManager
|
inline val currentRegistries: RegistryWrapper.WrapperLookup? get() = world?.registryManager
|
||||||
val defaultRegistries: RegistryWrapper.WrapperLookup = BuiltinRegistries.createWrapperLookup()
|
val defaultRegistries: RegistryWrapper.WrapperLookup = BuiltinRegistries.createWrapperLookup()
|
||||||
|
val defaultItems = defaultRegistries.getWrapperOrThrow(RegistryKeys.ITEM)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user