Handle positioning clothing separately to simplify downstream code

This commit is contained in:
Sollace 2022-07-06 11:10:27 +02:00
parent e8a5e6ce13
commit aecc80669c
12 changed files with 47 additions and 59 deletions

View file

@ -1,8 +1,7 @@
package com.minelittlepony.client.model;
import com.minelittlepony.client.model.armour.PonyArmourModel;
import com.minelittlepony.api.model.BodyPart;
import com.minelittlepony.api.model.ModelAttributes;
import com.minelittlepony.api.model.*;
import com.minelittlepony.api.model.armour.IArmour;
import com.minelittlepony.api.model.fabric.PonyModelPrepareCallback;
import com.minelittlepony.api.pony.meta.Sizes;
@ -24,10 +23,10 @@ import net.minecraft.util.math.MathHelper;
*/
public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPonyModel<T> {
protected ModelPart upperTorso;
protected ModelPart upperTorsoOverlay;
protected final ModelPart upperTorso;
protected final ModelPart upperTorsoOverlay;
protected ModelPart neck;
protected final ModelPart neck;
public AbstractPonyModel(ModelPart tree) {
super(tree);
@ -58,11 +57,25 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
* @param entity The entity we're being called for.
*/
@Override
public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
public final void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
attributes.checkRainboom(entity, swing, canFly(), ticks);
PonyModelPrepareCallback.EVENT.invoker().onPonyModelPrepared(entity, this, ModelAttributes.Mode.OTHER);
super.setAngles(entity, move, swing, ticks, headYaw, headPitch);
head.pivotY = head.getDefaultTransform().pivotY;
setModelAngles(entity, move, swing, ticks, headYaw, headPitch);
leftSleeve.copyTransform(leftArm);
rightSleeve.copyTransform(rightArm);
leftPants.copyTransform(leftLeg);
rightPants.copyTransform(rightLeg);
jacket.copyTransform(body);
hat.copyTransform(head);
upperTorsoOverlay.copyTransform(upperTorso);
}
protected void setModelAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
rotateHead(headYaw, headPitch);
shakeBody(move, swing, getWobbleAmount(), ticks);
rotateLegs(move, swing, ticks, entity);
@ -88,22 +101,12 @@ public abstract class AbstractPonyModel<T extends LivingEntity> extends ClientPo
if (attributes.isSwimmingRotated) {
head.setPivot(0, HEAD_RP_Y_SWIM, HEAD_RP_Z_SWIM);
} else {
head.setPivot(0, 0, 0);
}
}
if (attributes.isSleeping) {
ponySleep();
}
leftSleeve.copyTransform(leftArm);
rightSleeve.copyTransform(rightArm);
leftPants.copyTransform(leftLeg);
rightPants.copyTransform(rightLeg);
jacket.copyTransform(body);
hat.copyTransform(head);
upperTorsoOverlay.copyTransform(upperTorso);
}
public void setHeadRotation(float animationProgress, float yaw, float pitch) {

View file

@ -37,8 +37,8 @@ public class EnderStallionModel extends SkeleponyModel<EndermanEntity> {
}
@Override
public void setAngles(EndermanEntity entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setAngles(entity, move, swing, ticks, headYaw, headPitch);
public void setModelAngles(EndermanEntity entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setModelAngles(entity, move, swing, ticks, headYaw, headPitch);
if (isAttacking) {
head.pivotY -= 5;

View file

@ -14,8 +14,8 @@ public class IllagerPonyModel<T extends IllagerEntity> extends AlicornModel<T> {
}
@Override
public void setAngles(T illager, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setAngles(illager, move, swing, ticks, headYaw, headPitch);
public void setModelAngles(T illager, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setModelAngles(illager, move, swing, ticks, headYaw, headPitch);
IllagerEntity.State pose = illager.getState();

View file

@ -44,8 +44,8 @@ public class PiglinPonyModel extends ZomponyModel<HostileEntity> {
}
@Override
public void setAngles(HostileEntity entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setAngles(entity, move, swing, ticks, headYaw, headPitch);
public void setModelAngles(HostileEntity entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setModelAngles(entity, move, swing, ticks, headYaw, headPitch);
float progress = ticks * 0.1F + move * 0.5F;
float range = 0.08F + swing * 0.4F;

View file

@ -22,8 +22,6 @@ public class PonyArmourStandModel extends ArmorStandEntityModel {
leftArm.visible = true;
rightArm.visible = true;
if (entity.getLeftLegRotation().equals(DEFAULT_LEFT_LEG_ROTATION)) {
PartUtil.copyAngles(leftArm, leftLeg);
leftLeg.pitch *= -1;

View file

@ -82,11 +82,11 @@ public class SpikeModel<T extends LivingEntity> extends BipedEntityModel<T> {
tail2.yaw = tail.yaw / 2;
tail3.yaw = tail2.yaw / 2;
for (var part : this.getHeadParts()) {
for (var part : getHeadParts()) {
part.pivotY += 7;
}
for (var part : this.getBodyParts()) {
for (var part : getBodyParts()) {
part.pivotY += 7;
}
}

View file

@ -80,23 +80,16 @@ public class VillagerPonyModel<T extends LivingEntity & VillagerDataContainer> e
}
@Override
public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setAngles(entity, move, swing, ticks, headYaw, headPitch);
public void setModelAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setModelAngles(entity, move, swing, ticks, headYaw, headPitch);
boolean isHeadRolling = entity instanceof MerchantEntity
&& ((MerchantEntity)entity).getHeadRollingTimeLeft() > 0;
boolean isHeadRolling = entity instanceof MerchantEntity && ((MerchantEntity)entity).getHeadRollingTimeLeft() > 0;
if (isHeadRolling) {
float roll = 0.3F * MathHelper.sin(0.45F * ticks);
this.head.roll = roll;
this.hat.roll = roll;
this.head.pitch = 0.4F;
this.hat.pitch = 0.4F;
head.roll = 0.3F * MathHelper.sin(0.45F * ticks);
head.pitch = 0.4F;
} else {
this.head.roll = 0.0F;
this.hat.roll = 0.0F;
head.roll = 0;
}
}
}

View file

@ -28,8 +28,8 @@ public class WitchPonyModel extends EarthPonyModel<WitchEntity> {
}
@Override
public void setAngles(WitchEntity entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setAngles(entity, move, swing, ticks, headYaw, headPitch);
public void setModelAngles(WitchEntity entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setModelAngles(entity, move, swing, ticks, headYaw, headPitch);
if (entity.isDrinking()) {
float noseRot = MathHelper.sin(entity.age);
@ -39,7 +39,6 @@ public class WitchPonyModel extends EarthPonyModel<WitchEntity> {
snout.rotate(0, 0, 0);
}
if (rightArmPose != ArmPose.EMPTY) {
float rot = (float)(Math.tan(ticks / 7) + Math.sin(ticks / 3));
if (rot > 1) rot = 1;
@ -48,21 +47,16 @@ public class WitchPonyModel extends EarthPonyModel<WitchEntity> {
float legDrinkingAngle = -1 * PI/3 + rot;
rightArm.pitch = legDrinkingAngle;
rightSleeve.pitch = legDrinkingAngle;
rightArm.yaw = 0.1F;
rightSleeve.yaw = 0.1F;
rightArm.pivotX = 0.1F;
rightSleeve.pivotX = 0.1F;
if (rot > 0) {
rot = 0;
}
head.pitch = -rot / 2;
hat.pitch = -rot / 2;
} else {
rightArm.pivotX = 0;
rightSleeve.pivotX = 0;
}
}

View file

@ -29,8 +29,8 @@ public class AlicornModel<T extends LivingEntity> extends UnicornModel<T> implem
}
@Override
public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setAngles(entity, move, swing, ticks, headYaw, headPitch);
public void setModelAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setModelAngles(entity, move, swing, ticks, headYaw, headPitch);
if (canFly()) {
getWings().setRotationAndAngles(attributes.isGoingFast, attributes.interpolatorId, move, swing, 0, ticks);

View file

@ -33,8 +33,8 @@ public class EarthPonyModel<T extends LivingEntity> extends AbstractPonyModel<T>
}
@Override
public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setAngles(entity, move, swing, ticks, headYaw, headPitch);
public void setModelAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setModelAngles(entity, move, swing, ticks, headYaw, headPitch);
snout.setGender(getMetadata().getGender());
cape.pivotY = sneaking ? 2 : riding ? -4 : 0;
}

View file

@ -29,8 +29,8 @@ public class PegasusModel<T extends LivingEntity> extends EarthPonyModel<T> impl
}
@Override
public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setAngles(entity, move, swing, ticks, headYaw, headPitch);
public void setModelAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setModelAngles(entity, move, swing, ticks, headYaw, headPitch);
getWings().setRotationAndAngles(attributes.isGoingFast, entity.getUuid(), move, swing, 0, ticks);
}

View file

@ -16,7 +16,7 @@ import net.minecraft.util.math.MathHelper;
public class SeaponyModel<T extends LivingEntity> extends UnicornModel<T> {
private final ModelPart bodyCenter;
private final ModelPart abdomin;
private final ModelPart leftFin;
private final ModelPart centerFin;
@ -24,7 +24,7 @@ public class SeaponyModel<T extends LivingEntity> extends UnicornModel<T> {
public SeaponyModel(ModelPart tree, boolean smallArms) {
super(tree, smallArms);
bodyCenter = tree.getChild("abdomin");
abdomin = tree.getChild("abdomin");
leftFin = tree.getChild("left_fin");
rightFin = tree.getChild("right_fin");
centerFin = tree.getChild("center_fin");
@ -61,8 +61,8 @@ public class SeaponyModel<T extends LivingEntity> extends UnicornModel<T> {
protected void ponySit() {}
@Override
public void setAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setAngles(entity, move, swing, ticks, headYaw, headPitch);
public void setModelAngles(T entity, float move, float swing, float ticks, float headYaw, float headPitch) {
super.setModelAngles(entity, move, swing, ticks, headYaw, headPitch);
float flapMotion = MathHelper.cos(ticks / 10) / 5;
@ -113,7 +113,7 @@ public class SeaponyModel<T extends LivingEntity> extends UnicornModel<T> {
@Override
protected void renderBody(MatrixStack stack, VertexConsumer vertices, int overlayUv, int lightUv, float red, float green, float blue, float alpha) {
body.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha);
bodyCenter.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha);
abdomin.render(stack, vertices, overlayUv, lightUv, red, green, blue, alpha);
body.rotate(stack);
tail.renderPart(stack, vertices, overlayUv, lightUv, red, green, blue, alpha, attributes.interpolatorId);
@ -142,7 +142,7 @@ public class SeaponyModel<T extends LivingEntity> extends UnicornModel<T> {
leftPants.visible = false;
rightPants.visible = false;
bodyCenter.visible = visible;
abdomin.visible = visible;
leftFin.visible = visible;
centerFin.visible = visible;