| 1 | package net.minecraft.client.model.monster.skeleton;
|
| 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.AnimationUtils;
|
| 7 | import net.minecraft.client.model.HumanoidModel;
|
| 8 | import net.minecraft.client.model.geom.ModelPart;
|
| 9 | import net.minecraft.client.model.geom.PartPose;
|
| 10 | import net.minecraft.client.model.geom.builders.CubeDeformation;
|
| 11 | import net.minecraft.client.model.geom.builders.CubeListBuilder;
|
| 12 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 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.SkeletonRenderState;
|
| 16 | import net.minecraft.util.Mth;
|
| 17 | import net.minecraft.world.entity.HumanoidArm;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public class SkeletonModel<S extends SkeletonRenderState> extends HumanoidModel<S> {
|
| 21 | public SkeletonModel(final ModelPart root) {
|
| 22 | super(root);
|
| 23 | }
|
| 24 |
|
| 25 | public static LayerDefinition createBodyLayer() {
|
| 26 | MeshDefinition mesh = HumanoidModel.createMesh(CubeDeformation.NONE, 0.0F);
|
| 27 | PartDefinition root = mesh.getRoot();
|
| 28 | createDefaultSkeletonMesh(root);
|
| 29 | return LayerDefinition.create(mesh, 64, 32);
|
| 30 | }
|
| 31 |
|
| 32 | protected static void createDefaultSkeletonMesh(final PartDefinition root) {
|
| 33 | root.addOrReplaceChild(
|
| 34 | "right_arm", CubeListBuilder.create().texOffs(40, 16).addBox(-1.0F, -2.0F, -1.0F, 2.0F, 12.0F, 2.0F), PartPose.offset(-5.0F, 2.0F, 0.0F)
|
| 35 | );
|
| 36 | root.addOrReplaceChild(
|
| 37 | "left_arm", CubeListBuilder.create().texOffs(40, 16).mirror().addBox(-1.0F, -2.0F, -1.0F, 2.0F, 12.0F, 2.0F), PartPose.offset(5.0F, 2.0F, 0.0F)
|
| 38 | );
|
| 39 | root.addOrReplaceChild(
|
| 40 | "right_leg", CubeListBuilder.create().texOffs(0, 16).addBox(-1.0F, 0.0F, -1.0F, 2.0F, 12.0F, 2.0F), PartPose.offset(-2.0F, 12.0F, 0.0F)
|
| 41 | );
|
| 42 | root.addOrReplaceChild(
|
| 43 | "left_leg", CubeListBuilder.create().texOffs(0, 16).mirror().addBox(-1.0F, 0.0F, -1.0F, 2.0F, 12.0F, 2.0F), PartPose.offset(2.0F, 12.0F, 0.0F)
|
| 44 | );
|
| 45 | }
|
| 46 |
|
| 47 | public static LayerDefinition createSingleModelDualBodyLayer() {
|
| 48 | MeshDefinition meshdefinition = new MeshDefinition();
|
| 49 | PartDefinition root = meshdefinition.getRoot();
|
| 50 | root.addOrReplaceChild(
|
| 51 | "body",
|
| 52 | CubeListBuilder.create()
|
| 53 | .texOffs(16, 16)
|
| 54 | .addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F)
|
| 55 | .texOffs(28, 0)
|
| 56 | .addBox(-4.0F, 10.0F, -2.0F, 8.0F, 1.0F, 4.0F)
|
| 57 | .texOffs(16, 48)
|
| 58 | .addBox(-4.0F, 0.0F, -2.0F, 8.0F, 12.0F, 4.0F, new CubeDeformation(0.025F)),
|
| 59 | PartPose.offset(0.0F, 0.0F, 0.0F)
|
| 60 | );
|
| 61 | root.addOrReplaceChild(
|
| 62 | "head",
|
| 63 | CubeListBuilder.create()
|
| 64 | .texOffs(0, 0)
|
| 65 | .addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F)
|
| 66 | .texOffs(0, 32)
|
| 67 | .addBox(-4.0F, -8.0F, -4.0F, 8.0F, 8.0F, 8.0F, new CubeDeformation(0.2F)),
|
| 68 | PartPose.offset(0.0F, 0.0F, 0.0F)
|
| 69 | )
|
| 70 | .addOrReplaceChild("hat", CubeListBuilder.create(), PartPose.ZERO);
|
| 71 | root.addOrReplaceChild(
|
| 72 | "right_arm",
|
| 73 | CubeListBuilder.create().texOffs(40, 16).addBox(-1.0F, -2.0F, -1.0F, 2.0F, 12.0F, 2.0F).texOffs(42, 33).addBox(-1.55F, -2.025F, -1.5F, 3.0F, 12.0F, 3.0F),
|
| 74 | PartPose.offset(-5.5F, 2.0F, 0.0F)
|
| 75 | );
|
| 76 | root.addOrReplaceChild(
|
| 77 | "left_arm",
|
| 78 | CubeListBuilder.create().texOffs(56, 16).addBox(-1.0F, -2.0F, -1.0F, 2.0F, 12.0F, 2.0F).texOffs(40, 48).addBox(-1.45F, -2.025F, -1.5F, 3.0F, 12.0F, 3.0F),
|
| 79 | PartPose.offset(5.5F, 2.0F, 0.0F)
|
| 80 | );
|
| 81 | root.addOrReplaceChild(
|
| 82 | "right_leg",
|
| 83 | CubeListBuilder.create().texOffs(0, 16).addBox(-1.0F, 0.0F, -1.0F, 2.0F, 12.0F, 2.0F).texOffs(0, 49).addBox(-1.5F, -0.0F, -1.5F, 3.0F, 12.0F, 3.0F),
|
| 84 | PartPose.offset(-2.0F, 12.0F, 0.0F)
|
| 85 | );
|
| 86 | root.addOrReplaceChild(
|
| 87 | "left_leg",
|
| 88 | CubeListBuilder.create().texOffs(0, 16).addBox(-1.0F, 0.0F, -1.0F, 2.0F, 12.0F, 2.0F).texOffs(4, 49).addBox(-1.5F, 0.0F, -1.5F, 3.0F, 12.0F, 3.0F),
|
| 89 | PartPose.offset(2.0F, 12.0F, 0.0F)
|
| 90 | );
|
| 91 | return LayerDefinition.create(meshdefinition, 64, 64);
|
| 92 | }
|
| 93 |
|
| 94 | public void setupAnim(final S state) {
|
| 95 | super.setupAnim(state);
|
| 96 | if (state.isAggressive && !state.isHoldingBow) {
|
| 97 | float swingAnimation = state.swingAnimation;
|
| 98 | float swing2 = Mth.sin(swingAnimation * (float) Math.PI);
|
| 99 | float swing = Mth.sin((1.0F - (1.0F - swingAnimation) * (1.0F - swingAnimation)) * (float) Math.PI);
|
| 100 | this.rightArm.zRot = 0.0F;
|
| 101 | this.leftArm.zRot = 0.0F;
|
| 102 | this.rightArm.yRot = -(0.1F - swing2 * 0.6F);
|
| 103 | this.leftArm.yRot = 0.1F - swing2 * 0.6F;
|
| 104 | this.rightArm.xRot = (float) (-Math.PI / 2);
|
| 105 | this.leftArm.xRot = (float) (-Math.PI / 2);
|
| 106 | this.rightArm.xRot -= swing2 * 1.2F - swing * 0.4F;
|
| 107 | this.leftArm.xRot -= swing2 * 1.2F - swing * 0.4F;
|
| 108 | AnimationUtils.bobArms(this.rightArm, this.leftArm, state.ageInTicks);
|
| 109 | }
|
| 110 | }
|
| 111 |
|
| 112 | public void translateToHand(final SkeletonRenderState state, final HumanoidArm arm, final PoseStack poseStack) {
|
| 113 | this.root().translateAndRotate(poseStack);
|
| 114 | float offset = arm == HumanoidArm.RIGHT ? 1.0F : -1.0F;
|
| 115 | ModelPart part = this.getArm(arm);
|
| 116 | part.x += offset;
|
| 117 | part.translateAndRotate(poseStack);
|
| 118 | part.x -= offset;
|
| 119 | }
|
| 120 | }
|
| 121 |
|