Perform a little housekeeping

This commit is contained in:
Sollace 2021-12-09 16:42:09 +02:00
parent 9132097c41
commit 2ad3280cac
5 changed files with 73 additions and 130 deletions

View file

@ -13,6 +13,7 @@ import java.util.UUID;
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 {
/**
@ -114,7 +115,7 @@ public class ModelAttributes {
return (MathHelper.sin(ticks * 0.136f) / 2) + ROTATE_270;
}
if (isFlying) {
return MathHelper.sin(ticks * 0.536f) + ROTATE_270 + 0.4f;
return MathHelper.sin(ticks * 0.536f) + WING_ROT_Z_FLYING;
}
return WING_ROT_Z_SNEAK;
}

View file

@ -1,72 +1,53 @@
package com.minelittlepony.api.model;
public interface PonyModelConstants {
float
PI = (float)Math.PI,
BASE_MODEL_SCALE = 15/16F,
BODY_CENTRE_X = 0,
BODY_CENTRE_Y = 8,
BODY_CENTRE_Z = 6,
NECK_CENTRE_X = BODY_CENTRE_X - 2,
NECK_CENTRE_Y = BODY_CENTRE_Y - 6.8F,
NECK_CENTRE_Z = BODY_CENTRE_Z - 8.8F,
BODY_ROT_X_NOTSNEAK = 0,
BODY_ROT_X_SNEAK = 0.4F,
BODY_ROT_X_RIDING = PI * 3.8F,
BODY_RP_Y_NOTSNEAK = 0,
BODY_RP_Y_SNEAK = 7,
BODY_RP_Y_RIDING = 1,
BODY_RP_Z_NOTSNEAK = 0,
BODY_RP_Z_SNEAK = -4,
BODY_RP_Z_RIDING = 4,
FRONT_LEG_RP_Y_NOTSNEAK = 8,
FRONT_LEG_RP_Y_SNEAK = 8,
HEAD_CENTRE_X = 0,
HEAD_CENTRE_Y = -1,
HEAD_CENTRE_Z = -2,
HEAD_RP_X = 0,
HEAD_RP_Y = 0,
HEAD_RP_Z = 0,
HORN_X = HEAD_CENTRE_X - 0.5F,
HORN_Y = HEAD_CENTRE_Y - 10,
HORN_Z = HEAD_CENTRE_Z - 1.5F,
EXT_WING_RP_X = 4.5F,
EXT_WING_RP_Y = 5.3F,
EXT_WING_RP_Z = 6,
WING_ROT_Z_SNEAK = 4,
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,
TAIL_RP_X = 0,
TAIL_RP_Y = 0,
LEG_SLEEP_OFFSET_Y = 2,
FRONT_LEG_SLEEP_OFFSET_Z = 6,
BACK_LEG_SLEEP_OFFSET_Z = -8,
TAIL_RP_Z_NOTSNEAK = 14,
TAIL_RP_Z = 14,
TAIL_RP_Z_SNEAK = 15,
TAIL_RP_Y_RIDING = 3,
TAIL_RP_Z_RIDING = 13,
THIRDP_ARM_CENTRE_X = 0,
THIRDP_ARM_CENTRE_Y = 4,
HEAD_RP_X_SNEAK = 0,
HEAD_RP_Y_SNEAK = 6,
HEAD_RP_Z_SNEAK = -2,
WING_FOLDED_RP_Y = 13,
WING_FOLDED_RP_Z = -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,

View file

@ -78,17 +78,17 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
} else if (riding) {
ponySit();
} else {
adjustBody(BODY_ROT_X_NOTSNEAK, BODY_RP_Y_NOTSNEAK, BODY_RP_Z_NOTSNEAK);
adjustBody(BODY_ROT_X, BODY_RP_Y, BODY_RP_Z);
rightLeg.pivotY = FRONT_LEG_RP_Y_NOTSNEAK;
leftLeg.pivotY = FRONT_LEG_RP_Y_NOTSNEAK;
rightLeg.pivotY = FRONT_LEG_RP_Y;
leftLeg.pivotY = FRONT_LEG_RP_Y;
if (!attributes.isSleeping) {
animateBreathing(ticks);
}
if (attributes.isSwimmingRotated) {
head.setPivot(0, -2, -4);
head.setPivot(0, HEAD_RP_Y_SWIM, HEAD_RP_Z_SWIM);
} else {
head.setPivot(0, 0, 0);
}
@ -98,7 +98,13 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
ponySleep();
}
animateWears();
leftSleeve.copyTransform(leftArm);
rightSleeve.copyTransform(rightArm);
leftPants.copyTransform(leftLeg);
rightPants.copyTransform(rightLeg);
jacket.copyTransform(body);
hat.copyTransform(head);
upperTorsoOverlay.copyTransform(upperTorso);
}
/**
@ -106,7 +112,7 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
*/
protected void ponyCrouch() {
adjustBody(BODY_ROT_X_SNEAK, BODY_RP_Y_SNEAK, BODY_RP_Z_SNEAK);
head.setPivot(0, 6, -2);
head.setPivot(HEAD_RP_X_SNEAK, HEAD_RP_Y_SNEAK, HEAD_RP_Z_SNEAK);
rightArm.pitch -= LEG_ROT_X_SNEAK_ADJ;
leftArm.pitch -= LEG_ROT_X_SNEAK_ADJ;
@ -122,22 +128,22 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
rightLeg.pitch = ROTATE_90;
leftLeg.pitch = ROTATE_90;
head.setPivot(1, 2, sneaking ? -1 : 1);
head.setPivot(HEAD_RP_X_SLEEP, HEAD_RP_Y_SLEEP, sneaking ? -1 : 1);
PartUtil.shift(rightArm, 0, 2, 6);
PartUtil.shift(leftArm, 0, 2, 6);
PartUtil.shift(rightLeg, 0, 2, -8);
PartUtil.shift(leftLeg, 0, 2, -8);
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);
}
protected void ponySit() {
if (attributes.isRidingInteractive) {
adjustBodyComponents(BODY_ROT_X_RIDING * 2, BODY_RP_Y_RIDING, BODY_RP_Z_RIDING);
adjustNeck(BODY_ROT_X_NOTSNEAK * 2, BODY_RP_Y_NOTSNEAK, BODY_RP_Z_NOTSNEAK - 4);
adjustNeck(BODY_ROT_X * 2, BODY_RP_Y, BODY_RP_Z - 4);
head.setPivot(0, -2, -5);
} else {
adjustBodyComponents(BODY_ROT_X_RIDING, BODY_RP_Y_RIDING, BODY_RP_Z_RIDING);
adjustNeck(BODY_ROT_X_NOTSNEAK, BODY_RP_Y_NOTSNEAK, BODY_RP_Z_NOTSNEAK);
adjustNeck(BODY_ROT_X, BODY_RP_Y, BODY_RP_Z);
head.setPivot(0, 0, 0);
}
@ -189,16 +195,6 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
neck.yaw = bodySwing;
}
private void animateWears() {
leftSleeve.copyTransform(leftArm);
rightSleeve.copyTransform(rightArm);
leftPants.copyTransform(leftLeg);
rightPants.copyTransform(rightLeg);
jacket.copyTransform(body);
hat.copyTransform(head);
upperTorsoOverlay.copyTransform(upperTorso);
}
/**
* Called to update the head rotation.
*
@ -213,18 +209,12 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
headPitch -= 0.9F;
}
head.yaw = 0;
head.roll = 0;
if (attributes.isSwimmingRotated) {
head.roll = -headYaw;
} else {
head.yaw = headYaw;
}
float pitch = (float)Math.toRadians(attributes.motionPitch);
head.pitch = MathHelper.clamp(headPitch, -1.25f - pitch, 0.5f - pitch);
head.setAngles(
MathHelper.clamp(headPitch, -1.25f - pitch, 0.5f - pitch),
attributes.isSwimmingRotated ? 0 : headYaw,
attributes.isSwimmingRotated ? -headYaw : 0
);
}
/**
@ -280,19 +270,10 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
float left = (ROTATE_90 + MathHelper.sin((move / 3) + 2 * PI) / 2) * lerp;
float right = (ROTATE_90 + MathHelper.sin(move / 3) / 2) * lerp;
leftArm.pitch = -left;
leftArm.yaw = -left/2;
leftArm.roll = left/2;
rightArm.pitch = -right;
rightArm.yaw = right/2;
rightArm.roll = -right/2;
leftLeg.pitch = legLeft;
rightLeg.pitch = right;
leftLeg.yaw = 0;
rightLeg.yaw = 0;
leftArm.setAngles(-left, -left/2, left/2);
rightArm.setAngles(-right, right/2, -right/2);
leftLeg.setAngles(legLeft, 0, leftLeg.roll);
rightLeg.setAngles(right, 0, rightLeg.roll);
}
/**
@ -305,20 +286,10 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
float armX = attributes.isGoingFast ? ROTATE_270 : MathHelper.sin(-swing / 2);
float legX = attributes.isGoingFast ? ROTATE_90 : MathHelper.sin(swing / 2);
leftArm.pitch = armX;
rightArm.pitch = armX;
leftLeg.pitch = legX;
rightLeg.pitch = legX;
leftArm.yaw = -0.2F;
leftLeg.yaw = 0.2F;
rightArm.yaw = 0.2F;
rightLeg.yaw = -0.2F;
rightArm.roll = 0;
leftArm.roll = 0;
leftArm.setAngles(armX, -0.2F, 0);
rightArm.setAngles(armX, 0.2F, 0);
leftLeg.setAngles(legX, 0.2F, leftLeg.roll);
rightLeg.setAngles(legX, -0.2F, rightLeg.roll);
}
/**
@ -333,20 +304,10 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
float baseRotation = move * 0.6662F; // magic number ahoy
float scale = swing / 4;
leftArm.pitch = MathHelper.cos(baseRotation + angle) * scale;
rightArm.pitch = MathHelper.cos(baseRotation + PI + angle / 2) * scale;
leftLeg.pitch = MathHelper.cos(baseRotation + PI - (angle * 0.4f)) * scale;
rightLeg.pitch = MathHelper.cos(baseRotation + angle / 5) * scale;
leftArm.yaw = 0;
rightArm.yaw = 0;
leftLeg.yaw = 0;
rightLeg.yaw = 0;
rightArm.roll = 0;
leftArm.roll = 0;
leftArm.setAngles(MathHelper.cos(baseRotation + angle) * scale, 0, 0);
rightArm.setAngles(MathHelper.cos(baseRotation + PI + angle / 2) * scale, 0, 0);
leftLeg.setAngles(MathHelper.cos(baseRotation + PI - (angle * 0.4f)) * scale, 0, leftLeg.roll);
rightLeg.setAngles(MathHelper.cos(baseRotation + angle / 5) * scale, 0, rightLeg.roll);
}
protected float getLegOutset() {

View file

@ -46,7 +46,7 @@ public class PonyElytra<T extends LivingEntity> extends AnimalModel<T> {
float rotateY = PI / 8;
float rotateZ = PI / 12;
float rpY = BODY_RP_Y_NOTSNEAK;
float rpY = BODY_RP_Y;
if (entity.isFallFlying()) {
float velY = 1;

View file

@ -64,7 +64,7 @@ public class PonyTail implements IPart, MsonModel {
tail.pivotY = TAIL_RP_Y_RIDING;
tail.pitch = PI / 5;
} else {
tail.setPivot(TAIL_RP_X, TAIL_RP_Y, TAIL_RP_Z_NOTSNEAK);
tail.setPivot(0, 0, TAIL_RP_Z);
if (rainboom) {
tail.pitch = ROTATE_90 + MathHelper.sin(move) / 10;
} else {
@ -89,7 +89,7 @@ public class PonyTail implements IPart, MsonModel {
}
private void rotateSneak() {
tail.setPivot(TAIL_RP_X, TAIL_RP_Y, TAIL_RP_Z_SNEAK);
tail.setPivot(0, 0, TAIL_RP_Z_SNEAK);
tail.pitch = -BODY_ROT_X_SNEAK + 0.1F;
}