| 1 | package net.minecraft.client.model.object.armorstand;
|
| 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.HumanoidModel;
|
| 7 | import net.minecraft.client.model.geom.ModelPart;
|
| 8 | import net.minecraft.client.model.geom.PartPose;
|
| 9 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 10 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 11 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 12 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 13 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 14 | import net.minecraft.client.renderer.entity.state.ArmorStandRenderState;
|
| 15 | import net.minecraft.world.entity.HumanoidArm;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class ArmorStandModel extends ArmorStandArmorModel {
|
| 19 | private static final String RIGHT_BODY_STICK = "right_body_stick";
|
| 20 | private static final String LEFT_BODY_STICK = "left_body_stick";
|
| 21 | private static final String SHOULDER_STICK = "shoulder_stick";
|
| 22 | private static final String BASE_PLATE = "base_plate";
|
| 23 | private final ModelPart rightBodyStick;
|
| 24 | private final ModelPart leftBodyStick;
|
| 25 | private final ModelPart shoulderStick;
|
| 26 | private final ModelPart basePlate;
|
| 27 |
|
| 28 | public ArmorStandModel(final ModelPart root) {
|
| 29 | super(root);
|
| 30 | this.rightBodyStick = root.getChild("right_body_stick");
|
| 31 | this.leftBodyStick = root.getChild("left_body_stick");
|
| 32 | this.shoulderStick = root.getChild("shoulder_stick");
|
| 33 | this.basePlate = root.getChild("base_plate");
|
| 34 | this.hat.visible = false;
|
| 35 | }
|
| 36 |
|
| 37 | public static LayerDefinition createBodyLayer() {
|
| 38 | MeshDefinition mesh = HumanoidModel.createMesh(CubeDeformation.NONE, 0.0F);
|
| 39 | PartDefinition root = mesh.getRoot();
|
| 40 | root.addOrReplaceChild("head", CubeListBuilder.create().texOffs(0, 0).addBox(-1.0F, -7.0F, -1.0F, 2.0F, 7.0F, 2.0F), PartPose.offset(0.0F, 1.0F, 0.0F));
|
| 41 | root.addOrReplaceChild("body", CubeListBuilder.create().texOffs(0, 26).addBox(-6.0F, 0.0F, -1.5F, 12.0F, 3.0F, 3.0F), PartPose.ZERO);
|
| 42 | root.addOrReplaceChild(
|
| 43 | "right_arm", CubeListBuilder.create().texOffs(24, 0).addBox(-2.0F, -2.0F, -1.0F, 2.0F, 12.0F, 2.0F), PartPose.offset(-5.0F, 2.0F, 0.0F)
|
| 44 | );
|
| 45 | root.addOrReplaceChild(
|
| 46 | "left_arm", CubeListBuilder.create().texOffs(32, 16).mirror().addBox(0.0F, -2.0F, -1.0F, 2.0F, 12.0F, 2.0F), PartPose.offset(5.0F, 2.0F, 0.0F)
|
| 47 | );
|
| 48 | root.addOrReplaceChild("right_leg", CubeListBuilder.create().texOffs(8, 0).addBox(-1.0F, 0.0F, -1.0F, 2.0F, 11.0F, 2.0F), PartPose.offset(-1.9F, 12.0F, 0.0F));
|
| 49 | root.addOrReplaceChild(
|
| 50 | "left_leg", CubeListBuilder.create().texOffs(40, 16).mirror().addBox(-1.0F, 0.0F, -1.0F, 2.0F, 11.0F, 2.0F), PartPose.offset(1.9F, 12.0F, 0.0F)
|
| 51 | );
|
| 52 | root.addOrReplaceChild("right_body_stick", CubeListBuilder.create().texOffs(16, 0).addBox(-3.0F, 3.0F, -1.0F, 2.0F, 7.0F, 2.0F), PartPose.ZERO);
|
| 53 | root.addOrReplaceChild("left_body_stick", CubeListBuilder.create().texOffs(48, 16).addBox(1.0F, 3.0F, -1.0F, 2.0F, 7.0F, 2.0F), PartPose.ZERO);
|
| 54 | root.addOrReplaceChild("shoulder_stick", CubeListBuilder.create().texOffs(0, 48).addBox(-4.0F, 10.0F, -1.0F, 8.0F, 2.0F, 2.0F), PartPose.ZERO);
|
| 55 | root.addOrReplaceChild(
|
| 56 | "base_plate", CubeListBuilder.create().texOffs(0, 32).addBox(-6.0F, 11.0F, -6.0F, 12.0F, 1.0F, 12.0F), PartPose.offset(0.0F, 12.0F, 0.0F)
|
| 57 | );
|
| 58 | return LayerDefinition.create(mesh, 64, 64);
|
| 59 | }
|
| 60 |
|
| 61 | @Override
|
| 62 | public void setupAnim(final ArmorStandRenderState state) {
|
| 63 | super.setupAnim(state);
|
| 64 | this.basePlate.yRot = (float) (Math.PI / 180.0) * -state.yRot;
|
| 65 | this.leftArm.visible = state.showArms;
|
| 66 | this.rightArm.visible = state.showArms;
|
| 67 | this.basePlate.visible = state.showBasePlate;
|
| 68 | this.rightBodyStick.xRot = (float) (Math.PI / 180.0) * state.bodyPose.x();
|
| 69 | this.rightBodyStick.yRot = (float) (Math.PI / 180.0) * state.bodyPose.y();
|
| 70 | this.rightBodyStick.zRot = (float) (Math.PI / 180.0) * state.bodyPose.z();
|
| 71 | this.leftBodyStick.xRot = (float) (Math.PI / 180.0) * state.bodyPose.x();
|
| 72 | this.leftBodyStick.yRot = (float) (Math.PI / 180.0) * state.bodyPose.y();
|
| 73 | this.leftBodyStick.zRot = (float) (Math.PI / 180.0) * state.bodyPose.z();
|
| 74 | this.shoulderStick.xRot = (float) (Math.PI / 180.0) * state.bodyPose.x();
|
| 75 | this.shoulderStick.yRot = (float) (Math.PI / 180.0) * state.bodyPose.y();
|
| 76 | this.shoulderStick.zRot = (float) (Math.PI / 180.0) * state.bodyPose.z();
|
| 77 | }
|
| 78 |
|
| 79 | public void translateToHand(final ArmorStandRenderState state, final HumanoidArm arm, final PoseStack poseStack) {
|
| 80 | ModelPart modelPart = this.getArm(arm);
|
| 81 | boolean handVisible = modelPart.visible;
|
| 82 | modelPart.visible = true;
|
| 83 | super.translateToHand(state, arm, poseStack);
|
| 84 | modelPart.visible = handVisible;
|
| 85 | }
|
| 86 | }
|
| 87 |
|