From c64731e7a9ed9adc0f1880b8165581bba33ee951 Mon Sep 17 00:00:00 2001 From: Electroblob77 <35599699+Electroblob77@users.noreply.github.com> Date: Tue, 3 Nov 2020 01:33:22 +0000 Subject: [PATCH] Fix ClassCastException in player animations, fixes #533 Somehow some unwrapped model parts managed to slip through (exactly *how* is a mystery!) so we're just safety-checking everything, I doubt this incurs much performance cost in the scheme of things. --- .../animation/ModelRendererExtended.java | 27 +++++++++++++++++++ .../client/animation/PlayerAnimator.java | 2 ++ 2 files changed, 29 insertions(+) diff --git a/src/main/java/electroblob/wizardry/client/animation/ModelRendererExtended.java b/src/main/java/electroblob/wizardry/client/animation/ModelRendererExtended.java index b8b3a846..d6691503 100644 --- a/src/main/java/electroblob/wizardry/client/animation/ModelRendererExtended.java +++ b/src/main/java/electroblob/wizardry/client/animation/ModelRendererExtended.java @@ -93,6 +93,33 @@ public class ModelRendererExtended extends ModelRenderer { } } + /** + * Returns whether the given {@link ModelBiped} is fully wrapped, i.e. all its parts are instances of + * {@code ModelRendererExtended}. If the given model is a {@link ModelPlayer}, this also checks the extra boxes for + * player skin overlays. + */ + public static boolean isWrapped(ModelBiped model){ + + boolean flag = true; + + if(model instanceof ModelPlayer){ + flag = flag && ((ModelPlayer)model).bipedBodyWear instanceof ModelRendererExtended; + flag = flag && ((ModelPlayer)model).bipedRightArmwear instanceof ModelRendererExtended; + flag = flag && ((ModelPlayer)model).bipedLeftArmwear instanceof ModelRendererExtended; + flag = flag && ((ModelPlayer)model).bipedRightLegwear instanceof ModelRendererExtended; + flag = flag && ((ModelPlayer)model).bipedLeftLegwear instanceof ModelRendererExtended; + } + + return flag + && model.bipedHead instanceof ModelRendererExtended + && model.bipedBody instanceof ModelRendererExtended + && model.bipedRightArm instanceof ModelRendererExtended + && model.bipedLeftArm instanceof ModelRendererExtended + && model.bipedRightLeg instanceof ModelRendererExtended + && model.bipedLeftLeg instanceof ModelRendererExtended + && model.bipedHeadwear instanceof ModelRendererExtended; + } + /** Resets the rotation of this model part to the angle set by the parent model. */ public void resetRotation(){ this.actualRotationX = Float.NaN; diff --git a/src/main/java/electroblob/wizardry/client/animation/PlayerAnimator.java b/src/main/java/electroblob/wizardry/client/animation/PlayerAnimator.java index 8d4783da..2f28d1e3 100644 --- a/src/main/java/electroblob/wizardry/client/animation/PlayerAnimator.java +++ b/src/main/java/electroblob/wizardry/client/animation/PlayerAnimator.java @@ -173,6 +173,8 @@ public class PlayerAnimator { for(ModelBiped model : models){ + if(!ModelRendererExtended.isWrapped(model)) continue; // Should never happen but somehow it does + animation.setRotationAngles(player, model, partialTicks, firstPerson); if(autoRotateSecondLayer && model instanceof ModelPlayer){