| 1 | package net.minecraft.client.model.animal.golem;
|
| 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.LivingEntityRenderState;
|
| 14 | import net.minecraft.util.Mth;
|
| 15 |
|
| 16 | @Environment(EnvType.CLIENT)
|
| 17 | public class SnowGolemModel extends EntityModel<LivingEntityRenderState> {
|
| 18 | private static final String UPPER_BODY = "upper_body";
|
| 19 | private final ModelPart upperBody;
|
| 20 | private final ModelPart head;
|
| 21 | private final ModelPart leftArm;
|
| 22 | private final ModelPart rightArm;
|
| 23 |
|
| 24 | public SnowGolemModel(final ModelPart root) {
|
| 25 | super(root);
|
| 26 | this.head = root.getChild("head");
|
| 27 | this.leftArm = root.getChild("left_arm");
|
| 28 | this.rightArm = root.getChild("right_arm");
|
| 29 | this.upperBody = root.getChild("upper_body");
|
| 30 | }
|
| 31 |
|
| 32 | public static LayerDefinition createBodyLayer() {
|
| 33 | MeshDefinition mesh = new MeshDefinition();
|
| 34 | PartDefinition root = mesh.getRoot();
|
| 35 | float yOffset = 4.0F;
|
| 36 | CubeDeformation deformation = new CubeDeformation(-0.5F);
|
| 37 | root.addOrReplaceChild(
|
| 38 | "head", CubeListBuilder.create().texOffs(0, 0).addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, deformation), PartPose.offset(0.0F, 4.0F, 0.0F)
|
| 39 | );
|
| 40 | CubeListBuilder arm = CubeListBuilder.create().texOffs(32, 0).addBox(-1.0F, 0.0F, -1.0F, 12.0F, 2.0F, 2.0F, deformation);
|
| 41 | root.addOrReplaceChild("left_arm", arm, PartPose.offsetAndRotation(5.0F, 6.0F, 1.0F, 0.0F, 0.0F, 1.0F));
|
| 42 | root.addOrReplaceChild("right_arm", arm, PartPose.offsetAndRotation(-5.0F, 6.0F, -1.0F, 0.0F, (float) Math.PI, -1.0F));
|
| 43 | root.addOrReplaceChild(
|
| 44 | "upper_body", CubeListBuilder.create().texOffs(0, 16).addBox(-5.0F, -10.0F, -5.0F, 10.0F, 10.0F, 10.0F, deformation), PartPose.offset(0.0F, 13.0F, 0.0F)
|
| 45 | );
|
| 46 | root.addOrReplaceChild(
|
| 47 | "lower_body", CubeListBuilder.create().texOffs(0, 36).addBox(-6.0F, -12.0F, -6.0F, 12.0F, 12.0F, 12.0F, deformation), PartPose.offset(0.0F, 24.0F, 0.0F)
|
| 48 | );
|
| 49 | return LayerDefinition.create(mesh, 64, 64);
|
| 50 | }
|
| 51 |
|
| 52 | public void setupAnim(final LivingEntityRenderState state) {
|
| 53 | super.setupAnim(state);
|
| 54 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 55 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 56 | this.upperBody.yRot = state.yRot * (float) (Math.PI / 180.0) * 0.25F;
|
| 57 | float sin = Mth.sin(this.upperBody.yRot);
|
| 58 | float cos = Mth.cos(this.upperBody.yRot);
|
| 59 | this.leftArm.yRot = this.upperBody.yRot;
|
| 60 | this.rightArm.yRot = this.upperBody.yRot + (float) Math.PI;
|
| 61 | this.leftArm.x = cos * 5.0F;
|
| 62 | this.leftArm.z = -sin * 5.0F;
|
| 63 | this.rightArm.x = -cos * 5.0F;
|
| 64 | this.rightArm.z = sin * 5.0F;
|
| 65 | }
|
| 66 |
|
| 67 | public ModelPart getHead() {
|
| 68 | return this.head;
|
| 69 | }
|
| 70 | }
|
| 71 |
|