From 98c52ff7978acc8a1e195033920240808b17d634 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Thu, 30 Jan 2025 20:34:12 +0100 Subject: feat: Parse 1.21.3 and below bow animations --- .../texturepack/CustomModelOverrideParser.kt | 7 ++++++ .../texturepack/FirmamentModelPredicate.kt | 5 +++-- .../features/texturepack/PredicateModel.kt | 2 +- .../texturepack/predicates/AndPredicate.kt | 7 +++--- .../texturepack/predicates/CastPredicate.kt | 9 ++++++-- .../texturepack/predicates/PullingPredicate.kt | 26 ++++++++++++++++++++++ 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/PullingPredicate.kt diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt index fca8944..4529d1d 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/CustomModelOverrideParser.kt @@ -22,6 +22,7 @@ import moe.nea.firmament.features.texturepack.predicates.LorePredicate import moe.nea.firmament.features.texturepack.predicates.NotPredicate import moe.nea.firmament.features.texturepack.predicates.OrPredicate import moe.nea.firmament.features.texturepack.predicates.PetPredicate +import moe.nea.firmament.features.texturepack.predicates.PullingPredicate import moe.nea.firmament.util.json.KJsonOps object CustomModelOverrideParser { @@ -79,6 +80,12 @@ object CustomModelOverrideParser { if (predicateName == "cast") { // 1.21.4 parsedPredicates.add(CastPredicate.Parser.parse(predicates[predicateName]) ?: return neverPredicate) } + if (predicateName == "pull") { + parsedPredicates.add(PullingPredicate.Parser.parse(predicates[predicateName]) ?: return neverPredicate) + } + if (predicateName == "pulling") { + parsedPredicates.add(PullingPredicate.AnyPulling) + } if (!predicateName.startsWith("firmament:")) continue val identifier = Identifier.of(predicateName) val parser = predicateParsers[identifier] ?: return neverPredicate diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/FirmamentModelPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/FirmamentModelPredicate.kt index d11fec0..6cef4ca 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/FirmamentModelPredicate.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/FirmamentModelPredicate.kt @@ -1,8 +1,9 @@ - package moe.nea.firmament.features.texturepack +import net.minecraft.entity.LivingEntity import net.minecraft.item.ItemStack interface FirmamentModelPredicate { - fun test(stack: ItemStack): Boolean + fun test(stack: ItemStack, holder: LivingEntity?): Boolean = test(stack) + fun test(stack: ItemStack): Boolean = test(stack, null) } diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/PredicateModel.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/PredicateModel.kt index b52e96b..0edad4c 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/PredicateModel.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/PredicateModel.kt @@ -39,7 +39,7 @@ class PredicateModel { ) { val model = overrides - .find { it.predicate.test(stack) } + .findLast { it.predicate.test(stack, user) } ?.model ?: fallback model.update(state, stack, resolver, transformationMode, world, user, seed) diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/AndPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/AndPredicate.kt index 99abaaa..70eb814 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/AndPredicate.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/AndPredicate.kt @@ -3,15 +3,16 @@ package moe.nea.firmament.features.texturepack.predicates import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonObject +import net.minecraft.entity.LivingEntity import moe.nea.firmament.features.texturepack.CustomModelOverrideParser import moe.nea.firmament.features.texturepack.FirmamentModelPredicate import moe.nea.firmament.features.texturepack.FirmamentModelPredicateParser import net.minecraft.item.ItemStack class AndPredicate(val children: Array) : FirmamentModelPredicate { - override fun test(stack: ItemStack): Boolean { - return children.all { it.test(stack) } - } + override fun test(stack: ItemStack, holder: LivingEntity?): Boolean { + return children.all { it.test(stack, holder) } + } object Parser : FirmamentModelPredicateParser { override fun parse(jsonElement: JsonElement): FirmamentModelPredicate { diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/CastPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/CastPredicate.kt index 7ccaadf..2b79c1a 100644 --- a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/CastPredicate.kt +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/CastPredicate.kt @@ -1,10 +1,11 @@ package moe.nea.firmament.features.texturepack.predicates import com.google.gson.JsonElement +import net.minecraft.entity.LivingEntity +import net.minecraft.entity.player.PlayerEntity import net.minecraft.item.ItemStack import moe.nea.firmament.features.texturepack.FirmamentModelPredicate import moe.nea.firmament.features.texturepack.FirmamentModelPredicateParser -import moe.nea.firmament.util.MC class CastPredicate : FirmamentModelPredicate { object Parser : FirmamentModelPredicateParser { @@ -14,7 +15,11 @@ class CastPredicate : FirmamentModelPredicate { } } + override fun test(stack: ItemStack, holder: LivingEntity?): Boolean { + return (holder as? PlayerEntity)?.fishHook != null && holder.activeItem === stack + } + override fun test(stack: ItemStack): Boolean { - return MC.player?.fishHook != null // TODO pass through more of the model predicate context + return false } } diff --git a/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/PullingPredicate.kt b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/PullingPredicate.kt new file mode 100644 index 0000000..fa46a70 --- /dev/null +++ b/src/texturePacks/java/moe/nea/firmament/features/texturepack/predicates/PullingPredicate.kt @@ -0,0 +1,26 @@ +package moe.nea.firmament.features.texturepack.predicates + +import com.google.gson.JsonElement +import net.minecraft.entity.LivingEntity +import net.minecraft.item.BowItem +import net.minecraft.item.ItemStack +import moe.nea.firmament.features.texturepack.FirmamentModelPredicate +import moe.nea.firmament.features.texturepack.FirmamentModelPredicateParser + +class PullingPredicate(val percentage: Double) : FirmamentModelPredicate { + companion object { + val AnyPulling = PullingPredicate(0.1) + } + + object Parser : FirmamentModelPredicateParser { + override fun parse(jsonElement: JsonElement): FirmamentModelPredicate? { + return PullingPredicate(jsonElement.asDouble) + } + } + + override fun test(stack: ItemStack, holder: LivingEntity?): Boolean { + if (holder == null) return false + return BowItem.getPullProgress(holder.itemUseTime) >= percentage + } + +} -- cgit