| 1 | package net.minecraft.client.model.animal.llama;
|
| 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.LlamaRenderState;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class LlamaModel extends EntityModel<LlamaRenderState> {
|
| 18 | private final ModelPart head;
|
| 19 | private final ModelPart rightHindLeg;
|
| 20 | private final ModelPart leftHindLeg;
|
| 21 | private final ModelPart rightFrontLeg;
|
| 22 | private final ModelPart leftFrontLeg;
|
| 23 | private final ModelPart rightChest;
|
| 24 | private final ModelPart leftChest;
|
| 25 |
|
| 26 | public LlamaModel(final ModelPart root) {
|
| 27 | super(root);
|
| 28 | this.head = root.getChild("head");
|
| 29 | this.rightChest = root.getChild("right_chest");
|
| 30 | this.leftChest = root.getChild("left_chest");
|
| 31 | this.rightHindLeg = root.getChild("right_hind_leg");
|
| 32 | this.leftHindLeg = root.getChild("left_hind_leg");
|
| 33 | this.rightFrontLeg = root.getChild("right_front_leg");
|
| 34 | this.leftFrontLeg = root.getChild("left_front_leg");
|
| 35 | }
|
| 36 |
|
| 37 | public static LayerDefinition createBodyLayer(final CubeDeformation g) {
|
| 38 | MeshDefinition mesh = new MeshDefinition();
|
| 39 | PartDefinition root = mesh.getRoot();
|
| 40 | root.addOrReplaceChild(
|
| 41 | "head",
|
| 42 | CubeListBuilder.create()
|
| 43 | .texOffs(0, 0)
|
| 44 | .addBox(-2.0F, -14.0F, -10.0F, 4.0F, 4.0F, 9.0F, g)
|
| 45 | .texOffs(0, 14)
|
| 46 | .addBox("neck", -4.0F, -16.0F, -6.0F, 8.0F, 18.0F, 6.0F, g)
|
| 47 | .texOffs(17, 0)
|
| 48 | .addBox("ear", -4.0F, -19.0F, -4.0F, 3.0F, 3.0F, 2.0F, g)
|
| 49 | .texOffs(17, 0)
|
| 50 | .addBox("ear", 1.0F, -19.0F, -4.0F, 3.0F, 3.0F, 2.0F, g),
|
| 51 | PartPose.offset(0.0F, 7.0F, -6.0F)
|
| 52 | );
|
| 53 | root.addOrReplaceChild(
|
| 54 | "body",
|
| 55 | CubeListBuilder.create().texOffs(29, 0).addBox(-6.0F, -10.0F, -7.0F, 12.0F, 18.0F, 10.0F, g),
|
| 56 | PartPose.offsetAndRotation(0.0F, 5.0F, 2.0F, (float) (Math.PI / 2), 0.0F, 0.0F)
|
| 57 | );
|
| 58 | root.addOrReplaceChild(
|
| 59 | "right_chest",
|
| 60 | CubeListBuilder.create().texOffs(45, 28).addBox(-3.0F, 0.0F, 0.0F, 8.0F, 8.0F, 3.0F, g),
|
| 61 | PartPose.offsetAndRotation(-8.5F, 3.0F, 3.0F, 0.0F, (float) (Math.PI / 2), 0.0F)
|
| 62 | );
|
| 63 | root.addOrReplaceChild(
|
| 64 | "left_chest",
|
| 65 | CubeListBuilder.create().texOffs(45, 41).addBox(-3.0F, 0.0F, 0.0F, 8.0F, 8.0F, 3.0F, g),
|
| 66 | PartPose.offsetAndRotation(5.5F, 3.0F, 3.0F, 0.0F, (float) (Math.PI / 2), 0.0F)
|
| 67 | );
|
| 68 | int legWidth = 4;
|
| 69 | int legHeight = 14;
|
| 70 | CubeListBuilder leg = CubeListBuilder.create().texOffs(29, 29).addBox(-2.0F, 0.0F, -2.0F, 4.0F, 14.0F, 4.0F, g);
|
| 71 | root.addOrReplaceChild("right_hind_leg", leg, PartPose.offset(-3.5F, 10.0F, 6.0F));
|
| 72 | root.addOrReplaceChild("left_hind_leg", leg, PartPose.offset(3.5F, 10.0F, 6.0F));
|
| 73 | root.addOrReplaceChild("right_front_leg", leg, PartPose.offset(-3.5F, 10.0F, -5.0F));
|
| 74 | root.addOrReplaceChild("left_front_leg", leg, PartPose.offset(3.5F, 10.0F, -5.0F));
|
| 75 | return LayerDefinition.create(mesh, 128, 64);
|
| 76 | }
|
| 77 |
|
| 78 | public void setupAnim(final LlamaRenderState state) {
|
| 79 | super.setupAnim(state);
|
| 80 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 81 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 82 | float animationSpeed = state.walkAnimationSpeed;
|
| 83 | float animationPos = state.walkAnimationPos;
|
| 84 | this.rightHindLeg.xRot = Mth.cos(animationPos * 0.6662F) * 1.4F * animationSpeed;
|
| 85 | this.leftHindLeg.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * 1.4F * animationSpeed;
|
| 86 | this.rightFrontLeg.xRot = Mth.cos(animationPos * 0.6662F + (float) Math.PI) * 1.4F * animationSpeed;
|
| 87 | this.leftFrontLeg.xRot = Mth.cos(animationPos * 0.6662F) * 1.4F * animationSpeed;
|
| 88 | this.rightChest.visible = state.hasChest;
|
| 89 | this.leftChest.visible = state.hasChest;
|
| 90 | }
|
| 91 | }
|
| 92 |
|