| 1 | package net.minecraft.client.model.animal.equine;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.EntityModel;
|
| 6 | import net.minecraft.client.model.geom.ModelPart;
|
| 7 | import net.minecraft.client.model.geom.PartPose;
|
| 8 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 9 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 10 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 12 | import net.minecraft.client.renderer.entity.state.EquineRenderState;
|
| 13 | import net.minecraft.util.Mth;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public abstract class AbstractEquineModel<T extends EquineRenderState> extends EntityModel<T> {
|
| 17 | private static final float DEG_125 = 2.1816616F;
|
| 18 | private static final float DEG_60 = (float) (Math.PI / 3);
|
| 19 | private static final float DEG_45 = (float) (Math.PI / 4);
|
| 20 | private static final float DEG_30 = (float) (Math.PI / 6);
|
| 21 | private static final float DEG_15 = (float) (Math.PI / 12);
|
| 22 | protected static final String HEAD_PARTS = "head_parts";
|
| 23 | protected final ModelPart body;
|
| 24 | protected final ModelPart headParts;
|
| 25 | protected final ModelPart rightHindLeg;
|
| 26 | protected final ModelPart leftHindLeg;
|
| 27 | protected final ModelPart rightFrontLeg;
|
| 28 | protected final ModelPart leftFrontLeg;
|
| 29 | private final ModelPart tail;
|
| 30 |
|
| 31 | public AbstractEquineModel(final ModelPart root) {
|
| 32 | super(root);
|
| 33 | this.body = root.getChild("body");
|
| 34 | this.headParts = root.getChild("head_parts");
|
| 35 | this.rightHindLeg = root.getChild("right_hind_leg");
|
| 36 | this.leftHindLeg = root.getChild("left_hind_leg");
|
| 37 | this.rightFrontLeg = root.getChild("right_front_leg");
|
| 38 | this.leftFrontLeg = root.getChild("left_front_leg");
|
| 39 | this.tail = this.body.getChild("tail");
|
| 40 | }
|
| 41 |
|
| 42 | public AbstractEquineModel(
|
| 43 | final ModelPart root,
|
| 44 | final ModelPart headParts,
|
| 45 | final ModelPart rightHindLeg,
|
| 46 | final ModelPart rightFrontLeg,
|
| 47 | final ModelPart leftHindLeg,
|
| 48 | final ModelPart leftFrontLeg,
|
| 49 | final ModelPart tail
|
| 50 | ) {
|
| 51 | super(root);
|
| 52 | this.body = root.getChild("body");
|
| 53 | this.headParts = headParts;
|
| 54 | this.rightHindLeg = rightHindLeg;
|
| 55 | this.leftHindLeg = leftHindLeg;
|
| 56 | this.rightFrontLeg = rightFrontLeg;
|
| 57 | this.leftFrontLeg = leftFrontLeg;
|
| 58 | this.tail = tail;
|
| 59 | }
|
| 60 |
|
| 61 | public static MeshDefinition createBodyMesh(final CubeDeformation g) {
|
| 62 | MeshDefinition mesh = new MeshDefinition();
|
| 63 | PartDefinition root = mesh.getRoot();
|
| 64 | PartDefinition body = root.addOrReplaceChild(
|
| 65 | "body",
|
| 66 | CubeListBuilder.create().texOffs(0, 32).addBox(-5.0F, -8.0F, -17.0F, 10.0F, 10.0F, 22.0F, new CubeDeformation(0.05F)),
|
| 67 | PartPose.offset(0.0F, 11.0F, 5.0F)
|
| 68 | );
|
| 69 | PartDefinition headParts = root.addOrReplaceChild(
|
| 70 | "head_parts",
|
| 71 | CubeListBuilder.create().texOffs(0, 35).addBox(-2.05F, -6.0F, -2.0F, 4.0F, 12.0F, 7.0F),
|
| 72 | PartPose.offsetAndRotation(0.0F, 4.0F, -12.0F, (float) (Math.PI / 6), 0.0F, 0.0F)
|
| 73 | );
|
| 74 | PartDefinition head = headParts.addOrReplaceChild(
|
| 75 | "head", CubeListBuilder.create().texOffs(0, 13).addBox(-3.0F, -11.0F, -2.0F, 6.0F, 5.0F, 7.0F, g), PartPose.ZERO
|
| 76 | );
|
| 77 | headParts.addOrReplaceChild("mane", CubeListBuilder.create().texOffs(56, 36).addBox(-1.0F, -11.0F, 5.01F, 2.0F, 16.0F, 2.0F, g), PartPose.ZERO);
|
| 78 | headParts.addOrReplaceChild("upper_mouth", CubeListBuilder.create().texOffs(0, 25).addBox(-2.0F, -11.0F, -7.0F, 4.0F, 5.0F, 5.0F, g), PartPose.ZERO);
|
| 79 | root.addOrReplaceChild(
|
| 80 | "left_hind_leg", CubeListBuilder.create().texOffs(48, 21).mirror().addBox(-3.0F, -1.01F, -1.0F, 4.0F, 11.0F, 4.0F, g), PartPose.offset(4.0F, 14.0F, 7.0F)
|
| 81 | );
|
| 82 | root.addOrReplaceChild(
|
| 83 | "right_hind_leg", CubeListBuilder.create().texOffs(48, 21).addBox(-1.0F, -1.01F, -1.0F, 4.0F, 11.0F, 4.0F, g), PartPose.offset(-4.0F, 14.0F, 7.0F)
|
| 84 | );
|
| 85 | root.addOrReplaceChild(
|
| 86 | "left_front_leg", CubeListBuilder.create().texOffs(48, 21).mirror().addBox(-3.0F, -1.01F, -1.9F, 4.0F, 11.0F, 4.0F, g), PartPose.offset(4.0F, 14.0F, -10.0F)
|
| 87 | );
|
| 88 | root.addOrReplaceChild(
|
| 89 | "right_front_leg", CubeListBuilder.create().texOffs(48, 21).addBox(-1.0F, -1.01F, -1.9F, 4.0F, 11.0F, 4.0F, g), PartPose.offset(-4.0F, 14.0F, -10.0F)
|
| 90 | );
|
| 91 | body.addOrReplaceChild(
|
| 92 | "tail",
|
| 93 | CubeListBuilder.create().texOffs(42, 36).addBox(-1.5F, 0.0F, 0.0F, 3.0F, 14.0F, 4.0F, g),
|
| 94 | PartPose.offsetAndRotation(0.0F, -5.0F, 2.0F, (float) (Math.PI / 6), 0.0F, 0.0F)
|
| 95 | );
|
| 96 | head.addOrReplaceChild(
|
| 97 | "left_ear", CubeListBuilder.create().texOffs(19, 16).addBox(0.55F, -13.0F, 4.0F, 2.0F, 3.0F, 1.0F, new CubeDeformation(-0.001F)), PartPose.ZERO
|
| 98 | );
|
| 99 | head.addOrReplaceChild(
|
| 100 | "right_ear", CubeListBuilder.create().texOffs(19, 16).addBox(-2.55F, -13.0F, 4.0F, 2.0F, 3.0F, 1.0F, new CubeDeformation(-0.001F)), PartPose.ZERO
|
| 101 | );
|
| 102 | return mesh;
|
| 103 | }
|
| 104 |
|
| 105 | public void setupAnim(final T state) {
|
| 106 | super.setupAnim(state);
|
| 107 | float clampedYRot = Mth.clamp(state.yRot, -20.0F, 20.0F);
|
| 108 | float headRotXRad = state.xRot * (float) (Math.PI / 180.0);
|
| 109 | float animationSpeed = state.walkAnimationSpeed;
|
| 110 | float animationPos = state.walkAnimationPos;
|
| 111 | if (animationSpeed > 0.2F) {
|
| 112 | headRotXRad += Mth.cos(animationPos * 0.8F) * 0.15F * animationSpeed;
|
| 113 | }
|
| 114 |
|
| 115 | float eating = state.eatAnimation;
|
| 116 | float standing = state.standAnimation;
|
| 117 | float iStanding = 1.0F - standing;
|
| 118 | float feedingAnim = state.feedingAnimation;
|
| 119 | boolean animateTail = state.animateTail;
|
| 120 | this.headParts.xRot = (float) (Math.PI / 6) + headRotXRad;
|
| 121 | this.headParts.yRot = clampedYRot * (float) (Math.PI / 180.0);
|
| 122 | float waterMultiplier = state.isInWater ? 0.2F : 1.0F;
|
| 123 | float legAnim1 = Mth.cos(waterMultiplier * animationPos * 0.6662F + (float) Math.PI);
|
| 124 | float legXRotAnim = legAnim1 * 0.8F * animationSpeed;
|
| 125 | float baseHeadAngle = (1.0F - Math.max(standing, eating)) * ((float) (Math.PI / 6) + headRotXRad + feedingAnim * Mth.sin(state.ageInTicks) * 0.05F);
|
| 126 | this.headParts.xRot = standing * ((float) (Math.PI / 12) + headRotXRad) + eating * (2.1816616F + Mth.sin(state.ageInTicks) * 0.05F) + baseHeadAngle;
|
| 127 | this.headParts.yRot = standing * clampedYRot * (float) (Math.PI / 180.0) + (1.0F - Math.max(standing, eating)) * this.headParts.yRot;
|
| 128 | this.animateHeadPartsPlacement(eating, standing);
|
| 129 | this.body.xRot = standing * (float) (-Math.PI / 4) + iStanding * this.body.xRot;
|
| 130 | this.leftFrontLeg.y = this.leftFrontLeg.y - this.getLegStandingYOffset() * standing;
|
| 131 | this.leftFrontLeg.z = this.leftFrontLeg.z + this.getLegStandingZOffset() * standing;
|
| 132 | this.rightFrontLeg.y = this.leftFrontLeg.y;
|
| 133 | this.rightFrontLeg.z = this.leftFrontLeg.z;
|
| 134 | float standAngle = this.getLegStandAngle() * standing;
|
| 135 | float bobValue = Mth.cos(state.ageInTicks * 0.6F + (float) Math.PI);
|
| 136 | float legStandingXRotOffset = this.getLegStandingXRotOffset();
|
| 137 | float rlegRot = (legStandingXRotOffset + bobValue) * standing + legXRotAnim * iStanding;
|
| 138 | float llegRot = (legStandingXRotOffset - bobValue) * standing - legXRotAnim * iStanding;
|
| 139 | this.leftHindLeg.xRot = standAngle - legAnim1 * 0.5F * animationSpeed * iStanding;
|
| 140 | this.rightHindLeg.xRot = standAngle + legAnim1 * 0.5F * animationSpeed * iStanding;
|
| 141 | this.leftFrontLeg.xRot = rlegRot;
|
| 142 | this.rightFrontLeg.xRot = llegRot;
|
| 143 | this.offsetLegPositionWhenStanding(standing);
|
| 144 | float ageScale = state.ageScale;
|
| 145 | this.tail.xRot = this.getTailXRotOffset() + (float) (Math.PI / 6) + animationSpeed * 0.75F;
|
| 146 | this.tail.y += animationSpeed * ageScale;
|
| 147 | this.tail.z += animationSpeed * 2.0F * ageScale;
|
| 148 | if (animateTail) {
|
| 149 | this.tail.yRot = Mth.cos(state.ageInTicks * 0.7F);
|
| 150 | } else {
|
| 151 | this.tail.yRot = 0.0F;
|
| 152 | }
|
| 153 | }
|
| 154 |
|
| 155 | protected void offsetLegPositionWhenStanding(final float standing) {
|
| 156 | }
|
| 157 |
|
| 158 | protected float getLegStandAngle() {
|
| 159 | return (float) (Math.PI / 12);
|
| 160 | }
|
| 161 |
|
| 162 | protected float getLegStandingYOffset() {
|
| 163 | return 12.0F;
|
| 164 | }
|
| 165 |
|
| 166 | protected float getLegStandingZOffset() {
|
| 167 | return 4.0F;
|
| 168 | }
|
| 169 |
|
| 170 | protected float getLegStandingXRotOffset() {
|
| 171 | return (float) (-Math.PI / 3);
|
| 172 | }
|
| 173 |
|
| 174 | protected float getTailXRotOffset() {
|
| 175 | return 0.0F;
|
| 176 | }
|
| 177 |
|
| 178 | protected void animateHeadPartsPlacement(final float eating, final float standing) {
|
| 179 | this.headParts.y = this.headParts.y + Mth.lerp(eating, Mth.lerp(standing, 0.0F, -8.0F), 7.0F);
|
| 180 | this.headParts.z = Mth.lerp(standing, this.headParts.z, -4.0F);
|
| 181 | }
|
| 182 | }
|
| 183 |
|