| 1 | package net.minecraft.client.model.npc;
|
| 2 |
|
| 3 | import com.mojang.blaze3d.vertex.PoseStack;
|
| 4 | import net.fabricmc.api.EnvType;
|
| 5 | import net.fabricmc.api.Environment;
|
| 6 | import net.minecraft.client.model.EntityModel;
|
| 7 | import net.minecraft.client.model.HeadedModel;
|
| 8 | import net.minecraft.client.model.VillagerLikeModel;
|
| 9 | import net.minecraft.client.model.geom.ModelPart;
|
| 10 | import net.minecraft.client.model.geom.PartPose;
|
| 11 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 12 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 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.VillagerRenderState;
|
| 16 | import net.minecraft.util.Mth;
|
| 17 |
|
| 18 | @Environment(EnvType.CLIENT)
|
| 19 | public class VillagerModel extends EntityModel<VillagerRenderState> implements HeadedModel, VillagerLikeModel<VillagerRenderState> {
|
| 20 | private final ModelPart head;
|
| 21 | private final ModelPart rightLeg;
|
| 22 | private final ModelPart leftLeg;
|
| 23 | private final ModelPart arms;
|
| 24 |
|
| 25 | public VillagerModel(final ModelPart root) {
|
| 26 | super(root);
|
| 27 | this.head = root.getChild("head");
|
| 28 | this.rightLeg = root.getChild("right_leg");
|
| 29 | this.leftLeg = root.getChild("left_leg");
|
| 30 | this.arms = root.getChild("arms");
|
| 31 | }
|
| 32 |
|
| 33 | public static MeshDefinition createBodyModel() {
|
| 34 | MeshDefinition mesh = new MeshDefinition();
|
| 35 | PartDefinition root = mesh.getRoot();
|
| 36 | float offset = 0.5F;
|
| 37 | PartDefinition head = root.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -10.0F, -4.0F, 8.0F, 10.0F, 8.0F), PartPose.ZERO);
|
| 38 | PartDefinition hat = head.addOrReplaceChild(
|
| 39 | "hat", CubeListBuilder.create().texOffs(32, 0).addBox(-4.0F, -10.0F, -4.0F, 8.0F, 10.0F, 8.0F, new CubeDeformation(0.51F)), PartPose.ZERO
|
| 40 | );
|
| 41 | hat.addOrReplaceChild(
|
| 42 | "hat_rim", CubeListBuilder.create().texOffs(30, 47).addBox(-8.0F, -8.0F, -6.0F, 16.0F, 16.0F, 1.0F), PartPose.rotation((float) (-Math.PI / 2), 0.0F, 0.0F)
|
| 43 | );
|
| 44 | head.addOrReplaceChild("nose", CubeListBuilder.create().texOffs(24, 0).addBox(-1.0F, -1.0F, -6.0F, 2.0F, 4.0F, 2.0F), PartPose.offset(0.0F, -2.0F, 0.0F));
|
| 45 | PartDefinition body = root.addOrReplaceChild("body", CubeListBuilder.create().texOffs(16, 20).addBox(-4.0F, 0.0F, -3.0F, 8.0F, 12.0F, 6.0F), PartPose.ZERO);
|
| 46 | body.addOrReplaceChild(
|
| 47 | "jacket", CubeListBuilder.create().texOffs(0, 38).addBox(-4.0F, 0.0F, -3.0F, 8.0F, 20.0F, 6.0F, new CubeDeformation(0.5F)), PartPose.ZERO
|
| 48 | );
|
| 49 | root.addOrReplaceChild(
|
| 50 | "arms",
|
| 51 | CubeListBuilder.create()
|
| 52 | .texOffs(44, 22)
|
| 53 | .addBox(-8.0F, -2.0F, -2.0F, 4.0F, 8.0F, 4.0F)
|
| 54 | .texOffs(44, 22)
|
| 55 | .addBox(4.0F, -2.0F, -2.0F, 4.0F, 8.0F, 4.0F, true)
|
| 56 | .texOffs(40, 38)
|
| 57 | .addBox(-4.0F, 2.0F, -2.0F, 8.0F, 4.0F, 4.0F),
|
| 58 | PartPose.offsetAndRotation(0.0F, 3.0F, -1.0F, -0.75F, 0.0F, 0.0F)
|
| 59 | );
|
| 60 | root.addOrReplaceChild(
|
| 61 | "right_leg", CubeListBuilder.create().texOffs(0, 22).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F), PartPose.offset(-2.0F, 12.0F, 0.0F)
|
| 62 | );
|
| 63 | root.addOrReplaceChild(
|
| 64 | "left_leg", CubeListBuilder.create().texOffs(0, 22).mirror().addBox(-2.0F, 0.0F, -2.0F, 4.0F, 12.0F, 4.0F), PartPose.offset(2.0F, 12.0F, 0.0F)
|
| 65 | );
|
| 66 | return mesh;
|
| 67 | }
|
| 68 |
|
| 69 | public static MeshDefinition createNoHatModel() {
|
| 70 | MeshDefinition mesh = createBodyModel();
|
| 71 | mesh.getRoot().clearChild("head").clearRecursively();
|
| 72 | return mesh;
|
| 73 | }
|
| 74 |
|
| 75 | public void setupAnim(final VillagerRenderState state) {
|
| 76 | super.setupAnim(state);
|
| 77 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 78 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 79 | if (state.isUnhappy) {
|
| 80 | this.head.zRot = 0.3F * Mth.sin(0.45F * state.ageInTicks);
|
| 81 | this.head.xRot = 0.4F;
|
| 82 | } else {
|
| 83 | this.head.zRot = 0.0F;
|
| 84 | }
|
| 85 |
|
| 86 | this.rightLeg.xRot = Mth.cos(state.walkAnimationPos * 0.6662F) * 1.4F * state.walkAnimationSpeed * 0.5F;
|
| 87 | this.leftLeg.xRot = Mth.cos(state.walkAnimationPos * 0.6662F + (float) Math.PI) * 1.4F * state.walkAnimationSpeed * 0.5F;
|
| 88 | this.rightLeg.yRot = 0.0F;
|
| 89 | this.leftLeg.yRot = 0.0F;
|
| 90 | }
|
| 91 |
|
| 92 | @Override
|
| 93 | public ModelPart getHead() {
|
| 94 | return this.head;
|
| 95 | }
|
| 96 |
|
| 97 | public void translateToArms(final VillagerRenderState state, final PoseStack outputPoseStack) {
|
| 98 | this.root.translateAndRotate(outputPoseStack);
|
| 99 | this.arms.translateAndRotate(outputPoseStack);
|
| 100 | }
|
| 101 | }
|
| 102 |
|