From 5f1dcf164743b5957b21d6d951c073438f87eef1 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 28 Mar 2023 15:53:14 +0100 Subject: [PATCH] Update some things and remove PonyModelConstants --- .../com/minelittlepony/api/model/IModel.java | 13 +- .../com/minelittlepony/api/model/IPart.java | 2 +- .../minelittlepony/api/model/IPegasus.java | 4 + .../api/model/ModelAttributes.java | 10 +- .../com/minelittlepony/api/model/Pivot.java | 13 ++ .../api/model/PonyModelConstants.java | 55 -------- .../client/model/AbstractPonyModel.java | 131 ++++++++++-------- .../client/model/ClientPonyModel.java | 20 +-- .../client/model/IMobModel.java | 5 +- .../client/model/IPonyMixinModel.java | 10 -- .../client/model/IPonyModel.java | 3 +- .../client/model/PonyElytra.java | 23 ++- .../client/model/entity/BreezieModel.java | 28 ++-- .../model/entity/EnderStallionModel.java | 2 +- .../client/model/entity/WitchPonyModel.java | 2 +- .../model/entity/race/ChangelingModel.java | 4 +- .../model/entity/race/SeaponyModel.java | 4 +- .../model/entity/race/UnicornModel.java | 4 +- .../client/model/gear/ChristmasHat.java | 5 +- .../client/model/gear/SaddleBags.java | 8 +- .../client/model/part/PonyTail.java | 25 ++-- .../client/model/part/PonyWings.java | 13 +- .../client/model/part/SeaponyTail.java | 7 +- .../client/render/IPonyRenderContext.java | 3 +- .../client/render/entity/PonyRenderer.java | 1 + .../render/entity/feature/CapeFeature.java | 6 +- .../client/transform/PonyTransformation.java | 44 +++--- .../com/minelittlepony/util/MathUtil.java | 16 ++- 28 files changed, 205 insertions(+), 256 deletions(-) create mode 100644 src/main/java/com/minelittlepony/api/model/Pivot.java delete mode 100644 src/main/java/com/minelittlepony/api/model/PonyModelConstants.java diff --git a/src/main/java/com/minelittlepony/api/model/IModel.java b/src/main/java/com/minelittlepony/api/model/IModel.java index 19134402..6a748c87 100644 --- a/src/main/java/com/minelittlepony/api/model/IModel.java +++ b/src/main/java/com/minelittlepony/api/model/IModel.java @@ -26,7 +26,9 @@ public interface IModel { /** * Gets the skin metadata associated with this model. */ - IPonyData getMetadata(); + default IPonyData getMetadata() { + return getAttributes().metadata; + } /** * Sets the pony metadata object associated with this model. @@ -42,8 +44,13 @@ public interface IModel { /** * Returns true if this model is riding a boat, horse, or other animals. + * + * @deprecated User model#getAttributes().isSitting */ - boolean isRiding(); + @Deprecated + default boolean isRiding() { + return getAttributes().isSitting; + } default Race getRace() { return PonyConfig.getEffectiveRace(getMetadata().getRace()); @@ -70,7 +77,7 @@ public interface IModel { return 0; } - return MathHelper.sin(MathHelper.sqrt(getSwingAmount()) * PonyModelConstants.PI * 2) * 0.04F; + return MathHelper.sin(MathHelper.sqrt(getSwingAmount()) * MathHelper.PI * 2) * 0.04F; } /** diff --git a/src/main/java/com/minelittlepony/api/model/IPart.java b/src/main/java/com/minelittlepony/api/model/IPart.java index d52b8300..db6a059e 100644 --- a/src/main/java/com/minelittlepony/api/model/IPart.java +++ b/src/main/java/com/minelittlepony/api/model/IPart.java @@ -3,7 +3,7 @@ package com.minelittlepony.api.model; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.util.math.MatrixStack; -public interface IPart extends PonyModelConstants { +public interface IPart { /** * Sets the model's various rotation angles. *

diff --git a/src/main/java/com/minelittlepony/api/model/IPegasus.java b/src/main/java/com/minelittlepony/api/model/IPegasus.java index 2bea883b..00fcd015 100644 --- a/src/main/java/com/minelittlepony/api/model/IPegasus.java +++ b/src/main/java/com/minelittlepony/api/model/IPegasus.java @@ -2,8 +2,12 @@ package com.minelittlepony.api.model; import com.minelittlepony.api.pony.meta.Wearable; import com.minelittlepony.client.MineLittlePony; +import com.minelittlepony.util.MathUtil; public interface IPegasus extends IModel { + public static final float WINGS_HALF_SPREAD_ANGLE = MathUtil.Angles._270_DEG; + public static final float WINGS_FULL_SPREAD_ANGLE = MathUtil.Angles._270_DEG + 0.4F; + public static final float WINGS_RAISED_ANGLE = 4; /** * Returns true if the wings are spread. diff --git a/src/main/java/com/minelittlepony/api/model/ModelAttributes.java b/src/main/java/com/minelittlepony/api/model/ModelAttributes.java index 0f5da808..ed9b9ca6 100644 --- a/src/main/java/com/minelittlepony/api/model/ModelAttributes.java +++ b/src/main/java/com/minelittlepony/api/model/ModelAttributes.java @@ -14,10 +14,6 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import static com.minelittlepony.api.model.PonyModelConstants.ROTATE_270; -import static com.minelittlepony.api.model.PonyModelConstants.WING_ROT_Z_SNEAK; -import static com.minelittlepony.api.model.PonyModelConstants.WING_ROT_Z_FLYING; - public class ModelAttributes { /** * True if the model is sleeping in a bed. @@ -128,12 +124,12 @@ public class ModelAttributes { private float calcWingRotationFactor(float ticks) { if (isSwimming) { - return (MathHelper.sin(ticks * 0.136f) / 2) + ROTATE_270; + return (MathHelper.sin(ticks * 0.136f) / 2) + MathUtil.Angles._270_DEG; } if (isFlying) { - return MathHelper.sin(ticks * 0.536f) + WING_ROT_Z_FLYING; + return MathHelper.sin(ticks * 0.536f) + IPegasus.WINGS_FULL_SPREAD_ANGLE; } - return WING_ROT_Z_SNEAK; + return IPegasus.WINGS_RAISED_ANGLE; } public void updateLivingState(LivingEntity entity, IPony pony, Mode mode) { diff --git a/src/main/java/com/minelittlepony/api/model/Pivot.java b/src/main/java/com/minelittlepony/api/model/Pivot.java new file mode 100644 index 00000000..5f2ab6a1 --- /dev/null +++ b/src/main/java/com/minelittlepony/api/model/Pivot.java @@ -0,0 +1,13 @@ +package com.minelittlepony.api.model; + +import net.minecraft.client.model.ModelPart; + +public record Pivot(float x, float y, float z) { + public void set(ModelPart part) { + part.setPivot(x, y, z); + } + + public void add(ModelPart part) { + part.setPivot(part.pivotX + x, part.pivotY + y, part.pivotZ + z); + } +} \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/api/model/PonyModelConstants.java b/src/main/java/com/minelittlepony/api/model/PonyModelConstants.java deleted file mode 100644 index 19cb74ce..00000000 --- a/src/main/java/com/minelittlepony/api/model/PonyModelConstants.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.minelittlepony.api.model; - -public interface PonyModelConstants { - float - PI = (float)Math.PI, - - ROTATE_270 = 4.712F, - ROTATE_90 = 1.571F, - - BASE_MODEL_SCALE = 15/16F, - - BODY_ROT_X = 0, - BODY_ROT_X_SNEAK = 0.4F, - BODY_ROT_X_RIDING = PI * 3.8F, - - BODY_RP_Y = 0, - BODY_RP_Y_SNEAK = 7, - BODY_RP_Y_RIDING = 1, - - BODY_RP_Z = 0, - BODY_RP_Z_SNEAK = -4, - BODY_RP_Z_RIDING = 4, - - FRONT_LEG_RP_Y = 8, - FRONT_LEG_RP_Y_SNEAK = 8, - - WING_ROT_Z_FLYING = ROTATE_270 + 0.4F, - WING_ROT_Z_SNEAK = 4, - - LEG_ROT_X_SNEAK_ADJ = 0.4F, - - LEG_SLEEP_OFFSET_Y = 2, - FRONT_LEG_SLEEP_OFFSET_Z = 6, - BACK_LEG_SLEEP_OFFSET_Z = -8, - - TAIL_RP_Z = 14, - TAIL_RP_Z_SNEAK = 15, - - TAIL_RP_Y_RIDING = 3, - TAIL_RP_Z_RIDING = 13, - - HEAD_RP_X_SNEAK = 0, - HEAD_RP_Y_SNEAK = 6, - HEAD_RP_Z_SNEAK = -2, - - HEAD_RP_X_SLEEP = 1, - HEAD_RP_Y_SLEEP = 2, - - HEAD_RP_Y_SWIM = -2, - HEAD_RP_Z_SWIM = -4, - - NECK_ROT_X = 0.166F, - - FIN_ROT_Y = PI / 6; -} diff --git a/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java b/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java index e0eab2df..bdd9908f 100644 --- a/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/AbstractPonyModel.java @@ -5,7 +5,7 @@ import com.minelittlepony.api.model.fabric.PonyModelPrepareCallback; import com.minelittlepony.api.pony.meta.Sizes; import com.minelittlepony.client.transform.PonyTransformation; import com.minelittlepony.client.util.render.RenderList; -import com.minelittlepony.mson.util.PartUtil; +import com.minelittlepony.util.MathUtil; import java.util.ArrayList; import java.util.List; @@ -22,6 +22,19 @@ import net.minecraft.util.math.*; * Foundation class for all types of ponies. */ public abstract class AbstractPonyModel extends ClientPonyModel { + public static final float NECK_X = 0.166F; + public static final float LEG_SNEAKING_PITCH_ADJUSTMENT = 0.4F; + public static final float BODY_RIDING_PITCH = MathHelper.PI * 3.8F; + public static final float BODY_SNEAKING_PITCH = 0.4F; + public static final float FRONT_LEGS_Y = 8; + + public static final Pivot ORIGIN = new Pivot(0, 0, 0); + public static final Pivot HEAD_SNEAKING = new Pivot(0, 6, -2); + public static final Pivot HEAD_SLEEPING = new Pivot(1, 2, 0); + public static final Pivot BODY_SNEAKING = new Pivot(0, 7, -4); + public static final Pivot BODY_RIDING = new Pivot(0, 1, 4); + public static final Pivot FONT_LEGS_SLEEPING = new Pivot(0, 2, 6); + public static final Pivot BACK_LEGS_SLEEPING = new Pivot(0, 2, -6); protected final ModelPart neck; @@ -133,10 +146,10 @@ public abstract class AbstractPonyModel extends ClientPo } else if (riding) { ponySit(); } else { - adjustBody(BODY_ROT_X, BODY_RP_Y, BODY_RP_Z); + adjustBody(0, ORIGIN); - rightLeg.pivotY = FRONT_LEG_RP_Y; - leftLeg.pivotY = FRONT_LEG_RP_Y; + rightLeg.pivotY = FRONT_LEGS_Y; + leftLeg.pivotY = FRONT_LEGS_Y; if (!attributes.isSleeping) { animateBreathing(animationProgress); @@ -165,76 +178,76 @@ public abstract class AbstractPonyModel extends ClientPo * Aligns legs to a sneaky position. */ protected void ponyCrouch() { - adjustBody(BODY_ROT_X_SNEAK, BODY_RP_Y_SNEAK, BODY_RP_Z_SNEAK); - head.setPivot(HEAD_RP_X_SNEAK, HEAD_RP_Y_SNEAK, HEAD_RP_Z_SNEAK); + adjustBody(BODY_SNEAKING_PITCH, BODY_SNEAKING); + HEAD_SNEAKING.set(head); - rightArm.pitch -= LEG_ROT_X_SNEAK_ADJ; - leftArm.pitch -= LEG_ROT_X_SNEAK_ADJ; + rightArm.pitch -= LEG_SNEAKING_PITCH_ADJUSTMENT; + leftArm.pitch -= LEG_SNEAKING_PITCH_ADJUSTMENT; - leftLeg.pivotY = FRONT_LEG_RP_Y_SNEAK; - rightLeg.pivotY = FRONT_LEG_RP_Y_SNEAK; + leftLeg.pivotY = FRONT_LEGS_Y; + rightLeg.pivotY = FRONT_LEGS_Y; } protected void ponySleep() { - rightArm.pitch = -ROTATE_90; - leftArm.pitch = -ROTATE_90; + rightArm.pitch = -MathUtil.Angles._90_DEG; + leftArm.pitch = -MathUtil.Angles._90_DEG; - rightLeg.pitch = ROTATE_90; - leftLeg.pitch = ROTATE_90; + rightLeg.pitch = MathUtil.Angles._90_DEG; + leftLeg.pitch = MathUtil.Angles._90_DEG; - head.setPivot(HEAD_RP_X_SLEEP, HEAD_RP_Y_SLEEP, sneaking ? -1 : 1); + HEAD_SLEEPING.set(head); + head.pivotZ = sneaking ? -1 : 1; - PartUtil.shift(rightArm, 0, LEG_SLEEP_OFFSET_Y, FRONT_LEG_SLEEP_OFFSET_Z); - PartUtil.shift(leftArm, 0, LEG_SLEEP_OFFSET_Y, FRONT_LEG_SLEEP_OFFSET_Z); - PartUtil.shift(rightLeg, 0, LEG_SLEEP_OFFSET_Y, BACK_LEG_SLEEP_OFFSET_Z); - PartUtil.shift(leftLeg, 0, LEG_SLEEP_OFFSET_Y, BACK_LEG_SLEEP_OFFSET_Z); + FONT_LEGS_SLEEPING.add(rightArm); + FONT_LEGS_SLEEPING.add(leftArm); + BACK_LEGS_SLEEPING.add(rightLeg); + BACK_LEGS_SLEEPING.add(leftLeg); } protected void ponySit() { + adjustBodyComponents(BODY_RIDING_PITCH * (attributes.isRidingInteractive ? 2 : 1), BODY_RIDING); if (attributes.isRidingInteractive) { - adjustBodyComponents(BODY_ROT_X_RIDING * 2, BODY_RP_Y_RIDING, BODY_RP_Z_RIDING); - neck.setPivot(NECK_ROT_X + BODY_ROT_X * 2, BODY_RP_Y, BODY_RP_Z - 4); + neck.setPivot(NECK_X, 0, -4); head.setPivot(0, -2, -5); } else { - adjustBodyComponents(BODY_ROT_X_RIDING, BODY_RP_Y_RIDING, BODY_RP_Z_RIDING); - neck.setPivot(NECK_ROT_X + BODY_ROT_X, BODY_RP_Y, BODY_RP_Z); + neck.setPivot(NECK_X, 0, 0); head.setPivot(0, 0, 0); } leftLeg.pivotZ = 14; leftLeg.pivotY = 17; - leftLeg.pitch = -PI / 4; - leftLeg.yaw = -PI / 7; + leftLeg.pitch = -MathHelper.PI / 4; + leftLeg.yaw = -MathHelper.PI / 7; leftLeg.pitch += body.pitch; rightLeg.pivotZ = 15; rightLeg.pivotY = 17; - rightLeg.pitch = -PI / 4; - rightLeg.yaw = PI / 7; + rightLeg.pitch = -MathHelper.PI / 4; + rightLeg.yaw = MathHelper.PI / 7; rightLeg.pitch += body.pitch; - leftArm.roll = -PI * 0.06f; + leftArm.roll = -MathHelper.PI * 0.06f; leftArm.pitch += body.pitch; - rightArm.roll = PI * 0.06f; + rightArm.roll = MathHelper.PI * 0.06f; rightArm.pitch += body.pitch; if (attributes.isRidingInteractive) { - leftLeg.yaw = PI / 15; - leftLeg.pitch = PI / 9; + leftLeg.yaw = MathHelper.PI / 15; + leftLeg.pitch = MathHelper.PI / 9; leftLeg.pivotZ = 10; leftLeg.pivotY = 7; - rightLeg.yaw = -PI / 15; - rightLeg.pitch = PI / 9; + rightLeg.yaw = -MathHelper.PI / 15; + rightLeg.pitch = MathHelper.PI / 9; rightLeg.pivotZ = 10; rightLeg.pivotY = 7; - leftArm.pitch = PI / 6; - rightArm.pitch = PI / 6; + leftArm.pitch = MathHelper.PI / 6; + rightArm.pitch = MathHelper.PI / 6; leftArm.roll *= 2; rightArm.roll *= 2; @@ -285,10 +298,10 @@ public abstract class AbstractPonyModel extends ClientPo float lerp = entity.isSwimming() ? (float)attributes.motionLerp : 1; - float legLeft = (ROTATE_90 + MathHelper.sin((move / 3) + 2 * PI/3) / 2) * lerp; + float legLeft = (MathUtil.Angles._90_DEG + MathHelper.sin((move / 3) + 2 * MathHelper.PI/3) / 2) * lerp; - float left = (ROTATE_90 + MathHelper.sin((move / 3) + 2 * PI) / 2) * lerp; - float right = (ROTATE_90 + MathHelper.sin(move / 3) / 2) * lerp; + float left = (MathUtil.Angles._90_DEG + MathHelper.sin((move / 3) + 2 * MathHelper.PI) / 2) * lerp; + float right = (MathUtil.Angles._90_DEG + MathHelper.sin(move / 3) / 2) * lerp; leftArm.setAngles(-left, -left/2, left/2); rightArm.setAngles(-right, right/2, -right/2); @@ -301,7 +314,7 @@ public abstract class AbstractPonyModel extends ClientPo * */ protected void rotateLegsOnGround(float move, float swing, float ticks, T entity) { - float angle = PI * (float) Math.pow(swing, 16); + float angle = MathHelper.PI * (float) Math.pow(swing, 16); float baseRotation = move * 0.6662F; // magic number ahoy float scale = swing / 4; @@ -313,10 +326,10 @@ public abstract class AbstractPonyModel extends ClientPo ); float yAngle = 0.2F * rainboomLegLotation; - leftArm.setAngles(MathHelper.lerp(rainboomLegLotation, MathHelper.cos(baseRotation + angle) * scale, -ROTATE_90 * rainboomLegLotation), -yAngle, 0); - rightArm.setAngles(MathHelper.lerp(rainboomLegLotation, MathHelper.cos(baseRotation + PI + angle / 2) * scale, -ROTATE_90 * rainboomLegLotation), yAngle, 0); - leftLeg.setAngles(MathHelper.lerp(rainboomLegLotation, MathHelper.cos(baseRotation + PI - (angle * 0.4f)) * scale, ROTATE_90 * rainboomLegLotation), yAngle, leftLeg.roll); - rightLeg.setAngles(MathHelper.lerp(rainboomLegLotation, MathHelper.cos(baseRotation + angle / 5) * scale, ROTATE_90 * rainboomLegLotation), -yAngle, rightLeg.roll); + leftArm.setAngles(MathHelper.lerp(rainboomLegLotation, MathHelper.cos(baseRotation + angle) * scale, -MathUtil.Angles._90_DEG * rainboomLegLotation), -yAngle, 0); + rightArm.setAngles(MathHelper.lerp(rainboomLegLotation, MathHelper.cos(baseRotation + MathHelper.PI + angle / 2) * scale, -MathUtil.Angles._90_DEG * rainboomLegLotation), yAngle, 0); + leftLeg.setAngles(MathHelper.lerp(rainboomLegLotation, MathHelper.cos(baseRotation + MathHelper.PI - (angle * 0.4f)) * scale, MathUtil.Angles._90_DEG * rainboomLegLotation), yAngle, leftLeg.roll); + rightLeg.setAngles(MathHelper.lerp(rainboomLegLotation, MathHelper.cos(baseRotation + angle / 5) * scale, MathUtil.Angles._90_DEG * rainboomLegLotation), -yAngle, rightLeg.roll); } protected float getLegOutset() { @@ -372,8 +385,8 @@ public abstract class AbstractPonyModel extends ClientPo } float mult = 1 - swag/2; - arm.pitch = arm.pitch * mult - (PI / 10) * swag; - arm.roll = -sigma * (PI / 15); + arm.pitch = arm.pitch * mult - (MathHelper.PI / 10) * swag; + arm.roll = -sigma * (MathHelper.PI / 15); if (attributes.isCrouching) { arm.pivotX -= sigma * 2; @@ -386,9 +399,9 @@ public abstract class AbstractPonyModel extends ClientPo break; case BLOCK: arm.pitch = (arm.pitch / 2 - 0.9424779F) - 0.3F; - arm.yaw = sigma * PI / 9; + arm.yaw = sigma * MathHelper.PI / 9; if (complement == pose) { - arm.yaw -= sigma * PI / 18; + arm.yaw -= sigma * MathHelper.PI / 18; } arm.pivotX += sigma; arm.pivotZ += 3; @@ -402,7 +415,7 @@ public abstract class AbstractPonyModel extends ClientPo case CROSSBOW_HOLD: aimBow(arm, limbSpeed); - arm.pitch = head.pitch - ROTATE_90; + arm.pitch = head.pitch - MathUtil.Angles._90_DEG; arm.yaw = head.yaw + 0.06F; break; case CROSSBOW_CHARGE: @@ -412,7 +425,7 @@ public abstract class AbstractPonyModel extends ClientPo arm.yaw = head.yaw + 0.06F; break; case THROW_SPEAR: - arm.pitch = ROTATE_90 * 2; + arm.pitch = MathUtil.Angles._90_DEG * 2; break; case SPYGLASS: float addedPitch = sneaking ? -0.2617994F : 0; @@ -439,7 +452,7 @@ public abstract class AbstractPonyModel extends ClientPo } protected void aimBow(ModelPart arm, float limbSpeed) { - arm.pitch = ROTATE_270 + head.pitch + (MathHelper.sin(limbSpeed * 0.067F) * 0.05F); + arm.pitch = MathUtil.Angles._270_DEG + head.pitch + (MathHelper.sin(limbSpeed * 0.067F) * 0.05F); arm.yaw = head.yaw - 0.06F; arm.roll = MathHelper.cos(limbSpeed * 0.09F) * 0.05F + 0.05F; @@ -469,8 +482,8 @@ public abstract class AbstractPonyModel extends ClientPo protected void swingArm(ModelPart arm) { float swing = 1 - (float)Math.pow(1 - getSwingAmount(), 3); - float deltaX = MathHelper.sin(swing * PI); - float deltaZ = MathHelper.sin(getSwingAmount() * PI); + float deltaX = MathHelper.sin(swing * MathHelper.PI); + float deltaZ = MathHelper.sin(getSwingAmount() * MathHelper.PI); float deltaAim = deltaZ * (0.7F - head.pitch) * 0.75F; @@ -502,15 +515,15 @@ public abstract class AbstractPonyModel extends ClientPo } } - protected void adjustBody(float rotateAngleX, float rotationPointY, float rotationPointZ) { - adjustBodyComponents(rotateAngleX, rotationPointY, rotationPointZ); - neck.setPivot(NECK_ROT_X + rotateAngleX, rotationPointY, rotationPointZ); + protected void adjustBody(float pitch, Pivot pivot) { + adjustBodyComponents(pitch, pivot); + neck.setPivot(NECK_X + pitch, pivot.y(), pivot.z()); } - protected void adjustBodyComponents(float rotateAngleX, float rotationPointY, float rotationPointZ) { - body.pitch = rotateAngleX; - body.pivotY = rotationPointY; - body.pivotZ = rotationPointZ; + protected void adjustBodyComponents(float pitch, Pivot pivot) { + body.pitch = pitch; + body.pivotY = pivot.y(); + body.pivotZ = pivot.z(); } @Override diff --git a/src/main/java/com/minelittlepony/client/model/ClientPonyModel.java b/src/main/java/com/minelittlepony/client/model/ClientPonyModel.java index 1917dea4..116b6458 100644 --- a/src/main/java/com/minelittlepony/client/model/ClientPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/ClientPonyModel.java @@ -56,20 +56,15 @@ public abstract class ClientPonyModel extends MsonPlayer } @Override - public void copyAttributes(BipedEntityModel other) { + public final void copyAttributes(BipedEntityModel other) { copyStateTo(other); } @Override - public ModelAttributes getAttributes() { + public final ModelAttributes getAttributes() { return attributes; } - @Override - public IPonyData getMetadata() { - return attributes.metadata; - } - @Override public Size getSize() { return child ? Sizes.FOAL : getMetadata().getSize(); @@ -80,22 +75,11 @@ public abstract class ClientPonyModel extends MsonPlayer attributes.metadata = meta; } - @Override - public ModelPart getHead() { - return head; - } - - @Override - public boolean isRiding() { - return riding; - } - @Override public float getSwingAmount() { return handSwingProgress; } - @Override public ModelPart getArm(Arm side) { return super.getArm(side); diff --git a/src/main/java/com/minelittlepony/client/model/IMobModel.java b/src/main/java/com/minelittlepony/client/model/IMobModel.java index e24864f5..5d570ac2 100644 --- a/src/main/java/com/minelittlepony/client/model/IMobModel.java +++ b/src/main/java/com/minelittlepony/client/model/IMobModel.java @@ -4,7 +4,6 @@ import net.minecraft.client.model.ModelPart; import net.minecraft.util.Arm; import net.minecraft.util.math.MathHelper; -import com.minelittlepony.api.model.PonyModelConstants; import com.minelittlepony.mson.util.PartUtil; /** @@ -20,8 +19,8 @@ public interface IMobModel { * @param ticks Render partial ticks */ static void rotateArmHolding(ModelPart arm, float direction, float swingProgress, float ticks) { - float swing = MathHelper.sin(swingProgress * PonyModelConstants.PI); - float roll = MathHelper.sin((1 - (1 - swingProgress) * (1 - swingProgress)) * PonyModelConstants.PI); + float swing = MathHelper.sin(swingProgress * MathHelper.PI); + float roll = MathHelper.sin((1 - (1 - swingProgress) * (1 - swingProgress)) * MathHelper.PI); float cos = MathHelper.cos(ticks * 0.09F) * 0.05F + 0.05F; float sin = MathHelper.sin(ticks * 0.067F) / 10; diff --git a/src/main/java/com/minelittlepony/client/model/IPonyMixinModel.java b/src/main/java/com/minelittlepony/client/model/IPonyMixinModel.java index 2ccf8fd1..38dadaf8 100644 --- a/src/main/java/com/minelittlepony/client/model/IPonyMixinModel.java +++ b/src/main/java/com/minelittlepony/client/model/IPonyMixinModel.java @@ -43,11 +43,6 @@ public interface IPonyMixinModel mixin().transform(part, stack); } - @Override - default IPonyData getMetadata() { - return mixin().getMetadata(); - } - @Override default ModelAttributes getAttributes() { return mixin().getAttributes(); @@ -63,11 +58,6 @@ public interface IPonyMixinModel mixin().setMetadata(meta); } - @Override - default boolean isRiding() { - return mixin().isRiding(); - } - @Override default float getSwingAmount() { return mixin().getSwingAmount(); diff --git a/src/main/java/com/minelittlepony/client/model/IPonyModel.java b/src/main/java/com/minelittlepony/client/model/IPonyModel.java index e0da776e..482bfe07 100644 --- a/src/main/java/com/minelittlepony/client/model/IPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/IPonyModel.java @@ -8,11 +8,10 @@ import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.ICapitated; import com.minelittlepony.api.model.IModel; import com.minelittlepony.api.model.ModelAttributes; -import com.minelittlepony.api.model.PonyModelConstants; import com.minelittlepony.api.pony.IPony; import com.minelittlepony.mson.api.MsonModel; -public interface IPonyModel extends PonyModelConstants, IModel, ICapitated, MsonModel { +public interface IPonyModel extends IModel, ICapitated, MsonModel { void copyAttributes(BipedEntityModel other); diff --git a/src/main/java/com/minelittlepony/client/model/PonyElytra.java b/src/main/java/com/minelittlepony/client/model/PonyElytra.java index 55c98093..466b3f11 100644 --- a/src/main/java/com/minelittlepony/client/model/PonyElytra.java +++ b/src/main/java/com/minelittlepony/client/model/PonyElytra.java @@ -4,12 +4,11 @@ import net.minecraft.client.model.ModelPart; import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.render.entity.model.AnimalModel; import net.minecraft.entity.LivingEntity; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import com.google.common.collect.ImmutableList; -import static com.minelittlepony.api.model.PonyModelConstants.*; - /** * Modified from ModelElytra. */ @@ -42,11 +41,11 @@ public class PonyElytra extends AnimalModel { */ @Override public void setAngles(T entity, float limbDistance, float limbAngle, float age, float headYaw, float headPitch) { - float rotateX = PI / 2; - float rotateY = PI / 8; - float rotateZ = PI / 12; + float rotateX = MathHelper.PI / 2; + float rotateY = MathHelper.PI / 8; + float rotateZ = MathHelper.PI / 12; - float rpY = BODY_RP_Y; + float rpY = 0; if (entity.isFallFlying()) { float velY = 1; @@ -56,13 +55,13 @@ public class PonyElytra extends AnimalModel { velY = 1 - (float) Math.pow(-motion.normalize().y, 1.5); } - rotateX = velY * PI * (2 / 3F) + (1 - velY) * rotateX; - rotateY = velY * (PI / 2) + (1 - velY) * rotateY; + rotateX = velY * MathHelper.PI * (2 / 3F) + (1 - velY) * rotateX; + rotateY = velY * (MathHelper.PI / 2) + (1 - velY) * rotateY; } else if (isSneaking) { - rotateX = PI * 1.175F; - rotateY = PI / 2; - rotateZ = PI / 4; - rpY = BODY_RP_Y_SNEAK; + rotateX = MathHelper.PI * 1.175F; + rotateY = MathHelper.PI / 2; + rotateZ = MathHelper.PI / 4; + rpY = AbstractPonyModel.BODY_SNEAKING.y(); } leftWing.pivotX = 5; diff --git a/src/main/java/com/minelittlepony/client/model/entity/BreezieModel.java b/src/main/java/com/minelittlepony/client/model/entity/BreezieModel.java index 8766088b..be3debf5 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/BreezieModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/BreezieModel.java @@ -10,8 +10,6 @@ import net.minecraft.util.math.MathHelper; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; -import static com.minelittlepony.api.model.PonyModelConstants.PI; - public class BreezieModel extends BipedEntityModel { private ModelPart neck; @@ -48,13 +46,13 @@ public class BreezieModel extends BipedEntityModel { leftArm.pitch = MathHelper.cos(move * 0.6662F) * swing; leftArm.roll = 0; - rightArm.setAngles(swing * MathHelper.cos(move * 0.6662F + PI), 0, 0); - leftLeg .setAngles(swing * MathHelper.cos(move * 0.6662F + PI) * 1.4F, 0, 0); - rightLeg.setAngles(swing * MathHelper.cos(move * 0.6662F) * 1.4F, 0, 0); + rightArm.setAngles(swing * MathHelper.cos(move * 0.6662F + MathHelper.PI), 0, 0); + leftLeg .setAngles(swing * MathHelper.cos(move * 0.6662F + MathHelper.PI) * 1.4F, 0, 0); + rightLeg.setAngles(swing * MathHelper.cos(move * 0.6662F) * 1.4F, 0, 0); if (riding) { - leftArm.pitch += -PI / 5; - rightArm.pitch += -PI / 5; + leftArm.pitch += -MathHelper.PI / 5; + rightArm.pitch += -MathHelper.PI / 5; rotateLegRiding(leftLeg, -1); rotateLegRiding(rightLeg, 1); @@ -100,11 +98,11 @@ public class BreezieModel extends BipedEntityModel { protected void rotateLegRiding(ModelPart leg, float factor) { - leg.setAngles(-1.4137167F, factor * PI / 10, factor * 0.07853982F); + leg.setAngles(-1.4137167F, factor * MathHelper.PI / 10, factor * 0.07853982F); } protected void swingArms(Arm mainHand) { - body.yaw = MathHelper.sin(MathHelper.sqrt(handSwingProgress) * PI * 2) / 5; + body.yaw = MathHelper.sin(MathHelper.sqrt(handSwingProgress) * MathHelper.TAU) / 5; if (mainHand == Arm.LEFT) { body.yaw *= -1; @@ -124,13 +122,13 @@ public class BreezieModel extends BipedEntityModel { float swingAmount = 1 - (float)Math.pow(1 - handSwingProgress, 4); - float swingFactorX = MathHelper.sin(swingAmount * PI); - float swingX = MathHelper.sin(handSwingProgress * PI) * (0.7F - head.pitch) * 0.75F; + float swingFactorX = MathHelper.sin(swingAmount * MathHelper.PI); + float swingX = MathHelper.sin(handSwingProgress * MathHelper.PI) * (0.7F - head.pitch) * 0.75F; ModelPart mainArm = getArm(mainHand); mainArm.pitch -= swingFactorX * 1.2F + swingX; mainArm.yaw += body.yaw * 2; - mainArm.roll -= MathHelper.sin(handSwingProgress * PI) * 0.4F; + mainArm.roll -= MathHelper.sin(handSwingProgress * MathHelper.PI) * 0.4F; } protected void rotateArm(ModelPart arm, ArmPose pose, float factor) { @@ -139,7 +137,7 @@ public class BreezieModel extends BipedEntityModel { arm.yaw = 0; break; case ITEM: - arm.pitch = arm.pitch / 2 - (PI / 10); + arm.pitch = arm.pitch / 2 - (MathHelper.PI / 10); arm.yaw = 0; case BLOCK: arm.pitch = arm.pitch / 2 - 0.9424779F; @@ -151,9 +149,9 @@ public class BreezieModel extends BipedEntityModel { protected void raiseArm(ModelPart up, ModelPart down, float factor) { up.yaw = head.yaw + (factor / 10); - up.pitch = head.pitch - (PI / 2); + up.pitch = head.pitch - MathHelper.HALF_PI; down.yaw = head.yaw - (factor / 2); - down.pitch = head.pitch - (PI / 2); + down.pitch = head.pitch - MathHelper.HALF_PI; } } diff --git a/src/main/java/com/minelittlepony/client/model/entity/EnderStallionModel.java b/src/main/java/com/minelittlepony/client/model/entity/EnderStallionModel.java index 0fa4a898..7ab47868 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/EnderStallionModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/EnderStallionModel.java @@ -85,6 +85,6 @@ public class EnderStallionModel extends SkeleponyModel { @Override public float getWingRotationFactor(float ticks) { - return MathHelper.sin(ticks) + WING_ROT_Z_SNEAK; + return MathHelper.sin(ticks) + WINGS_HALF_SPREAD_ANGLE; } } diff --git a/src/main/java/com/minelittlepony/client/model/entity/WitchPonyModel.java b/src/main/java/com/minelittlepony/client/model/entity/WitchPonyModel.java index ea23a3fc..78c3a603 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/WitchPonyModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/WitchPonyModel.java @@ -44,7 +44,7 @@ public class WitchPonyModel extends EarthPonyModel { if (rot > 1) rot = 1; if (rot < -1) rot = -1; - float legDrinkingAngle = -1 * PI/3 + rot; + float legDrinkingAngle = -1 * MathHelper.PI/3 + rot; rightArm.pitch = legDrinkingAngle; rightArm.yaw = 0.1F; diff --git a/src/main/java/com/minelittlepony/client/model/entity/race/ChangelingModel.java b/src/main/java/com/minelittlepony/client/model/entity/race/ChangelingModel.java index eda44883..22273c5d 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/race/ChangelingModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/race/ChangelingModel.java @@ -18,8 +18,8 @@ public class ChangelingModel extends AlicornModel { @Override public float getWingRotationFactor(float ticks) { if (isFlying()) { - return MathHelper.sin(ticks * 3) + ROTATE_270; + return MathHelper.sin(ticks * 3) + WINGS_HALF_SPREAD_ANGLE; } - return WING_ROT_Z_SNEAK; + return WINGS_RAISED_ANGLE; } } diff --git a/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java b/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java index 1f7799ab..d656e318 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/race/SeaponyModel.java @@ -14,6 +14,8 @@ import net.minecraft.util.math.MathHelper; public class SeaponyModel extends UnicornModel { + private static final float FIN_Y_ANGLE = MathHelper.PI / 6; + private final ModelPart leftFin; private final ModelPart centerFin; private final ModelPart rightFin; @@ -62,7 +64,7 @@ public class SeaponyModel extends UnicornModel { flapMotion /= 2; } - float finAngle = FIN_ROT_Y + flapMotion; + float finAngle = FIN_Y_ANGLE + flapMotion; leftFin.yaw = finAngle; rightFin.yaw = -finAngle; diff --git a/src/main/java/com/minelittlepony/client/model/entity/race/UnicornModel.java b/src/main/java/com/minelittlepony/client/model/entity/race/UnicornModel.java index d6a5f647..a1011f66 100644 --- a/src/main/java/com/minelittlepony/client/model/entity/race/UnicornModel.java +++ b/src/main/java/com/minelittlepony/client/model/entity/race/UnicornModel.java @@ -62,8 +62,8 @@ public class UnicornModel extends EarthPonyModel impl @Override protected void ponyCrouch() { super.ponyCrouch(); - unicornArmRight.pitch -= LEG_ROT_X_SNEAK_ADJ; - unicornArmLeft.pitch -= LEG_ROT_X_SNEAK_ADJ; + unicornArmRight.pitch -= LEG_SNEAKING_PITCH_ADJUSTMENT; + unicornArmLeft.pitch -= LEG_SNEAKING_PITCH_ADJUSTMENT; } @Override diff --git a/src/main/java/com/minelittlepony/client/model/gear/ChristmasHat.java b/src/main/java/com/minelittlepony/client/model/gear/ChristmasHat.java index 347a0286..4022fb71 100644 --- a/src/main/java/com/minelittlepony/client/model/gear/ChristmasHat.java +++ b/src/main/java/com/minelittlepony/client/model/gear/ChristmasHat.java @@ -8,14 +8,13 @@ import net.minecraft.util.math.MathHelper; import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.IModel; -import com.minelittlepony.api.model.PonyModelConstants; import com.minelittlepony.api.pony.meta.Wearable; import com.minelittlepony.common.util.Color; import java.util.Calendar; import java.util.UUID; -public class ChristmasHat extends AbstractWearableGear implements PonyModelConstants { +public class ChristmasHat extends AbstractWearableGear { private static boolean dayChecked = false; private static boolean dayResult = false; @@ -49,7 +48,7 @@ public class ChristmasHat extends AbstractWearableGear implements PonyModelConst @Override public void pose(IModel model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) { - float pi = PI * (float) Math.pow(swing, 16); + float pi = MathHelper.PI * (float) Math.pow(swing, 16); float mve = move * 0.6662f; float srt = swing / 10; diff --git a/src/main/java/com/minelittlepony/client/model/gear/SaddleBags.java b/src/main/java/com/minelittlepony/client/model/gear/SaddleBags.java index a276fb4f..d42f13a2 100644 --- a/src/main/java/com/minelittlepony/client/model/gear/SaddleBags.java +++ b/src/main/java/com/minelittlepony/client/model/gear/SaddleBags.java @@ -3,8 +3,8 @@ package com.minelittlepony.client.model.gear; import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.IModel; import com.minelittlepony.api.model.IPegasus; -import com.minelittlepony.api.model.PonyModelConstants; import com.minelittlepony.api.pony.meta.Wearable; +import com.minelittlepony.util.MathUtil; import java.util.UUID; @@ -15,7 +15,7 @@ import net.minecraft.entity.Entity; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; -public class SaddleBags extends AbstractWearableGear implements PonyModelConstants { +public class SaddleBags extends AbstractWearableGear { public static final Identifier TEXTURE = new Identifier("minelittlepony", "textures/models/saddlebags.png"); @@ -43,7 +43,7 @@ public class SaddleBags extends AbstractWearableGear implements PonyModelConstan hangLow = model.canFly() && ((IPegasus)model).wingsAreOpen(); } - float pi = PI * (float) Math.pow(swing, 16); + float pi = MathHelper.PI * (float) Math.pow(swing, 16); float mve = move * 0.6662f; float srt = swing / 10; @@ -54,7 +54,7 @@ public class SaddleBags extends AbstractWearableGear implements PonyModelConstan rightBag.pitch = bodySwing; if (model instanceof IPegasus && model.isFlying()) { - bodySwing = ((IPegasus)model).getWingRotationFactor(ticks) - ROTATE_270; + bodySwing = ((IPegasus)model).getWingRotationFactor(ticks) - MathUtil.Angles._270_DEG; bodySwing /= 10; } diff --git a/src/main/java/com/minelittlepony/client/model/part/PonyTail.java b/src/main/java/com/minelittlepony/client/model/part/PonyTail.java index dd821e01..6dc1c4df 100644 --- a/src/main/java/com/minelittlepony/client/model/part/PonyTail.java +++ b/src/main/java/com/minelittlepony/client/model/part/PonyTail.java @@ -10,11 +10,16 @@ import com.minelittlepony.api.model.ModelAttributes; import com.minelittlepony.api.pony.meta.TailShape; import com.minelittlepony.client.model.AbstractPonyModel; import com.minelittlepony.mson.api.*; +import com.minelittlepony.util.MathUtil; import java.util.ArrayList; import java.util.List; public class PonyTail implements IPart, MsonModel { + private static final float TAIL_Z = 14; + private static final float TAIL_RIDING_Y = 3; + private static final float TAIL_RIDING_Z = 13; + private static final float TAIL_SNEAKING_Z = 15; private ModelPart tail; private AbstractPonyModel model; @@ -49,15 +54,16 @@ public class PonyTail implements IPart, MsonModel { tail.yaw = bodySwing * 5; if (model.getAttributes().isCrouching && !rainboom) { - rotateSneak(); - } else if (model.isRiding()) { - tail.pivotZ = TAIL_RP_Z_RIDING; - tail.pivotY = TAIL_RP_Y_RIDING; - tail.pitch = PI / 5; + tail.setPivot(0, 0, TAIL_SNEAKING_Z); + tail.pitch = -model.body.pitch + 0.1F; + } else if (model.getAttributes().isSitting) { + tail.pivotZ = TAIL_RIDING_Z; + tail.pivotY = TAIL_RIDING_Y; + tail.pitch = MathHelper.PI / 5; } else { - tail.setPivot(0, 0, TAIL_RP_Z); + tail.setPivot(0, 0, TAIL_Z); if (rainboom) { - tail.pitch = ROTATE_90 + MathHelper.sin(move) / 10; + tail.pitch = MathUtil.Angles._90_DEG + MathHelper.sin(move) / 10; } else { tail.pitch = swing / 2; @@ -77,11 +83,6 @@ public class PonyTail implements IPart, MsonModel { tail.yaw += sinTickFactor; } - private void rotateSneak() { - tail.setPivot(0, 0, TAIL_RP_Z_SNEAK); - tail.pitch = -BODY_ROT_X_SNEAK + 0.1F; - } - @Override public void setVisible(boolean visible, ModelAttributes attributes) { tail.visible = visible; diff --git a/src/main/java/com/minelittlepony/client/model/part/PonyWings.java b/src/main/java/com/minelittlepony/client/model/part/PonyWings.java index f5af1e54..880dcad9 100644 --- a/src/main/java/com/minelittlepony/client/model/part/PonyWings.java +++ b/src/main/java/com/minelittlepony/client/model/part/PonyWings.java @@ -10,6 +10,7 @@ import com.minelittlepony.api.model.*; import com.minelittlepony.api.pony.meta.Wearable; import com.minelittlepony.mson.api.ModelView; import com.minelittlepony.mson.api.MsonModel; +import com.minelittlepony.util.MathUtil; public class PonyWings implements IPart, MsonModel { @@ -57,9 +58,9 @@ public class PonyWings implements IPart, MsonModel { float progress = pegasus.getSwingAmount(); if (progress > 0) { - flap = MathHelper.sin(MathHelper.sqrt(progress) * PI * 2); + flap = MathHelper.sin(MathHelper.sqrt(progress) * MathHelper.TAU); } else { - float pi = PI * (float) Math.pow(swing, 16); + float pi = MathHelper.PI * (float) Math.pow(swing, 16); float mve = move * 0.6662f; // magic number ahoy (actually 2/3) float srt = swing / 4; @@ -70,7 +71,7 @@ public class PonyWings implements IPart, MsonModel { getLeft().rotateWalking(flap); getRight().rotateWalking(-flap); - float flapAngle = ROTATE_270; + float flapAngle = MathUtil.Angles._270_DEG; if (pegasus.wingsAreOpen()) { flapAngle = pegasus.getWingRotationFactor(ticks); @@ -78,7 +79,7 @@ public class PonyWings implements IPart, MsonModel { flapAngle -= 1F; } } else { - flapAngle = ROTATE_270 - 0.9F + (float)Math.sin(ticks / 10) / 15F; + flapAngle = MathUtil.Angles._270_DEG - 0.9F + (float)Math.sin(ticks / 10) / 15F; } if (!pegasus.isFlying()) { @@ -120,8 +121,8 @@ public class PonyWings implements IPart, MsonModel { folded.yaw = swing * walkingRotationSpeed; } - public void rotateFlying(float angle) { - extended.roll = angle; + public void rotateFlying(float roll) { + extended.roll = roll; } public void render(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha) { diff --git a/src/main/java/com/minelittlepony/client/model/part/SeaponyTail.java b/src/main/java/com/minelittlepony/client/model/part/SeaponyTail.java index 80176378..22d37fe9 100644 --- a/src/main/java/com/minelittlepony/client/model/part/SeaponyTail.java +++ b/src/main/java/com/minelittlepony/client/model/part/SeaponyTail.java @@ -10,9 +10,6 @@ import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.MathHelper; public class SeaponyTail implements IPart, MsonModel { - - private static final float TAIL_ROTX = PI / 2; - private final ModelPart tailBase; private final ModelPart tailTip; @@ -28,9 +25,9 @@ public class SeaponyTail implements IPart, MsonModel { public void setRotationAndAngles(ModelAttributes attributes, float move, float swing, float bodySwing, float ticks) { float rotation = attributes.isSleeping ? 0 : MathHelper.sin(ticks * 0.536f) / 4; - tailBase.pitch = TAIL_ROTX + rotation; + tailBase.pitch = MathHelper.HALF_PI + rotation; tailTip.pitch = rotation; - tailFins.pitch = rotation - TAIL_ROTX; + tailFins.pitch = rotation - MathHelper.HALF_PI; } @Override diff --git a/src/main/java/com/minelittlepony/client/render/IPonyRenderContext.java b/src/main/java/com/minelittlepony/client/render/IPonyRenderContext.java index 8a7f905f..edeb4710 100644 --- a/src/main/java/com/minelittlepony/client/render/IPonyRenderContext.java +++ b/src/main/java/com/minelittlepony/client/render/IPonyRenderContext.java @@ -1,7 +1,6 @@ package com.minelittlepony.client.render; import com.minelittlepony.api.model.BodyPart; -import com.minelittlepony.api.model.PonyModelConstants; import com.minelittlepony.api.model.gear.IGear; import com.minelittlepony.api.pony.IPony; import com.minelittlepony.client.model.*; @@ -11,7 +10,7 @@ import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; -public interface IPonyRenderContext & IPonyModel> extends PonyModelConstants, IGear.Context { +public interface IPonyRenderContext & IPonyModel> extends IGear.Context { IPony getEntityPony(T entity); diff --git a/src/main/java/com/minelittlepony/client/render/entity/PonyRenderer.java b/src/main/java/com/minelittlepony/client/render/entity/PonyRenderer.java index 7398543d..ed5a8230 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/PonyRenderer.java +++ b/src/main/java/com/minelittlepony/client/render/entity/PonyRenderer.java @@ -9,6 +9,7 @@ import net.minecraft.client.render.entity.feature.StuckArrowsFeatureRenderer; import net.minecraft.entity.mob.MobEntity; public class PonyRenderer> extends AbstractPonyRenderer { + protected static final float BASE_MODEL_SCALE = 15/16F; public PonyRenderer(EntityRendererFactory.Context context, ModelKey key, TextureSupplier texture) { this(context, key, texture, 1); diff --git a/src/main/java/com/minelittlepony/client/render/entity/feature/CapeFeature.java b/src/main/java/com/minelittlepony/client/render/entity/feature/CapeFeature.java index 740242c3..4eb168e8 100644 --- a/src/main/java/com/minelittlepony/client/render/entity/feature/CapeFeature.java +++ b/src/main/java/com/minelittlepony/client/render/entity/feature/CapeFeature.java @@ -4,8 +4,6 @@ import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.client.model.ClientPonyModel; import com.minelittlepony.client.render.IPonyRenderContext; -import static com.minelittlepony.api.model.PonyModelConstants.PI; - import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.render.OverlayTexture; import net.minecraft.client.render.RenderLayer; @@ -43,8 +41,8 @@ public class CapeFeature> float motionYaw = player.prevBodyYaw + (player.bodyYaw - player.prevBodyYaw); - double sin = MathHelper.sin(motionYaw * PI / 180); - double cos = (-MathHelper.cos(motionYaw * PI / 180)); + double sin = MathHelper.sin(motionYaw * MathHelper.RADIANS_PER_DEGREE); + double cos = -MathHelper.cos(motionYaw * MathHelper.RADIANS_PER_DEGREE); float capeMotionY = (float) capeY * 10; diff --git a/src/main/java/com/minelittlepony/client/transform/PonyTransformation.java b/src/main/java/com/minelittlepony/client/transform/PonyTransformation.java index 95142fb1..f1393ba1 100644 --- a/src/main/java/com/minelittlepony/client/transform/PonyTransformation.java +++ b/src/main/java/com/minelittlepony/client/transform/PonyTransformation.java @@ -3,13 +3,15 @@ package com.minelittlepony.client.transform; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.util.math.Vec3d; -import com.google.common.collect.Maps; import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.IModel; import com.minelittlepony.api.pony.meta.Size; import com.minelittlepony.api.pony.meta.Sizes; +import java.util.Arrays; import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; public enum PonyTransformation { @@ -19,7 +21,7 @@ public enum PonyTransformation { if (model.getAttributes().isSwimming) stack.translate(0, -0.3F, 0); if (model.getAttributes().isCrouching) stack.translate(0, -0.2F, 0); if (model.getAttributes().isSleeping) stack.translate(0, -0.61F, 0.1F); - if (model.isRiding()) stack.translate(0, -0.2F, -0.2F); + if (model.getAttributes().isSitting) stack.translate(0, -0.2F, -0.2F); switch (part) { case NECK: @@ -29,7 +31,7 @@ public enum PonyTransformation { if (model.getAttributes().isCrouching) stack.translate(0, 0.1F, 0); break; case BACK: - stack.translate(riderOffset.x, riderOffset.y, riderOffset.z); + translateForRider(stack); break; default: } @@ -41,7 +43,7 @@ public enum PonyTransformation { if (model.getAttributes().isSwimming) stack.translate(0, -0.2F, 0); if (model.getAttributes().isCrouching) stack.translate(0, -0.15F, 0); if (model.getAttributes().isSleeping) stack.translate(0, -0.6F, 0.15F); - if (model.isRiding()) stack.translate(0, 0, -0.2F); + if (model.getAttributes().isSitting) stack.translate(0, 0, -0.2F); switch (part) { case NECK: @@ -66,7 +68,7 @@ public enum PonyTransformation { stack.scale(0.9F, 1.12F, 0.9F); break; case BACK: - stack.translate(riderOffset.x, riderOffset.y, riderOffset.z); + translateForRider(stack); break; } } @@ -76,7 +78,7 @@ public enum PonyTransformation { public void transform(IModel model, BodyPart part, MatrixStack stack) { if (model.getAttributes().isCrouching) stack.translate(0, -0.15F, 0); if (model.getAttributes().isSleeping) stack.translate(0, -0.6F, 0.25F); - if (model.isRiding()) stack.translate(0, 0, -0.2F); + if (model.getAttributes().isSitting) stack.translate(0, 0, -0.2F); switch (part) { case NECK: @@ -101,7 +103,7 @@ public enum PonyTransformation { stack.scale(1.15F, 1.12F, 1.15F); break; case BACK: - stack.translate(riderOffset.x, riderOffset.y, riderOffset.z); + translateForRider(stack); break; } } @@ -112,7 +114,7 @@ public enum PonyTransformation { if (model.getAttributes().isSwimming) stack.translate(0, -0.9F, 0); if (model.getAttributes().isCrouching) stack.translate(0, -0.2F, 0); if (model.getAttributes().isSleeping) stack.translate(0, -0.8F, -0.3F); - if (model.isRiding()) stack.translate(0, -0.6F, -0.2F); + if (model.getAttributes().isSitting) stack.translate(0, -0.6F, -0.2F); stack.translate(0, 0.2F, 0); @@ -130,7 +132,7 @@ public enum PonyTransformation { stack.scale(1, 0.81F, 1); break; case BACK: - stack.translate(riderOffset.x, riderOffset.y, riderOffset.z); + translateForRider(stack); break; default: } @@ -141,7 +143,7 @@ public enum PonyTransformation { public void transform(IModel model, BodyPart part, MatrixStack stack) { if (model.getAttributes().isCrouching) stack.translate(0, -0.15F, 0); if (model.getAttributes().isSleeping) stack.translate(0, -0.5F, 0.35F); - if (model.isRiding()) stack.translate(0, 0.1F, -0.2F); + if (model.getAttributes().isSitting) stack.translate(0, 0.1F, -0.2F); switch (part) { case NECK: @@ -163,8 +165,7 @@ public enum PonyTransformation { if (model.getAttributes().isGoingFast) stack.translate(0, 0.05F, 0); break; case BACK: - riderOffset = new Vec3d(0, 2.2F, 0.75F); - stack.translate(riderOffset.x, riderOffset.y, riderOffset.z); + translateForRider(stack); break; } } @@ -175,7 +176,7 @@ public enum PonyTransformation { if (model.getAttributes().isSwimming) stack.translate(0, -0.6F, 0); if (model.getAttributes().isCrouching) stack.translate(0, -0.15F, 0); if (model.getAttributes().isSleeping) stack.translate(0, -0.45F, -0.3F); - if (model.isRiding()) stack.translate(0, -0.4F, -0.2F); + if (model.getAttributes().isSitting) stack.translate(0, -0.4F, -0.2F); switch (part) { case NECK: @@ -198,23 +199,16 @@ public enum PonyTransformation { if (model.getAttributes().isGoingFast) stack.translate(0, 0.05F, 0); break; case BACK: - stack.translate(riderOffset.x, riderOffset.y, riderOffset.z); + translateForRider(stack); break; } } }; - private static final Map REGISTRY = Maps.newEnumMap(Sizes.class); - - static { - for (PonyTransformation i : values()) { - REGISTRY.put(i.size, i); - } - } - - protected Vec3d riderOffset; + private static final Map REGISTRY = Arrays.stream(values()).collect(Collectors.toMap(i -> i.size, Function.identity())); private final Sizes size; + private final Vec3d riderOffset; PonyTransformation(Sizes size, float rX, float rY, float rZ) { this.size = size; @@ -225,6 +219,10 @@ public enum PonyTransformation { return riderOffset; } + public void translateForRider(MatrixStack stack) { + stack.translate(riderOffset.x, riderOffset.y, riderOffset.z); + } + public abstract void transform(IModel model, BodyPart part, MatrixStack stack); public static PonyTransformation forSize(Size size) { diff --git a/src/main/java/com/minelittlepony/util/MathUtil.java b/src/main/java/com/minelittlepony/util/MathUtil.java index 81a5f186..7df0afa2 100644 --- a/src/main/java/com/minelittlepony/util/MathUtil.java +++ b/src/main/java/com/minelittlepony/util/MathUtil.java @@ -2,13 +2,19 @@ package com.minelittlepony.util; import net.minecraft.util.math.MathHelper; -public class MathUtil { +public interface MathUtil { + interface Angles { + float + _270_DEG = 270 * MathHelper.RADIANS_PER_DEGREE, + _90_DEG = 90 * MathHelper.RADIANS_PER_DEGREE + ; + } - public static double clampLimit(double num, double limit) { + static double clampLimit(double num, double limit) { return MathHelper.clamp(num, -limit, limit); } - public static int mod(int value, int mod) { + static int mod(int value, int mod) { value %= mod; while (value < 0) value += mod; @@ -16,7 +22,7 @@ public class MathUtil { return value; } - public static float interpolateDegress(float prev, float current, float partialTicks) { + static float interpolateDegress(float prev, float current, float partialTicks) { float difference = current - prev; while (difference < -180) difference += 360; @@ -25,7 +31,7 @@ public class MathUtil { return prev + partialTicks * difference; } - public static boolean compareFloats(float a, float b) { + static boolean compareFloats(float a, float b) { return Math.abs(a - b) <= 0.001F; } }