From a5d67a7e1c8d9b451b9d9962d64124704796a22e Mon Sep 17 00:00:00 2001 From: Sollace Date: Sun, 3 Jun 2018 16:38:03 +0200 Subject: [PATCH] Fix leg wonkyness in general --- .../model/AbstractPonyModel.java | 156 ++++++++---------- .../minelittlepony/model/ModelMobPony.java | 35 +++- .../model/player/ModelUnicorn.java | 24 ++- .../model/ponies/ModelIllagerPony.java | 51 +++--- .../model/ponies/ModelVillagerPony.java | 4 +- .../model/ponies/ModelZombiePony.java | 6 +- 6 files changed, 134 insertions(+), 142 deletions(-) diff --git a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java index 0d1ee69f..f23f8fae 100644 --- a/src/main/java/com/minelittlepony/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/model/AbstractPonyModel.java @@ -18,6 +18,7 @@ import net.minecraft.client.model.ModelPlayer; import net.minecraft.client.model.ModelRenderer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.util.EnumHandSide; import net.minecraft.util.math.MathHelper; @@ -73,7 +74,11 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { * Checks flying and speed conditions and sets rainboom to true if we're a species with wings and is going faaast. */ protected void checkRainboom(Entity entity, float swing) { - rainboom = isFlying() && swing >= 0.9999F; + rainboom = canFly() && Math.sqrt(entity.motionX * entity.motionX + entity.motionZ * entity.motionZ) > 0.4F; + } + + public void setLivingAnimations(EntityLivingBase entity, float move, float swing, float partialTicks) { + } /** @@ -81,7 +86,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { * * @param move Entity motion parameter - i.e. velocity in no specific direction used in bipeds to calculate step amount. * @param swing Degree to which each 'limb' swings. - * @param ticks Total whole and partial ticks since the entity's existance. Used in animations together with {@code swing} and {@code move}. + * @param ticks Total whole and partial ticks since the entity's existance. Used in animations together with {@code swing} and {@code move}. * @param headYaw Horizontal head motion in radians. * @param headPitch Vertical head motion in radians. * @param scale Scaling factor used to render this model. Determined by the return value of {@link RenderLivingBase.prepareScale}. Usually {@code 0.0625F}. @@ -101,9 +106,9 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { updateHeadRotation(headRotateAngleX, headRotateAngleY); - rotateLook(move, swing, getWobbleAmount(), ticks); + shakeBody(move, swing, getWobbleAmount(), ticks); + rotateLegs(move, swing, ticks, entity); - setLegs(move, swing, ticks, entity); if (!rainboom) { holdItem(swing); } @@ -138,7 +143,6 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { if (isSleeping) ponySleep(); - aimBow(leftArmPose, rightArmPose, ticks); fixSpecialRotationPoints(move); animateWears(); @@ -147,9 +151,11 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { } protected float getWobbleAmount() { - if (swingProgress <= -9990.0F) { + + if (swingProgress <= 0) { return 0; } + return MathHelper.sin(MathHelper.sqrt(swingProgress) * PI * 2) * 0.2F; } @@ -167,7 +173,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { * @param bodySwing Horizontal (Y) body rotation. * @param ticks Total whole and partial ticks since the entity's existance. Used in animations together with {@code swing} and {@code move}. */ - protected void rotateLook(float move, float swing, float bodySwing, float ticks) { + protected void shakeBody(float move, float swing, float bodySwing, float ticks) { tail.setRotationAndAngles(rainboom, move, swing, bodySwing, ticks); bodySwing /= 5; @@ -209,22 +215,41 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { * * Takes the same parameters as {@link AbstractPonyModel.setRotationAndAngles} * - * TODO: This can be merged into adjustLegs - * */ - protected void setLegs(float move, float swing, float ticks, Entity entity) { + protected void rotateLegs(float move, float swing, float ticks, Entity entity) { if (isFlying()) { rotateLegsInFlight(move, swing, ticks, entity); } else { rotateLegsOnGround(move, swing, ticks, entity); } - bipedLeftArm.rotateAngleZ = 0; bipedRightArm.rotateAngleZ = 0; + bipedLeftArm.rotateAngleZ = 0; - adjustLegs(move, swing, ticks); + float sin = MathHelper.sin(bipedBody.rotateAngleY) * 5; + float cos = MathHelper.cos(bipedBody.rotateAngleY) * 5; + + float spread = getLegSpread(); + + bipedRightArm.rotationPointZ = spread + sin; + bipedLeftArm.rotationPointZ = spread - sin; + + float legRPX = cos - getLegOutset(); + + bipedRightArm.rotationPointX = -legRPX; + bipedRightLeg.rotationPointX = -legRPX; + + bipedLeftArm.rotationPointX = legRPX; + bipedLeftLeg.rotationPointX = legRPX; + + bipedRightArm.rotateAngleY += bipedBody.rotateAngleY; + bipedLeftArm.rotateAngleY += bipedBody.rotateAngleY; + + bipedRightArm.rotationPointY = bipedLeftArm.rotationPointY = 8; + bipedRightLeg.rotationPointZ = bipedLeftLeg.rotationPointZ = 10; } + /** * Rotates legs in quopy fashion whilst flying. * @@ -289,39 +314,6 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { return rainboom ? 2 : 1; } - /** - * - * Used to set the legs rotation based on walking/crouching animations. - * - * Takes the same parameters as {@link AbstractPonyModel.setRotationAndAngles} - * - * TODO: This can be merged into setLegs - * - */ - protected void adjustLegs(float move, float swing, float ticks) { - float sin = MathHelper.sin(bipedBody.rotateAngleY) * 5; - float cos = MathHelper.cos(bipedBody.rotateAngleY) * 5; - - float spread = getLegSpread(); - - bipedRightArm.rotationPointZ = spread + sin; - bipedLeftArm.rotationPointZ = spread - sin; - - float legRPX = cos - getLegOutset(); - - bipedRightArm.rotationPointX = -legRPX; - bipedRightLeg.rotationPointX = -legRPX; - - bipedLeftArm.rotationPointX = legRPX; - bipedLeftLeg.rotationPointX = legRPX; - - bipedRightArm.rotateAngleY += bipedBody.rotateAngleY; - bipedLeftArm.rotateAngleY += bipedBody.rotateAngleY; - - bipedRightArm.rotationPointY = bipedLeftArm.rotationPointY = 8; - bipedRightLeg.rotationPointZ = bipedLeftLeg.rotationPointZ = 10; - } - /** * Adjusts legs as if holding an item. Delegates to the correct arm/leg/limb as neccessary. * @@ -330,8 +322,8 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { protected void holdItem(float swing) { boolean both = leftArmPose == ArmPose.ITEM && rightArmPose == ArmPose.ITEM; - alignArmForAction(bipedLeftArm, leftArmPose, both, swing, 1); - alignArmForAction(bipedRightArm, rightArmPose, both, swing, -1); + alignArmForAction(bipedLeftArm, leftArmPose, rightArmPose, both, swing, 1); + alignArmForAction(bipedRightArm, rightArmPose, leftArmPose, both, swing, -1); } /** @@ -342,7 +334,7 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { * @param both True if we have something in both hands * @param swing Degree to which each 'limb' swings. */ - protected void alignArmForAction(ModelRenderer arm, ArmPose pose, boolean both, float swing, float reflect) { + protected void alignArmForAction(ModelRenderer arm, ArmPose pose, ArmPose complement, boolean both, float swing, float reflect) { switch (pose) { case ITEM: float swag = 1; @@ -351,25 +343,48 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { } float mult = 1 - swag/2; arm.rotateAngleX = arm.rotateAngleX * mult - (PI / 10) * swag; - arm.rotateAngleZ = -reflect * (mult - PI / 10); + arm.rotateAngleZ = -reflect * (PI / 15); + if (isSneak) { + arm.rotationPointX -= reflect * 2; + } case EMPTY: arm.rotateAngleY = 0; break; case BLOCK: - arm.rotateAngleX = arm.rotateAngleX / 2 - 0.9424779F; - arm.rotateAngleY = reflect * PI / 6; + if (complement != ArmPose.BOW_AND_ARROW) { + arm.rotateAngleX = (arm.rotateAngleX / 2 - 0.9424779F) - 0.3F; + arm.rotateAngleY = reflect * PI / 9; + arm.rotationPointX += reflect; + arm.rotationPointZ += 3; + if (isSneak) { + arm.rotationPointY += 4; + } + } + break; + case BOW_AND_ARROW: + aimBow(arm, swing); break; default: } } + protected void aimBow(ModelRenderer arm, float ticks) { + arm.rotateAngleX = ROTATE_270 + bipedHead.rotateAngleX + (MathHelper.sin(ticks * 0.067F) * 0.05F); + arm.rotateAngleY = bipedHead.rotateAngleY - 0.06F; + arm.rotateAngleZ = MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; + if (isSneak) { + arm.rotationPointY += 4; + } + } + + /** * Animates arm swinging. Delegates to the correct arm/leg/limb as neccessary. * * @param entity The entity we are being called for. */ protected void swingItem(Entity entity) { - if (swingProgress > -9990.0F && !isSleeping) { + if (swingProgress > 0 && !isSleeping) { EnumHandSide mainSide = getMainHand(entity); swingArm(getArmForSide(mainSide)); @@ -459,19 +474,6 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { AbstractPonyRenderer.shiftRotationPoint(bipedLeftLeg, 0, 2, -8); } - protected void aimBow(ArmPose leftArm, ArmPose rightArm, float ticks) { - if (rightArm == ArmPose.BOW_AND_ARROW) aimBowPony(bipedRightArm, ticks); - if (leftArm == ArmPose.BOW_AND_ARROW) aimBowPony(bipedLeftArm, ticks); - } - - protected void aimBowPony(ModelRenderer arm, float ticks) { - arm.rotateAngleZ = 0; - arm.rotateAngleY = bipedHead.rotateAngleY - 0.06F; - arm.rotateAngleX = ROTATE_270 + bipedHead.rotateAngleX; - arm.rotateAngleZ += MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; - arm.rotateAngleX += MathHelper.sin(ticks * 0.067F) * 0.05F; - } - /** * Called after postioning but before wears alignment to perform some last-minute adjustments. * @@ -688,30 +690,6 @@ public abstract class AbstractPonyModel extends ModelPlayer implements IModel { return swingProgress; } - /** - * Rotates the provided arm to the correct orientation for holding an item. - * - * @param arm The arm to rotate - * @param direction Direction multiplier. 1 for right, -1 for left. - * @param swingProgress How far we are through the current swing - * @param ticks Render partial ticks - */ - protected void rotateArmHolding(ModelRenderer arm, float direction, float swingProgress, float ticks) { - float swing = MathHelper.sin(swingProgress * PI); - float roll = MathHelper.sin((1 - (1 - swingProgress) * (1 - swingProgress)) * PI); - - float cos = MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; - float sin = MathHelper.sin(ticks * 0.067F) / 10; - - arm.rotateAngleX = -1.5707964F; - arm.rotateAngleX -= swing * 1.2F - roll * 0.4F; - arm.rotateAngleX += sin; - - arm.rotateAngleY = direction * (0.1F - swing * 0.6F); - arm.rotateAngleZ = cos; - - } - /** * Sets the model's various rotation angles. * diff --git a/src/main/java/com/minelittlepony/model/ModelMobPony.java b/src/main/java/com/minelittlepony/model/ModelMobPony.java index 1edb4daa..e7c95875 100644 --- a/src/main/java/com/minelittlepony/model/ModelMobPony.java +++ b/src/main/java/com/minelittlepony/model/ModelMobPony.java @@ -1,7 +1,11 @@ package com.minelittlepony.model; +import static com.minelittlepony.model.PonyModelConstants.PI; + import com.minelittlepony.model.player.ModelAlicorn; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.entity.Entity; import net.minecraft.util.math.MathHelper; /** @@ -22,8 +26,9 @@ public class ModelMobPony extends ModelAlicorn { } @Override - protected void adjustLegs(float move, float swing, float ticks) { - super.adjustLegs(move, swing, ticks); + protected void rotateLegs(float move, float swing, float ticks, Entity entity) { + super.rotateLegs(move, swing, ticks, entity); + if (rightArmPose != ArmPose.EMPTY) { if (canCast()) { unicornArmRight.setRotationPoint(-7, 12, -2); @@ -34,7 +39,7 @@ public class ModelMobPony extends ModelAlicorn { } if (leftArmPose != ArmPose.EMPTY) { - if (!canCast()) { + if (canCast()) { unicornArmRight.setRotationPoint(-7, 12, -2); rotateArmHolding(unicornArmLeft, -1, swingProgress, ticks); } else { @@ -42,4 +47,28 @@ public class ModelMobPony extends ModelAlicorn { } } } + + /** + * Rotates the provided arm to the correct orientation for holding an item. + * + * @param arm The arm to rotate + * @param direction Direction multiplier. 1 for right, -1 for left. + * @param swingProgress How far we are through the current swing + * @param ticks Render partial ticks + */ + protected void rotateArmHolding(ModelRenderer arm, float direction, float swingProgress, float ticks) { + float swing = MathHelper.sin(swingProgress * PI); + float roll = MathHelper.sin((1 - (1 - swingProgress) * (1 - swingProgress)) * PI); + + float cos = MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; + float sin = MathHelper.sin(ticks * 0.067F) / 10; + + arm.rotateAngleX = -1.5707964F; + arm.rotateAngleX -= swing * 1.2F - roll * 0.4F; + arm.rotateAngleX += sin; + + arm.rotateAngleY = direction * (0.1F - swing * 0.6F); + arm.rotateAngleZ = cos; + + } } diff --git a/src/main/java/com/minelittlepony/model/player/ModelUnicorn.java b/src/main/java/com/minelittlepony/model/player/ModelUnicorn.java index cf755c82..245ceeb0 100644 --- a/src/main/java/com/minelittlepony/model/player/ModelUnicorn.java +++ b/src/main/java/com/minelittlepony/model/player/ModelUnicorn.java @@ -46,8 +46,14 @@ public class ModelUnicorn extends ModelEarthPony implements IModelUnicorn { } @Override - protected void adjustLegs(float move, float swing, float ticks) { - super.adjustLegs(move, swing, ticks); + protected void rotateLegs(float move, float swing, float ticks, Entity entity) { + super.rotateLegs(move, swing, ticks, entity); + + unicornArmLeft.rotationPointX = 5; + unicornArmRight.rotationPointX = -5; + + unicornArmLeft.rotationPointY = unicornArmRight.rotationPointY = 8; + unicornArmLeft.rotationPointZ = unicornArmRight.rotationPointZ = 10; unicornArmLeft.rotateAngleZ = 0; unicornArmRight.rotateAngleZ = 0; @@ -61,8 +67,8 @@ public class ModelUnicorn extends ModelEarthPony implements IModelUnicorn { if (canCast()) { boolean both = leftArmPose == ArmPose.ITEM && rightArmPose == ArmPose.ITEM; - alignArmForAction(unicornArmLeft, leftArmPose, both, swing, 1); - alignArmForAction(unicornArmRight, rightArmPose, both, swing, -1); + alignArmForAction(unicornArmLeft, leftArmPose, rightArmPose, both, swing, 1); + alignArmForAction(unicornArmRight, rightArmPose, leftArmPose, both, swing, -1); } else { super.holdItem(swing); } @@ -130,16 +136,6 @@ public class ModelUnicorn extends ModelEarthPony implements IModelUnicorn { unicornArmLeft.rotateAngleX += SNEAK_LEG_X_ROTATION_ADJUSTMENT; } - @Override - protected void aimBow(ArmPose leftArm, ArmPose rightArm, float ticks) { - if (canCast()) { - if (rightArm == ArmPose.BOW_AND_ARROW) aimBowPony(unicornArmRight, ticks); - if (leftArm == ArmPose.BOW_AND_ARROW) aimBowPony(unicornArmLeft, ticks); - } else { - super.aimBow(leftArm, rightArm, ticks); - } - } - @Override protected void renderHead(Entity entity, float move, float swing, float ticks, float headYaw, float headPitch, float scale) { super.renderHead(entity, move, swing, ticks, headYaw, headPitch, scale); diff --git a/src/main/java/com/minelittlepony/model/ponies/ModelIllagerPony.java b/src/main/java/com/minelittlepony/model/ponies/ModelIllagerPony.java index 14127339..269fffd8 100644 --- a/src/main/java/com/minelittlepony/model/ponies/ModelIllagerPony.java +++ b/src/main/java/com/minelittlepony/model/ponies/ModelIllagerPony.java @@ -23,50 +23,37 @@ public class ModelIllagerPony extends ModelAlicorn { IllagerArmPose pose = illager.getArmPose(); boolean rightHanded = illager.getPrimaryHand() == EnumHandSide.RIGHT; + float mult = rightHanded ? 1 : -1; + ModelRenderer arm = getArm(illager.getPrimaryHand()); if (pose == IllagerArmPose.ATTACKING) { // vindicator attacking float f = MathHelper.sin(swingProgress * (float) Math.PI); float f1 = MathHelper.sin((1.0F - (1.0F - swingProgress) * (1.0F - swingProgress)) * (float) Math.PI); - bipedRightArm.rotateAngleZ = 0.0F; - bipedLeftArm.rotateAngleZ = 0.0F; + + + float cos = MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; + float sin = MathHelper.sin(ticks * 0.067F) * 0.05F; + + bipedRightArm.rotateAngleZ = cos; + bipedLeftArm.rotateAngleZ = cos; + bipedRightArm.rotateAngleY = 0.15707964F; bipedLeftArm.rotateAngleY = -0.15707964F; - if (rightHanded) { - bipedRightArm.rotateAngleX = -1.8849558F + MathHelper.cos(ticks * 0.09F) * 0.15F; - bipedRightArm.rotateAngleX += f * 2.2F - f1 * 0.4F; - } else { - bipedLeftArm.rotateAngleX = -1.8849558F + MathHelper.cos(ticks * 0.09F) * 0.15F; - bipedLeftArm.rotateAngleX += f * 2.2F - f1 * 0.4F; - } + arm.rotateAngleX = -1.8849558F + MathHelper.cos(ticks * 0.09F) * 0.15F; + arm.rotateAngleX += f * 2.2F - f1 * 0.4F; - bipedRightArm.rotateAngleZ += MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; - bipedLeftArm.rotateAngleZ -= MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; - bipedRightArm.rotateAngleX += MathHelper.sin(ticks * 0.067F) * 0.05F; - bipedLeftArm.rotateAngleX -= MathHelper.sin(ticks * 0.067F) * 0.05F; + bipedRightArm.rotateAngleX += sin; + bipedLeftArm.rotateAngleX -= sin; } else if (pose == IllagerArmPose.SPELLCASTING) { // waving arms! - if (rightHanded) { -// this.bipedRightArm.rotationPointZ = 0.0F; -// this.bipedRightArm.rotationPointX = -5.0F; - bipedRightArm.rotateAngleX = (float) (-.75F * Math.PI); - bipedRightArm.rotateAngleZ = MathHelper.cos(ticks * 0.6662F) / 4; - bipedRightArm.rotateAngleY = 1.1F; - } else { -// this.bipedLeftArm.rotationPointZ = 0.0F; -// this.bipedLeftArm.rotationPointX = 5.0F; - bipedLeftArm.rotateAngleX = (float) (-.75F * Math.PI); - bipedLeftArm.rotateAngleZ = -MathHelper.cos(ticks * 0.6662F) / 4; - bipedLeftArm.rotateAngleY = -1.1F; - } - +// this.bipedRightArm.rotationPointZ = 0; + arm.rotateAngleX = (float) (-.75F * Math.PI); + arm.rotateAngleZ = mult * MathHelper.cos(ticks * 0.6662F) / 4; + arm.rotateAngleY = mult * 1.1F; } else if (pose == IllagerArmPose.BOW_AND_ARROW) { - if (rightHanded) { - aimBow(ArmPose.EMPTY, ArmPose.BOW_AND_ARROW, ticks); - } else { - aimBow(ArmPose.BOW_AND_ARROW, ArmPose.EMPTY, ticks); - } + aimBow(arm, ticks); } } diff --git a/src/main/java/com/minelittlepony/model/ponies/ModelVillagerPony.java b/src/main/java/com/minelittlepony/model/ponies/ModelVillagerPony.java index c8181686..6ba2669f 100644 --- a/src/main/java/com/minelittlepony/model/ponies/ModelVillagerPony.java +++ b/src/main/java/com/minelittlepony/model/ponies/ModelVillagerPony.java @@ -17,8 +17,8 @@ public class ModelVillagerPony extends ModelAlicorn { } @Override - protected void rotateLook(float move, float swing, float bodySwing, float ticks) { - super.rotateLook(move, swing, bodySwing, ticks); + protected void shakeBody(float move, float swing, float bodySwing, float ticks) { + super.shakeBody(move, swing, bodySwing, ticks); bag.rotateAngleY = bodySwing; apron.rotateAngleY = bodySwing; diff --git a/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java b/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java index d0a0fbfb..1cb51738 100644 --- a/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java +++ b/src/main/java/com/minelittlepony/model/ponies/ModelZombiePony.java @@ -3,10 +3,12 @@ package com.minelittlepony.model.ponies; import com.minelittlepony.model.ModelMobPony; import com.minelittlepony.render.AbstractPonyRenderer; +import net.minecraft.entity.Entity; + public class ModelZombiePony extends ModelMobPony { @Override - protected void adjustLegs(float move, float swing, float ticks) { - super.adjustLegs(move, swing, ticks); + protected void rotateLegs(float move, float swing, float ticks, Entity entity) { + super.rotateLegs(move, swing, ticks, entity); if (rightArmPose != ArmPose.EMPTY) return; if (islookAngleRight(move)) {