| 1 | package net.minecraft.client.model.animal.frog;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.animation.KeyframeAnimation;
|
| 6 | import net.minecraft.client.animation.definitions.FrogAnimation;
|
| 7 | import net.minecraft.client.model.EntityModel;
|
| 8 | import net.minecraft.client.model.geom.ModelPart;
|
| 9 | import net.minecraft.client.model.geom.PartPose;
|
| 10 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 11 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 12 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 13 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 14 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 15 | import net.minecraft.client.renderer.entity.state.FrogRenderState;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class FrogModel extends EntityModel<FrogRenderState> {
|
| 19 | private static final float MAX_WALK_ANIMATION_SPEED = 1.5F;
|
| 20 | private static final float MAX_SWIM_ANIMATION_SPEED = 1.0F;
|
| 21 | private static final float WALK_ANIMATION_SCALE_FACTOR = 2.5F;
|
| 22 | private final ModelPart body = this.root.getChild("body");
|
| 23 | private final ModelPart head = this.body.getChild("head");
|
| 24 | private final ModelPart eyes = this.head.getChild("eyes");
|
| 25 | private final ModelPart tongue = this.body.getChild("tongue");
|
| 26 | private final ModelPart leftArm = this.body.getChild("left_arm");
|
| 27 | private final ModelPart rightArm = this.body.getChild("right_arm");
|
| 28 | private final ModelPart leftLeg = this.root.getChild("left_leg");
|
| 29 | private final ModelPart rightLeg = this.root.getChild("right_leg");
|
| 30 | private final ModelPart croakingBody = this.body.getChild("croaking_body");
|
| 31 | private final KeyframeAnimation jumpAnimation;
|
| 32 | private final KeyframeAnimation croakAnimation;
|
| 33 | private final KeyframeAnimation tongueAnimation;
|
| 34 | private final KeyframeAnimation swimAnimation;
|
| 35 | private final KeyframeAnimation walkAnimation;
|
| 36 | private final KeyframeAnimation idleWaterAnimation;
|
| 37 |
|
| 38 | public FrogModel(final ModelPart root) {
|
| 39 | super(root.getChild("root"));
|
| 40 | this.jumpAnimation = FrogAnimation.FROG_JUMP.bake(root);
|
| 41 | this.croakAnimation = FrogAnimation.FROG_CROAK.bake(root);
|
| 42 | this.tongueAnimation = FrogAnimation.FROG_TONGUE.bake(root);
|
| 43 | this.swimAnimation = FrogAnimation.FROG_SWIM.bake(root);
|
| 44 | this.walkAnimation = FrogAnimation.FROG_WALK.bake(root);
|
| 45 | this.idleWaterAnimation = FrogAnimation.FROG_IDLE_WATER.bake(root);
|
| 46 | }
|
| 47 |
|
| 48 | public static LayerDefinition createBodyLayer() {
|
| 49 | MeshDefinition mesh = new MeshDefinition();
|
| 50 | PartDefinition root = mesh.getRoot();
|
| 51 | PartDefinition modelRoot = root.addOrReplaceChild("root", CubeListBuilder.create(), PartPose.offset(0.0F, 24.0F, 0.0F));
|
| 52 | PartDefinition body = modelRoot.addOrReplaceChild(
|
| 53 | "body",
|
| 54 | CubeListBuilder.create().texOffs(3, 1).addBox(-3.5F, -2.0F, -8.0F, 7.0F, 3.0F, 9.0F).texOffs(23, 22).addBox(-3.5F, -1.0F, -8.0F, 7.0F, 0.0F, 9.0F),
|
| 55 | PartPose.offset(0.0F, -2.0F, 4.0F)
|
| 56 | );
|
| 57 | PartDefinition head = body.addOrReplaceChild(
|
| 58 | "head",
|
| 59 | CubeListBuilder.create().texOffs(23, 13).addBox(-3.5F, -1.0F, -7.0F, 7.0F, 0.0F, 9.0F).texOffs(0, 13).addBox(-3.5F, -2.0F, -7.0F, 7.0F, 3.0F, 9.0F),
|
| 60 | PartPose.offset(0.0F, -2.0F, -1.0F)
|
| 61 | );
|
| 62 | PartDefinition eyes = head.addOrReplaceChild("eyes", CubeListBuilder.create(), PartPose.offset(-0.5F, 0.0F, 2.0F));
|
| 63 | eyes.addOrReplaceChild(
|
| 64 | "right_eye", CubeListBuilder.create().texOffs(0, 0).addBox(-1.5F, -1.0F, -1.5F, 3.0F, 2.0F, 3.0F), PartPose.offset(-1.5F, -3.0F, -6.5F)
|
| 65 | );
|
| 66 | eyes.addOrReplaceChild("left_eye", CubeListBuilder.create().texOffs(0, 5).addBox(-1.5F, -1.0F, -1.5F, 3.0F, 2.0F, 3.0F), PartPose.offset(2.5F, -3.0F, -6.5F));
|
| 67 | body.addOrReplaceChild(
|
| 68 | "croaking_body",
|
| 69 | CubeListBuilder.create().texOffs(26, 5).addBox(-3.5F, -0.1F, -2.9F, 7.0F, 2.0F, 3.0F, new CubeDeformation(-0.1F)),
|
| 70 | PartPose.offset(0.0F, -1.0F, -5.0F)
|
| 71 | );
|
| 72 | PartDefinition tongue = body.addOrReplaceChild(
|
| 73 | "tongue", CubeListBuilder.create().texOffs(17, 13).addBox(-2.0F, 0.0F, -7.1F, 4.0F, 0.0F, 7.0F), PartPose.offset(0.0F, -1.01F, 1.0F)
|
| 74 | );
|
| 75 | PartDefinition leftArm = body.addOrReplaceChild(
|
| 76 | "left_arm", CubeListBuilder.create().texOffs(0, 32).addBox(-1.0F, 0.0F, -1.0F, 2.0F, 3.0F, 3.0F), PartPose.offset(4.0F, -1.0F, -6.5F)
|
| 77 | );
|
| 78 | leftArm.addOrReplaceChild(
|
| 79 | "left_hand", CubeListBuilder.create().texOffs(18, 40).addBox(-4.0F, 0.01F, -4.0F, 8.0F, 0.0F, 8.0F), PartPose.offset(0.0F, 3.0F, -1.0F)
|
| 80 | );
|
| 81 | PartDefinition rightArm = body.addOrReplaceChild(
|
| 82 | "right_arm", CubeListBuilder.create().texOffs(0, 38).addBox(-1.0F, 0.0F, -1.0F, 2.0F, 3.0F, 3.0F), PartPose.offset(-4.0F, -1.0F, -6.5F)
|
| 83 | );
|
| 84 | rightArm.addOrReplaceChild(
|
| 85 | "right_hand", CubeListBuilder.create().texOffs(2, 40).addBox(-4.0F, 0.01F, -5.0F, 8.0F, 0.0F, 8.0F), PartPose.offset(0.0F, 3.0F, 0.0F)
|
| 86 | );
|
| 87 | PartDefinition leftLeg = modelRoot.addOrReplaceChild(
|
| 88 | "left_leg", CubeListBuilder.create().texOffs(14, 25).addBox(-1.0F, 0.0F, -2.0F, 3.0F, 3.0F, 4.0F), PartPose.offset(3.5F, -3.0F, 4.0F)
|
| 89 | );
|
| 90 | leftLeg.addOrReplaceChild(
|
| 91 | "left_foot", CubeListBuilder.create().texOffs(2, 32).addBox(-4.0F, 0.01F, -4.0F, 8.0F, 0.0F, 8.0F), PartPose.offset(2.0F, 3.0F, 0.0F)
|
| 92 | );
|
| 93 | PartDefinition rightLeg = modelRoot.addOrReplaceChild(
|
| 94 | "right_leg", CubeListBuilder.create().texOffs(0, 25).addBox(-2.0F, 0.0F, -2.0F, 3.0F, 3.0F, 4.0F), PartPose.offset(-3.5F, -3.0F, 4.0F)
|
| 95 | );
|
| 96 | rightLeg.addOrReplaceChild(
|
| 97 | "right_foot", CubeListBuilder.create().texOffs(18, 32).addBox(-4.0F, 0.01F, -4.0F, 8.0F, 0.0F, 8.0F), PartPose.offset(-2.0F, 3.0F, 0.0F)
|
| 98 | );
|
| 99 | return LayerDefinition.create(mesh, 48, 48);
|
| 100 | }
|
| 101 |
|
| 102 | public void setupAnim(final FrogRenderState state) {
|
| 103 | super.setupAnim(state);
|
| 104 | this.jumpAnimation.apply(state.jumpAnimationState, state.ageInTicks);
|
| 105 | this.croakAnimation.apply(state.croakAnimationState, state.ageInTicks);
|
| 106 | this.tongueAnimation.apply(state.tongueAnimationState, state.ageInTicks);
|
| 107 | if (state.isSwimming) {
|
| 108 | this.swimAnimation.applyWalk(state.walkAnimationPos, state.walkAnimationSpeed, 1.0F, 2.5F);
|
| 109 | } else {
|
| 110 | this.walkAnimation.applyWalk(state.walkAnimationPos, state.walkAnimationSpeed, 1.5F, 2.5F);
|
| 111 | }
|
| 112 |
|
| 113 | this.idleWaterAnimation.apply(state.swimIdleAnimationState, state.ageInTicks);
|
| 114 | this.croakingBody.visible = state.croakAnimationState.isStarted();
|
| 115 | }
|
| 116 | }
|
| 117 |
|