| 1 | package net.minecraft.client.model.animal.armadillo;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.animation.AnimationDefinition;
|
| 6 | import net.minecraft.client.animation.KeyframeAnimation;
|
| 7 | import net.minecraft.client.model.EntityModel;
|
| 8 | import net.minecraft.client.model.geom.ModelPart;
|
| 9 | import net.minecraft.client.renderer.entity.state.ArmadilloRenderState;
|
| 10 | import net.minecraft.util.Mth;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public abstract class ArmadilloModel extends EntityModel<ArmadilloRenderState> {
|
| 14 | private static final float MAX_DOWN_HEAD_ROTATION_EXTENT = 25.0F;
|
| 15 | private static final float MAX_UP_HEAD_ROTATION_EXTENT = 22.5F;
|
| 16 | private static final float MAX_WALK_ANIMATION_SPEED = 16.5F;
|
| 17 | private static final float WALK_ANIMATION_SCALE_FACTOR = 2.5F;
|
| 18 | protected static final String HEAD_CUBE = "head_cube";
|
| 19 | protected static final String RIGHT_EAR_CUBE = "right_ear_cube";
|
| 20 | protected static final String LEFT_EAR_CUBE = "left_ear_cube";
|
| 21 | private final ModelPart body;
|
| 22 | private final ModelPart rightHindLeg;
|
| 23 | private final ModelPart leftHindLeg;
|
| 24 | private final ModelPart cube;
|
| 25 | private final ModelPart head;
|
| 26 | private final ModelPart tail;
|
| 27 | private final KeyframeAnimation walkAnimation;
|
| 28 | private final KeyframeAnimation rollOutAnimation;
|
| 29 | private final KeyframeAnimation rollUpAnimation;
|
| 30 | private final KeyframeAnimation peekAnimation;
|
| 31 |
|
| 32 | public ArmadilloModel(
|
| 33 | final ModelPart root, final AnimationDefinition walk, final AnimationDefinition rollOut, final AnimationDefinition rollUp, final AnimationDefinition peek
|
| 34 | ) {
|
| 35 | super(root);
|
| 36 | this.body = root.getChild("body");
|
| 37 | this.rightHindLeg = root.getChild("right_hind_leg");
|
| 38 | this.leftHindLeg = root.getChild("left_hind_leg");
|
| 39 | this.head = this.body.getChild("head");
|
| 40 | this.tail = this.body.getChild("tail");
|
| 41 | this.cube = root.getChild("cube");
|
| 42 | this.walkAnimation = walk.bake(root);
|
| 43 | this.rollOutAnimation = rollOut.bake(root);
|
| 44 | this.rollUpAnimation = rollUp.bake(root);
|
| 45 | this.peekAnimation = peek.bake(root);
|
| 46 | }
|
| 47 |
|
| 48 | public void setupAnim(final ArmadilloRenderState state) {
|
| 49 | super.setupAnim(state);
|
| 50 | if (state.isHidingInShell) {
|
| 51 | this.body.skipDraw = true;
|
| 52 | this.leftHindLeg.visible = false;
|
| 53 | this.rightHindLeg.visible = false;
|
| 54 | this.tail.visible = false;
|
| 55 | this.cube.visible = true;
|
| 56 | } else {
|
| 57 | this.body.skipDraw = false;
|
| 58 | this.leftHindLeg.visible = true;
|
| 59 | this.rightHindLeg.visible = true;
|
| 60 | this.tail.visible = true;
|
| 61 | this.cube.visible = false;
|
| 62 | this.head.xRot = Mth.clamp(state.xRot, -22.5F, 25.0F) * (float) (Math.PI / 180.0);
|
| 63 | this.head.yRot = Mth.clamp(state.yRot, -32.5F, 32.5F) * (float) (Math.PI / 180.0);
|
| 64 | }
|
| 65 |
|
| 66 | if (!state.isHidingInShell) {
|
| 67 | this.walkAnimation.applyWalk(state.walkAnimationPos, state.walkAnimationSpeed, 16.5F, 2.5F);
|
| 68 | }
|
| 69 |
|
| 70 | this.rollOutAnimation.apply(state.rollOutAnimationState, state.ageInTicks);
|
| 71 | this.rollUpAnimation.apply(state.rollUpAnimationState, state.ageInTicks);
|
| 72 | this.peekAnimation.apply(state.peekAnimationState, state.ageInTicks);
|
| 73 | }
|
| 74 | }
|
| 75 |
|