| 1 | package net.minecraft.client.model.animal.axolotl;
|
| 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.LayerDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 12 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 13 | import net.minecraft.client.renderer.entity.state.AxolotlRenderState;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class AdultAxolotlModel extends EntityModel<AxolotlRenderState> {
|
| 18 | private static final float SWIMMING_LEG_XROT = 1.8849558F;
|
| 19 | private final ModelPart tail;
|
| 20 | private final ModelPart leftHindLeg;
|
| 21 | private final ModelPart rightHindLeg;
|
| 22 | private final ModelPart leftFrontLeg;
|
| 23 | private final ModelPart rightFrontLeg;
|
| 24 | private final ModelPart body;
|
| 25 | private final ModelPart head;
|
| 26 | private final ModelPart topGills;
|
| 27 | private final ModelPart leftGills;
|
| 28 | private final ModelPart rightGills;
|
| 29 |
|
| 30 | public AdultAxolotlModel(final ModelPart root) {
|
| 31 | super(root);
|
| 32 | this.body = root.getChild("body");
|
| 33 | this.head = this.body.getChild("head");
|
| 34 | this.rightHindLeg = this.body.getChild("right_hind_leg");
|
| 35 | this.leftHindLeg = this.body.getChild("left_hind_leg");
|
| 36 | this.rightFrontLeg = this.body.getChild("right_front_leg");
|
| 37 | this.leftFrontLeg = this.body.getChild("left_front_leg");
|
| 38 | this.tail = this.body.getChild("tail");
|
| 39 | this.topGills = this.head.getChild("top_gills");
|
| 40 | this.leftGills = this.head.getChild("left_gills");
|
| 41 | this.rightGills = this.head.getChild("right_gills");
|
| 42 | }
|
| 43 |
|
| 44 | public static LayerDefinition createBodyLayer() {
|
| 45 | MeshDefinition mesh = new MeshDefinition();
|
| 46 | PartDefinition root = mesh.getRoot();
|
| 47 | PartDefinition body = root.addOrReplaceChild(
|
| 48 | "body",
|
| 49 | CubeListBuilder.create().texOffs(0, 11).addBox(-4.0F, -2.0F, -9.0F, 8.0F, 4.0F, 10.0F).texOffs(2, 17).addBox(0.0F, -3.0F, -8.0F, 0.0F, 5.0F, 9.0F),
|
| 50 | PartPose.offset(0.0F, 19.5F, 5.0F)
|
| 51 | );
|
| 52 | CubeDeformation fudge = new CubeDeformation(0.001F);
|
| 53 | PartDefinition head = body.addOrReplaceChild(
|
| 54 | "head", CubeListBuilder.create().texOffs(0, 1).addBox(-4.0F, -3.0F, -5.0F, 8.0F, 5.0F, 5.0F, fudge), PartPose.offset(0.0F, 0.0F, -9.0F)
|
| 55 | );
|
| 56 | CubeListBuilder topGills = CubeListBuilder.create().texOffs(3, 37).addBox(-4.0F, -3.0F, 0.0F, 8.0F, 3.0F, 0.0F, fudge);
|
| 57 | CubeListBuilder leftGills = CubeListBuilder.create().texOffs(0, 40).addBox(-3.0F, -5.0F, 0.0F, 3.0F, 7.0F, 0.0F, fudge);
|
| 58 | CubeListBuilder rightGills = CubeListBuilder.create().texOffs(11, 40).addBox(0.0F, -5.0F, 0.0F, 3.0F, 7.0F, 0.0F, fudge);
|
| 59 | head.addOrReplaceChild("top_gills", topGills, PartPose.offset(0.0F, -3.0F, -1.0F));
|
| 60 | head.addOrReplaceChild("left_gills", leftGills, PartPose.offset(-4.0F, 0.0F, -1.0F));
|
| 61 | head.addOrReplaceChild("right_gills", rightGills, PartPose.offset(4.0F, 0.0F, -1.0F));
|
| 62 | CubeListBuilder leftLeg = CubeListBuilder.create().texOffs(2, 13).addBox(-1.0F, 0.0F, 0.0F, 3.0F, 5.0F, 0.0F, fudge);
|
| 63 | CubeListBuilder rightLeg = CubeListBuilder.create().texOffs(2, 13).addBox(-2.0F, 0.0F, 0.0F, 3.0F, 5.0F, 0.0F, fudge);
|
| 64 | body.addOrReplaceChild("right_hind_leg", rightLeg, PartPose.offset(-3.5F, 1.0F, -1.0F));
|
| 65 | body.addOrReplaceChild("left_hind_leg", leftLeg, PartPose.offset(3.5F, 1.0F, -1.0F));
|
| 66 | body.addOrReplaceChild("right_front_leg", rightLeg, PartPose.offset(-3.5F, 1.0F, -8.0F));
|
| 67 | body.addOrReplaceChild("left_front_leg", leftLeg, PartPose.offset(3.5F, 1.0F, -8.0F));
|
| 68 | body.addOrReplaceChild("tail", CubeListBuilder.create().texOffs(2, 19).addBox(0.0F, -3.0F, 0.0F, 0.0F, 5.0F, 12.0F), PartPose.offset(0.0F, 0.0F, 1.0F));
|
| 69 | return LayerDefinition.create(mesh, 64, 64);
|
| 70 | }
|
| 71 |
|
| 72 | public void setupAnim(final AxolotlRenderState state) {
|
| 73 | super.setupAnim(state);
|
| 74 | float playingDeadFactor = state.playingDeadFactor;
|
| 75 | float inWaterFactor = state.inWaterFactor;
|
| 76 | float onGroundFactor = state.onGroundFactor;
|
| 77 | float movingFactor = state.movingFactor;
|
| 78 | float notMovingFactor = 1.0F - movingFactor;
|
| 79 | float mirroredLegsFactor = 1.0F - Math.min(onGroundFactor, movingFactor);
|
| 80 | this.body.yRot = this.body.yRot + state.yRot * (float) (Math.PI / 180.0);
|
| 81 | this.setupSwimmingAnimation(state.ageInTicks, state.xRot, Math.min(movingFactor, inWaterFactor));
|
| 82 | this.setupWaterHoveringAnimation(state.ageInTicks, Math.min(notMovingFactor, inWaterFactor));
|
| 83 | this.setupGroundCrawlingAnimation(state.ageInTicks, Math.min(movingFactor, onGroundFactor));
|
| 84 | this.setupLayStillOnGroundAnimation(state.ageInTicks, Math.min(notMovingFactor, onGroundFactor));
|
| 85 | this.setupPlayDeadAnimation(playingDeadFactor);
|
| 86 | this.applyMirrorLegRotations(mirroredLegsFactor);
|
| 87 | }
|
| 88 |
|
| 89 | private void setupLayStillOnGroundAnimation(final float ageInTicks, final float factor) {
|
| 90 | if (!(factor <= 1.0E-5F)) {
|
| 91 | float animMoveSpeed = ageInTicks * 0.09F;
|
| 92 | float sineSway = Mth.sin(animMoveSpeed);
|
| 93 | float cosineSway = Mth.cos(animMoveSpeed);
|
| 94 | float movement = sineSway * sineSway - 2.0F * sineSway;
|
| 95 | float movement2 = cosineSway * cosineSway - 3.0F * sineSway;
|
| 96 | this.head.xRot += -0.09F * movement * factor;
|
| 97 | this.head.zRot += -0.2F * factor;
|
| 98 | this.tail.yRot += (-0.1F + 0.1F * movement) * factor;
|
| 99 | float gillAngle = (0.6F + 0.05F * movement2) * factor;
|
| 100 | this.topGills.xRot += gillAngle;
|
| 101 | this.leftGills.yRot -= gillAngle;
|
| 102 | this.rightGills.yRot += gillAngle;
|
| 103 | this.leftHindLeg.xRot += 1.1F * factor;
|
| 104 | this.leftHindLeg.yRot += 1.0F * factor;
|
| 105 | this.leftFrontLeg.xRot += 0.8F * factor;
|
| 106 | this.leftFrontLeg.yRot += 2.3F * factor;
|
| 107 | this.leftFrontLeg.zRot -= 0.5F * factor;
|
| 108 | }
|
| 109 | }
|
| 110 |
|
| 111 | private void setupGroundCrawlingAnimation(final float ageInTicks, final float factor) {
|
| 112 | if (!(factor <= 1.0E-5F)) {
|
| 113 | float animMoveSpeed = ageInTicks * 0.11F;
|
| 114 | float cosineSway = Mth.cos(animMoveSpeed);
|
| 115 | float hindLegYRotSway = (cosineSway * cosineSway - 2.0F * cosineSway) / 5.0F;
|
| 116 | float frontLegYRotSway = 0.7F * cosineSway;
|
| 117 | float headAndTailYRot = 0.09F * cosineSway * factor;
|
| 118 | this.head.yRot += headAndTailYRot;
|
| 119 | this.tail.yRot += headAndTailYRot;
|
| 120 | float gillAngle = (0.6F - 0.08F * (cosineSway * cosineSway + 2.0F * Mth.sin(animMoveSpeed))) * factor;
|
| 121 | this.topGills.xRot += gillAngle;
|
| 122 | this.leftGills.yRot -= gillAngle;
|
| 123 | this.rightGills.yRot += gillAngle;
|
| 124 | float hindLegXRot = 0.9424779F * factor;
|
| 125 | float frontLegXRot = 1.0995574F * factor;
|
| 126 | this.leftHindLeg.xRot += hindLegXRot;
|
| 127 | this.leftHindLeg.yRot += (1.5F - hindLegYRotSway) * factor;
|
| 128 | this.leftHindLeg.zRot += -0.1F * factor;
|
| 129 | this.leftFrontLeg.xRot += frontLegXRot;
|
| 130 | this.leftFrontLeg.yRot += ((float) (Math.PI / 2) - frontLegYRotSway) * factor;
|
| 131 | this.rightHindLeg.xRot += hindLegXRot;
|
| 132 | this.rightHindLeg.yRot += (-1.0F - hindLegYRotSway) * factor;
|
| 133 | this.rightFrontLeg.xRot += frontLegXRot;
|
| 134 | this.rightFrontLeg.yRot += ((float) (-Math.PI / 2) - frontLegYRotSway) * factor;
|
| 135 | }
|
| 136 | }
|
| 137 |
|
| 138 | private void setupWaterHoveringAnimation(final float ageInTicks, final float factor) {
|
| 139 | if (!(factor <= 1.0E-5F)) {
|
| 140 | float animMoveSpeed = ageInTicks * 0.075F;
|
| 141 | float cosineSway = Mth.cos(animMoveSpeed);
|
| 142 | float sineSway = Mth.sin(animMoveSpeed) * 0.15F;
|
| 143 | float bodyXRot = (-0.15F + 0.075F * cosineSway) * factor;
|
| 144 | this.body.xRot += bodyXRot;
|
| 145 | this.body.y -= sineSway * factor;
|
| 146 | this.head.xRot -= bodyXRot;
|
| 147 | this.topGills.xRot += 0.2F * cosineSway * factor;
|
| 148 | float gillYRot = (-0.3F * cosineSway - 0.19F) * factor;
|
| 149 | this.leftGills.yRot += gillYRot;
|
| 150 | this.rightGills.yRot -= gillYRot;
|
| 151 | this.leftHindLeg.xRot += ((float) (Math.PI * 3.0 / 4.0) - cosineSway * 0.11F) * factor;
|
| 152 | this.leftHindLeg.yRot += 0.47123894F * factor;
|
| 153 | this.leftHindLeg.zRot += 1.7278761F * factor;
|
| 154 | this.leftFrontLeg.xRot += ((float) (Math.PI / 4) - cosineSway * 0.2F) * factor;
|
| 155 | this.leftFrontLeg.yRot += 2.042035F * factor;
|
| 156 | this.tail.yRot += 0.5F * cosineSway * factor;
|
| 157 | }
|
| 158 | }
|
| 159 |
|
| 160 | private void setupSwimmingAnimation(final float ageInTicks, final float xRot, final float factor) {
|
| 161 | if (!(factor <= 1.0E-5F)) {
|
| 162 | float animMoveSpeed = ageInTicks * 0.33F;
|
| 163 | float sineSway = Mth.sin(animMoveSpeed);
|
| 164 | float cosineSway = Mth.cos(animMoveSpeed);
|
| 165 | float bodySway = 0.13F * sineSway;
|
| 166 | this.body.xRot += (xRot * (float) (Math.PI / 180.0) + bodySway) * factor;
|
| 167 | this.head.xRot -= bodySway * 1.8F * factor;
|
| 168 | this.body.y -= 0.45F * cosineSway * factor;
|
| 169 | this.topGills.xRot += (-0.5F * sineSway - 0.8F) * factor;
|
| 170 | float gillYRot = (0.3F * sineSway + 0.9F) * factor;
|
| 171 | this.leftGills.yRot += gillYRot;
|
| 172 | this.rightGills.yRot -= gillYRot;
|
| 173 | this.tail.yRot = this.tail.yRot + 0.3F * Mth.cos(animMoveSpeed * 0.9F) * factor;
|
| 174 | this.leftHindLeg.xRot += 1.8849558F * factor;
|
| 175 | this.leftHindLeg.yRot += -0.4F * sineSway * factor;
|
| 176 | this.leftHindLeg.zRot += (float) (Math.PI / 2) * factor;
|
| 177 | this.leftFrontLeg.xRot += 1.8849558F * factor;
|
| 178 | this.leftFrontLeg.yRot += (-0.2F * cosineSway - 0.1F) * factor;
|
| 179 | this.leftFrontLeg.zRot += (float) (Math.PI / 2) * factor;
|
| 180 | }
|
| 181 | }
|
| 182 |
|
| 183 | private void setupPlayDeadAnimation(final float factor) {
|
| 184 | if (!(factor <= 1.0E-5F)) {
|
| 185 | this.leftHindLeg.xRot += 1.4137167F * factor;
|
| 186 | this.leftHindLeg.yRot += 1.0995574F * factor;
|
| 187 | this.leftHindLeg.zRot += (float) (Math.PI / 4) * factor;
|
| 188 | this.leftFrontLeg.xRot += (float) (Math.PI / 4) * factor;
|
| 189 | this.leftFrontLeg.yRot += 2.042035F * factor;
|
| 190 | this.body.xRot += -0.15F * factor;
|
| 191 | this.body.zRot += 0.35F * factor;
|
| 192 | }
|
| 193 | }
|
| 194 |
|
| 195 | private void applyMirrorLegRotations(final float factor) {
|
| 196 | if (!(factor <= 1.0E-5F)) {
|
| 197 | this.rightHindLeg.xRot = this.rightHindLeg.xRot + this.leftHindLeg.xRot * factor;
|
| 198 | ModelPart var2 = this.rightHindLeg;
|
| 199 | var2.yRot = var2.yRot + -this.leftHindLeg.yRot * factor;
|
| 200 | var2 = this.rightHindLeg;
|
| 201 | var2.zRot = var2.zRot + -this.leftHindLeg.zRot * factor;
|
| 202 | this.rightFrontLeg.xRot = this.rightFrontLeg.xRot + this.leftFrontLeg.xRot * factor;
|
| 203 | var2 = this.rightFrontLeg;
|
| 204 | var2.yRot = var2.yRot + -this.leftFrontLeg.yRot * factor;
|
| 205 | var2 = this.rightFrontLeg;
|
| 206 | var2.zRot = var2.zRot + -this.leftFrontLeg.zRot * factor;
|
| 207 | }
|
| 208 | }
|
| 209 | }
|
| 210 |
|