| 1 | package net.minecraft.client.model.animal.panda;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.model.QuadrupedModel;
|
| 6 | import net.minecraft.client.model.geom.ModelPart;
|
| 7 | import net.minecraft.client.model.geom.PartPose;
|
| 8 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 9 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 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.PandaRenderState;
|
| 13 | import net.minecraft.util.Mth;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class PandaModel extends QuadrupedModel<PandaRenderState> {
|
| 17 | public PandaModel(final ModelPart root) {
|
| 18 | super(root);
|
| 19 | }
|
| 20 |
|
| 21 | public static LayerDefinition createBodyLayer() {
|
| 22 | MeshDefinition mesh = new MeshDefinition();
|
| 23 | PartDefinition root = mesh.getRoot();
|
| 24 | root.addOrReplaceChild(
|
| 25 | "head",
|
| 26 | CubeListBuilder.create()
|
| 27 | .texOffs(0, 6)
|
| 28 | .addBox(-6.5F, -5.0F, -4.0F, 13.0F, 10.0F, 9.0F)
|
| 29 | .texOffs(45, 16)
|
| 30 | .addBox("nose", -3.5F, 0.0F, -6.0F, 7.0F, 5.0F, 2.0F)
|
| 31 | .texOffs(52, 25)
|
| 32 | .addBox("left_ear", 3.5F, -8.0F, -1.0F, 5.0F, 4.0F, 1.0F)
|
| 33 | .texOffs(52, 25)
|
| 34 | .addBox("right_ear", -8.5F, -8.0F, -1.0F, 5.0F, 4.0F, 1.0F),
|
| 35 | PartPose.offset(0.0F, 11.5F, -17.0F)
|
| 36 | );
|
| 37 | root.addOrReplaceChild(
|
| 38 | "body",
|
| 39 | CubeListBuilder.create().texOffs(0, 25).addBox(-9.5F, -13.0F, -6.5F, 19.0F, 26.0F, 13.0F),
|
| 40 | PartPose.offsetAndRotation(0.0F, 10.0F, 0.0F, (float) (Math.PI / 2), 0.0F, 0.0F)
|
| 41 | );
|
| 42 | int legH = 9;
|
| 43 | int legW = 6;
|
| 44 | CubeListBuilder leg = CubeListBuilder.create().texOffs(40, 0).addBox(-3.0F, 0.0F, -3.0F, 6.0F, 9.0F, 6.0F);
|
| 45 | root.addOrReplaceChild("right_hind_leg", leg, PartPose.offset(-5.5F, 15.0F, 9.0F));
|
| 46 | root.addOrReplaceChild("left_hind_leg", leg, PartPose.offset(5.5F, 15.0F, 9.0F));
|
| 47 | root.addOrReplaceChild("right_front_leg", leg, PartPose.offset(-5.5F, 15.0F, -9.0F));
|
| 48 | root.addOrReplaceChild("left_front_leg", leg, PartPose.offset(5.5F, 15.0F, -9.0F));
|
| 49 | return LayerDefinition.create(mesh, 64, 64);
|
| 50 | }
|
| 51 |
|
| 52 | public void setupAnim(final PandaRenderState state) {
|
| 53 | super.setupAnim(state);
|
| 54 | if (state.isUnhappy) {
|
| 55 | this.head.yRot = 0.35F * Mth.sin(0.6F * state.ageInTicks);
|
| 56 | this.head.zRot = 0.35F * Mth.sin(0.6F * state.ageInTicks);
|
| 57 | this.rightFrontLeg.xRot = -0.75F * Mth.sin(0.3F * state.ageInTicks);
|
| 58 | this.leftFrontLeg.xRot = 0.75F * Mth.sin(0.3F * state.ageInTicks);
|
| 59 | } else {
|
| 60 | this.head.zRot = 0.0F;
|
| 61 | }
|
| 62 |
|
| 63 | if (state.isSneezing) {
|
| 64 | if (state.sneezeTime < 15) {
|
| 65 | this.head.xRot = (float) (-Math.PI / 4) * state.sneezeTime / 14.0F;
|
| 66 | } else if (state.sneezeTime < 20) {
|
| 67 | float internalSneezePos = (state.sneezeTime - 15) / 5;
|
| 68 | this.head.xRot = (float) (-Math.PI / 4) + (float) (Math.PI / 4) * internalSneezePos;
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | if (state.sitAmount > 0.0F) {
|
| 73 | this.animateSitting(state);
|
| 74 | if (state.isEating) {
|
| 75 | this.head.xRot = (float) (Math.PI / 2) + 0.2F * Mth.sin(state.ageInTicks * 0.6F);
|
| 76 | this.rightFrontLeg.xRot = -0.4F - 0.2F * Mth.sin(state.ageInTicks * 0.6F);
|
| 77 | this.leftFrontLeg.xRot = -0.4F - 0.2F * Mth.sin(state.ageInTicks * 0.6F);
|
| 78 | }
|
| 79 |
|
| 80 | if (state.isScared) {
|
| 81 | this.head.xRot = 2.1707964F;
|
| 82 | this.rightFrontLeg.xRot = -0.9F;
|
| 83 | this.leftFrontLeg.xRot = -0.9F;
|
| 84 | }
|
| 85 | } else {
|
| 86 | this.rightHindLeg.zRot = 0.0F;
|
| 87 | this.leftHindLeg.zRot = 0.0F;
|
| 88 | this.rightFrontLeg.zRot = 0.0F;
|
| 89 | this.leftFrontLeg.zRot = 0.0F;
|
| 90 | }
|
| 91 |
|
| 92 | if (state.lieOnBackAmount > 0.0F) {
|
| 93 | this.rightHindLeg.xRot = -0.6F * Mth.sin(state.ageInTicks * 0.15F);
|
| 94 | this.leftHindLeg.xRot = 0.6F * Mth.sin(state.ageInTicks * 0.15F);
|
| 95 | this.rightFrontLeg.xRot = 0.3F * Mth.sin(state.ageInTicks * 0.25F);
|
| 96 | this.leftFrontLeg.xRot = -0.3F * Mth.sin(state.ageInTicks * 0.25F);
|
| 97 | this.head.xRot = Mth.rotLerpRad(state.lieOnBackAmount, this.head.xRot, (float) (Math.PI / 2));
|
| 98 | }
|
| 99 |
|
| 100 | if (state.rollAmount > 0.0F) {
|
| 101 | this.head.xRot = Mth.rotLerpRad(state.rollAmount, this.head.xRot, 2.0561945F);
|
| 102 | this.rightHindLeg.xRot = -0.5F * Mth.sin(state.ageInTicks * 0.5F);
|
| 103 | this.leftHindLeg.xRot = 0.5F * Mth.sin(state.ageInTicks * 0.5F);
|
| 104 | this.rightFrontLeg.xRot = 0.5F * Mth.sin(state.ageInTicks * 0.5F);
|
| 105 | this.leftFrontLeg.xRot = -0.5F * Mth.sin(state.ageInTicks * 0.5F);
|
| 106 | }
|
| 107 | }
|
| 108 |
|
| 109 | protected void animateSitting(final PandaRenderState state) {
|
| 110 | this.body.xRot = Mth.rotLerpRad(state.sitAmount, this.body.xRot, 1.7407963F);
|
| 111 | this.head.xRot = Mth.rotLerpRad(state.sitAmount, this.head.xRot, (float) (Math.PI / 2));
|
| 112 | this.rightFrontLeg.zRot = -0.27079642F;
|
| 113 | this.leftFrontLeg.zRot = 0.27079642F;
|
| 114 | this.rightHindLeg.zRot = 0.5707964F;
|
| 115 | this.leftHindLeg.zRot = -0.5707964F;
|
| 116 | }
|
| 117 | }
|
| 118 |
|