| 1 | package net.minecraft.client.model.animal.camel;
|
| 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.CamelRenderState;
|
| 10 | import net.minecraft.util.Mth;
|
| 11 |
|
| 12 | @Environment(EnvType.CLIENT)
|
| 13 | public abstract class CamelModel extends EntityModel<CamelRenderState> {
|
| 14 | private static final float MAX_WALK_ANIMATION_SPEED = 2.0F;
|
| 15 | private static final float WALK_ANIMATION_SCALE_FACTOR = 2.5F;
|
| 16 | protected final ModelPart head;
|
| 17 | private final KeyframeAnimation walkAnimation;
|
| 18 | private final KeyframeAnimation sitAnimation;
|
| 19 | private final KeyframeAnimation sitPoseAnimation;
|
| 20 | private final KeyframeAnimation standupAnimation;
|
| 21 | private final KeyframeAnimation idleAnimation;
|
| 22 | private final KeyframeAnimation dashAnimation;
|
| 23 |
|
| 24 | public CamelModel(
|
| 25 | final ModelPart root,
|
| 26 | final AnimationDefinition walk,
|
| 27 | final AnimationDefinition sit,
|
| 28 | final AnimationDefinition sitPose,
|
| 29 | final AnimationDefinition standup,
|
| 30 | final AnimationDefinition idle,
|
| 31 | final AnimationDefinition dash
|
| 32 | ) {
|
| 33 | super(root);
|
| 34 | ModelPart body = root.getChild("body");
|
| 35 | this.head = body.getChild("head");
|
| 36 | this.walkAnimation = walk.bake(root);
|
| 37 | this.sitAnimation = sit.bake(root);
|
| 38 | this.sitPoseAnimation = sitPose.bake(root);
|
| 39 | this.standupAnimation = standup.bake(root);
|
| 40 | this.idleAnimation = idle.bake(root);
|
| 41 | this.dashAnimation = dash.bake(root);
|
| 42 | }
|
| 43 |
|
| 44 | public void setupAnim(final CamelRenderState state) {
|
| 45 | super.setupAnim(state);
|
| 46 | this.applyHeadRotation(state, state.yRot, state.xRot);
|
| 47 | this.walkAnimation.applyWalk(state.walkAnimationPos, state.walkAnimationSpeed, 2.0F, 2.5F);
|
| 48 | this.sitAnimation.apply(state.sitAnimationState, state.ageInTicks);
|
| 49 | this.sitPoseAnimation.apply(state.sitPoseAnimationState, state.ageInTicks);
|
| 50 | this.standupAnimation.apply(state.sitUpAnimationState, state.ageInTicks);
|
| 51 | this.idleAnimation.apply(state.idleAnimationState, state.ageInTicks);
|
| 52 | this.dashAnimation.apply(state.dashAnimationState, state.ageInTicks);
|
| 53 | }
|
| 54 |
|
| 55 | private void applyHeadRotation(final CamelRenderState state, float yRot, float xRot) {
|
| 56 | yRot = Mth.clamp(yRot, -30.0F, 30.0F);
|
| 57 | xRot = Mth.clamp(xRot, -25.0F, 45.0F);
|
| 58 | if (state.jumpCooldown > 0.0F) {
|
| 59 | float headRotation = 45.0F * state.jumpCooldown / 55.0F;
|
| 60 | xRot = Mth.clamp(xRot + headRotation, -25.0F, 70.0F);
|
| 61 | }
|
| 62 |
|
| 63 | this.head.yRot = yRot * (float) (Math.PI / 180.0);
|
| 64 | this.head.xRot = xRot * (float) (Math.PI / 180.0);
|
| 65 | }
|
| 66 | }
|
| 67 |
|