| 1 | package net.minecraft.client.model.monster.hoglin;
|
| 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.HoglinRenderState;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class HoglinModel extends EntityModel<HoglinRenderState> {
|
| 18 | private static final float DEFAULT_HEAD_X_ROT = 0.87266463F;
|
| 19 | private static final float ATTACK_HEAD_X_ROT_END = (float) (-Math.PI / 9);
|
| 20 | protected final ModelPart head;
|
| 21 | private final ModelPart rightEar;
|
| 22 | private final ModelPart leftEar;
|
| 23 | private final ModelPart rightFrontLeg;
|
| 24 | private final ModelPart leftFrontLeg;
|
| 25 | private final ModelPart rightHindLeg;
|
| 26 | private final ModelPart leftHindLeg;
|
| 27 |
|
| 28 | public HoglinModel(final ModelPart root) {
|
| 29 | super(root);
|
| 30 | this.head = root.getChild("head");
|
| 31 | this.rightEar = this.head.getChild("right_ear");
|
| 32 | this.leftEar = this.head.getChild("left_ear");
|
| 33 | this.rightFrontLeg = root.getChild("right_front_leg");
|
| 34 | this.leftFrontLeg = root.getChild("left_front_leg");
|
| 35 | this.rightHindLeg = root.getChild("right_hind_leg");
|
| 36 | this.leftHindLeg = root.getChild("left_hind_leg");
|
| 37 | }
|
| 38 |
|
| 39 | public static LayerDefinition createBodyLayer() {
|
| 40 | MeshDefinition mesh = new MeshDefinition();
|
| 41 | PartDefinition root = mesh.getRoot();
|
| 42 | PartDefinition body = root.addOrReplaceChild(
|
| 43 | "body", CubeListBuilder.create().texOffs(1, 1).addBox(-8.0F, -7.0F, -13.0F, 16.0F, 14.0F, 26.0F), PartPose.offset(0.0F, 7.0F, 0.0F)
|
| 44 | );
|
| 45 | body.addOrReplaceChild(
|
| 46 | "mane",
|
| 47 | CubeListBuilder.create().texOffs(90, 33).addBox(0.0F, 0.0F, -9.0F, 0.0F, 10.0F, 19.0F, new CubeDeformation(0.001F)),
|
| 48 | PartPose.offset(0.0F, -14.0F, -7.0F)
|
| 49 | );
|
| 50 | PartDefinition head = root.addOrReplaceChild(
|
| 51 | "head",
|
| 52 | CubeListBuilder.create().texOffs(61, 1).addBox(-7.0F, -3.0F, -19.0F, 14.0F, 6.0F, 19.0F),
|
| 53 | PartPose.offsetAndRotation(0.0F, 2.0F, -12.0F, 0.87266463F, 0.0F, 0.0F)
|
| 54 | );
|
| 55 | head.addOrReplaceChild(
|
| 56 | "right_ear",
|
| 57 | CubeListBuilder.create().texOffs(1, 1).addBox(-6.0F, -1.0F, -2.0F, 6.0F, 1.0F, 4.0F),
|
| 58 | PartPose.offsetAndRotation(-6.0F, -2.0F, -3.0F, 0.0F, 0.0F, (float) (-Math.PI * 2.0 / 9.0))
|
| 59 | );
|
| 60 | head.addOrReplaceChild(
|
| 61 | "left_ear",
|
| 62 | CubeListBuilder.create().texOffs(1, 6).addBox(0.0F, -1.0F, -2.0F, 6.0F, 1.0F, 4.0F),
|
| 63 | PartPose.offsetAndRotation(6.0F, -2.0F, -3.0F, 0.0F, 0.0F, (float) (Math.PI * 2.0 / 9.0))
|
| 64 | );
|
| 65 | head.addOrReplaceChild(
|
| 66 | "right_horn", CubeListBuilder.create().texOffs(10, 13).addBox(-1.0F, -11.0F, -1.0F, 2.0F, 11.0F, 2.0F), PartPose.offset(-7.0F, 2.0F, -12.0F)
|
| 67 | );
|
| 68 | head.addOrReplaceChild(
|
| 69 | "left_horn", CubeListBuilder.create().texOffs(1, 13).addBox(-1.0F, -11.0F, -1.0F, 2.0F, 11.0F, 2.0F), PartPose.offset(7.0F, 2.0F, -12.0F)
|
| 70 | );
|
| 71 | int frontLegHeight = 14;
|
| 72 | int backLegHeight = 11;
|
| 73 | root.addOrReplaceChild(
|
| 74 | "right_front_leg", CubeListBuilder.create().texOffs(66, 42).addBox(-3.0F, 0.0F, -3.0F, 6.0F, 14.0F, 6.0F), PartPose.offset(-4.0F, 10.0F, -8.5F)
|
| 75 | );
|
| 76 | root.addOrReplaceChild(
|
| 77 | "left_front_leg", CubeListBuilder.create().texOffs(41, 42).addBox(-3.0F, 0.0F, -3.0F, 6.0F, 14.0F, 6.0F), PartPose.offset(4.0F, 10.0F, -8.5F)
|
| 78 | );
|
| 79 | root.addOrReplaceChild(
|
| 80 | "right_hind_leg", CubeListBuilder.create().texOffs(21, 45).addBox(-2.5F, 0.0F, -2.5F, 5.0F, 11.0F, 5.0F), PartPose.offset(-5.0F, 13.0F, 10.0F)
|
| 81 | );
|
| 82 | root.addOrReplaceChild(
|
| 83 | "left_hind_leg", CubeListBuilder.create().texOffs(0, 45).addBox(-2.5F, 0.0F, -2.5F, 5.0F, 11.0F, 5.0F), PartPose.offset(5.0F, 13.0F, 10.0F)
|
| 84 | );
|
| 85 | return LayerDefinition.create(mesh, 128, 64);
|
| 86 | }
|
| 87 |
|
| 88 | public void setupAnim(final HoglinRenderState state) {
|
| 89 | super.setupAnim(state);
|
| 90 | float animationSpeed = state.walkAnimationSpeed;
|
| 91 | float animationPos = state.walkAnimationPos;
|
| 92 | this.rightEar.zRot = (float) (-Math.PI * 2.0 / 9.0) - animationSpeed * Mth.sin(animationPos);
|
| 93 | this.leftEar.zRot = (float) (Math.PI * 2.0 / 9.0) + animationSpeed * Mth.sin(animationPos);
|
| 94 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 95 | float headbuttLerpFactor = 1.0F - Mth.abs(10 - 2 * state.attackAnimationRemainingTicks) / 10.0F;
|
| 96 | this.animateHeadbutt(headbuttLerpFactor);
|
| 97 | float amplitudeMultiplier = 1.2F;
|
| 98 | this.rightFrontLeg.xRot = Mth.cos(animationPos) * 1.2F * animationSpeed;
|
| 99 | this.leftFrontLeg.xRot = Mth.cos(animationPos + (float) Math.PI) * 1.2F * animationSpeed;
|
| 100 | this.rightHindLeg.xRot = this.leftFrontLeg.xRot;
|
| 101 | this.leftHindLeg.xRot = this.rightFrontLeg.xRot;
|
| 102 | }
|
| 103 |
|
| 104 | protected void animateHeadbutt(final float headbuttLerpFactor) {
|
| 105 | this.head.xRot = Mth.lerp(headbuttLerpFactor, 0.87266463F, (float) (-Math.PI / 9));
|
| 106 | }
|
| 107 | }
|
| 108 |
|