feat: Parse 1.21.3 and below bow animations

This commit is contained in:
Linnea Gräf
2025-01-30 20:34:12 +01:00
parent 9e32d3029f
commit 98c52ff797
6 changed files with 48 additions and 8 deletions

View File

@@ -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

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -3,14 +3,15 @@ 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>) : 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 {

View File

@@ -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
}
}

View File

@@ -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
}
}