| 1 | package net.minecraft.client.model.animal.nautilus;
|
| 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.NautilusAnimation;
|
| 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.NautilusRenderState;
|
| 16 | import net.minecraft.util.Mth;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class NautilusModel extends EntityModel<NautilusRenderState> {
|
| 20 | private static final float SWIM_ANIMATION_SPEED_MAX = 2.0F;
|
| 21 | private static final float SWIM_ANIMATION_SCALE_FACTOR = 3.0F;
|
| 22 | private static final float IDLE_SWIM_ANIMATION_SPEED = 0.2F;
|
| 23 | private static final float IDLE_SWIM_ANIMATION_SCALE = 5.0F;
|
| 24 | protected final ModelPart body;
|
| 25 | protected final ModelPart nautilus;
|
| 26 | private final KeyframeAnimation swimAnimation;
|
| 27 |
|
| 28 | public NautilusModel(final ModelPart root) {
|
| 29 | super(root);
|
| 30 | this.nautilus = root.getChild("root");
|
| 31 | this.body = this.nautilus.getChild("body");
|
| 32 | this.swimAnimation = NautilusAnimation.SWIMMING.bake(root);
|
| 33 | }
|
| 34 |
|
| 35 | public static LayerDefinition createBodyLayer() {
|
| 36 | return LayerDefinition.create(createBodyMesh(), 128, 128);
|
| 37 | }
|
| 38 |
|
| 39 | public static MeshDefinition createBodyMesh() {
|
| 40 | MeshDefinition meshdefinition = new MeshDefinition();
|
| 41 | PartDefinition partdefinition = meshdefinition.getRoot();
|
| 42 | PartDefinition nautilus = partdefinition.addOrReplaceChild("root", CubeListBuilder.create(), PartPose.offset(0.0F, 29.0F, -6.0F));
|
| 43 | nautilus.addOrReplaceChild(
|
| 44 | "shell",
|
| 45 | CubeListBuilder.create()
|
| 46 | .texOffs(0, 0)
|
| 47 | .addBox(-7.0F, -10.0F, -7.0F, 14.0F, 10.0F, 16.0F, new CubeDeformation(0.0F))
|
| 48 | .texOffs(0, 26)
|
| 49 | .addBox(-7.0F, 0.0F, -7.0F, 14.0F, 8.0F, 20.0F, new CubeDeformation(0.0F))
|
| 50 | .texOffs(48, 26)
|
| 51 | .addBox(-7.0F, 0.0F, 6.0F, 14.0F, 8.0F, 0.0F, new CubeDeformation(0.0F)),
|
| 52 | PartPose.offset(0.0F, -13.0F, 5.0F)
|
| 53 | );
|
| 54 | PartDefinition body = nautilus.addOrReplaceChild(
|
| 55 | "body",
|
| 56 | CubeListBuilder.create()
|
| 57 | .texOffs(0, 54)
|
| 58 | .addBox(-5.0F, -4.51F, -3.0F, 10.0F, 8.0F, 14.0F, new CubeDeformation(0.0F))
|
| 59 | .texOffs(0, 76)
|
| 60 | .addBox(-5.0F, -4.51F, 7.0F, 10.0F, 8.0F, 0.0F, new CubeDeformation(0.0F)),
|
| 61 | PartPose.offset(0.0F, -8.5F, 12.3F)
|
| 62 | );
|
| 63 | body.addOrReplaceChild(
|
| 64 | "upper_mouth",
|
| 65 | CubeListBuilder.create().texOffs(54, 54).addBox(-5.0F, -2.0F, 0.0F, 10.0F, 4.0F, 4.0F, new CubeDeformation(-0.001F)),
|
| 66 | PartPose.offset(0.0F, -2.51F, 7.0F)
|
| 67 | );
|
| 68 | body.addOrReplaceChild(
|
| 69 | "inner_mouth",
|
| 70 | CubeListBuilder.create().texOffs(54, 70).addBox(-3.0F, -2.0F, -0.5F, 6.0F, 4.0F, 4.0F, new CubeDeformation(0.0F)),
|
| 71 | PartPose.offset(0.0F, -0.51F, 7.5F)
|
| 72 | );
|
| 73 | body.addOrReplaceChild(
|
| 74 | "lower_mouth",
|
| 75 | CubeListBuilder.create().texOffs(54, 62).addBox(-5.0F, -1.98F, 0.0F, 10.0F, 4.0F, 4.0F, new CubeDeformation(-0.001F)),
|
| 76 | PartPose.offset(0.0F, 1.49F, 7.0F)
|
| 77 | );
|
| 78 | return meshdefinition;
|
| 79 | }
|
| 80 |
|
| 81 | public static LayerDefinition createBabyBodyLayer() {
|
| 82 | MeshDefinition meshdefinition = new MeshDefinition();
|
| 83 | PartDefinition partdefinition = meshdefinition.getRoot();
|
| 84 | PartDefinition nautilus = partdefinition.addOrReplaceChild("root", CubeListBuilder.create(), PartPose.offset(-0.5F, 28.0F, -0.5F));
|
| 85 | nautilus.addOrReplaceChild(
|
| 86 | "shell",
|
| 87 | CubeListBuilder.create()
|
| 88 | .texOffs(0, 0)
|
| 89 | .addBox(-6.0F, -4.0F, -1.0F, 7.0F, 4.0F, 7.0F, new CubeDeformation(0.0F))
|
| 90 | .texOffs(0, 11)
|
| 91 | .addBox(-6.0F, 0.0F, -1.0F, 7.0F, 4.0F, 9.0F, new CubeDeformation(0.0F))
|
| 92 | .texOffs(23, 11)
|
| 93 | .addBox(-6.0F, 0.0F, 5.0F, 7.0F, 4.0F, 0.0F, new CubeDeformation(0.0F)),
|
| 94 | PartPose.offset(3.0F, -8.0F, -2.0F)
|
| 95 | );
|
| 96 | PartDefinition body = nautilus.addOrReplaceChild(
|
| 97 | "body",
|
| 98 | CubeListBuilder.create()
|
| 99 | .texOffs(0, 24)
|
| 100 | .addBox(-2.5F, -3.01F, -1.0F, 5.0F, 4.0F, 7.0F, new CubeDeformation(0.0F))
|
| 101 | .texOffs(0, 35)
|
| 102 | .addBox(-2.5F, -3.01F, 4.1F, 5.0F, 4.0F, 0.0F, new CubeDeformation(0.0F)),
|
| 103 | PartPose.offset(0.5F, -5.0F, 3.0F)
|
| 104 | );
|
| 105 | body.addOrReplaceChild(
|
| 106 | "upper_mouth",
|
| 107 | CubeListBuilder.create().texOffs(24, 24).addBox(-2.5F, -1.0F, 0.0F, 5.0F, 2.0F, 2.0F, new CubeDeformation(-0.001F)),
|
| 108 | PartPose.offset(0.0F, -2.01F, 3.9F)
|
| 109 | );
|
| 110 | body.addOrReplaceChild(
|
| 111 | "inner_mouth",
|
| 112 | CubeListBuilder.create().texOffs(24, 32).addBox(-1.5F, -1.0F, -1.0F, 3.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)),
|
| 113 | PartPose.offset(0.0F, -1.01F, 4.9F)
|
| 114 | );
|
| 115 | body.addOrReplaceChild(
|
| 116 | "lower_mouth",
|
| 117 | CubeListBuilder.create().texOffs(24, 28).addBox(-2.5F, -1.0F, 0.0F, 5.0F, 2.0F, 2.0F, new CubeDeformation(-0.001F)),
|
| 118 | PartPose.offset(0.0F, -0.01F, 3.9F)
|
| 119 | );
|
| 120 | return LayerDefinition.create(meshdefinition, 64, 64);
|
| 121 | }
|
| 122 |
|
| 123 | public void setupAnim(final NautilusRenderState state) {
|
| 124 | super.setupAnim(state);
|
| 125 | this.applyBodyRotation(state.yRot, state.xRot);
|
| 126 | this.swimAnimation.applyWalk(state.walkAnimationPos + state.ageInTicks / 5.0F, state.walkAnimationSpeed + 0.2F, 2.0F, 3.0F);
|
| 127 | }
|
| 128 |
|
| 129 | private void applyBodyRotation(float yRot, float xRot) {
|
| 130 | yRot = Mth.clamp(yRot, -10.0F, 10.0F);
|
| 131 | xRot = Mth.clamp(xRot, -10.0F, 10.0F);
|
| 132 | this.body.yRot = yRot * (float) (Math.PI / 180.0);
|
| 133 | this.body.xRot = xRot * (float) (Math.PI / 180.0);
|
| 134 | }
|
| 135 | }
|
| 136 |
|