| 1 | package net.minecraft.client.model.monster.spider;
|
| 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.CubeListBuilder;
|
| 9 | import net.minecraft.client.model.geom.builders.LayerDefinition;
|
| 10 | import net.minecraft.client.model.geom.builders.MeshDefinition;
|
| 11 | import net.minecraft.client.model.geom.builders.PartDefinition;
|
| 12 | import net.minecraft.client.renderer.entity.state.LivingEntityRenderState;
|
| 13 | import net.minecraft.util.Mth;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class SpiderModel extends EntityModel<LivingEntityRenderState> {
|
| 17 | private static final String BODY_0 = "body0";
|
| 18 | private static final String BODY_1 = "body1";
|
| 19 | private static final String RIGHT_MIDDLE_FRONT_LEG = "right_middle_front_leg";
|
| 20 | private static final String LEFT_MIDDLE_FRONT_LEG = "left_middle_front_leg";
|
| 21 | private static final String RIGHT_MIDDLE_HIND_LEG = "right_middle_hind_leg";
|
| 22 | private static final String LEFT_MIDDLE_HIND_LEG = "left_middle_hind_leg";
|
| 23 | private final ModelPart head;
|
| 24 | private final ModelPart rightHindLeg;
|
| 25 | private final ModelPart leftHindLeg;
|
| 26 | private final ModelPart rightMiddleHindLeg;
|
| 27 | private final ModelPart leftMiddleHindLeg;
|
| 28 | private final ModelPart rightMiddleFrontLeg;
|
| 29 | private final ModelPart leftMiddleFrontLeg;
|
| 30 | private final ModelPart rightFrontLeg;
|
| 31 | private final ModelPart leftFrontLeg;
|
| 32 |
|
| 33 | public SpiderModel(final ModelPart root) {
|
| 34 | super(root);
|
| 35 | this.head = root.getChild("head");
|
| 36 | this.rightHindLeg = root.getChild("right_hind_leg");
|
| 37 | this.leftHindLeg = root.getChild("left_hind_leg");
|
| 38 | this.rightMiddleHindLeg = root.getChild("right_middle_hind_leg");
|
| 39 | this.leftMiddleHindLeg = root.getChild("left_middle_hind_leg");
|
| 40 | this.rightMiddleFrontLeg = root.getChild("right_middle_front_leg");
|
| 41 | this.leftMiddleFrontLeg = root.getChild("left_middle_front_leg");
|
| 42 | this.rightFrontLeg = root.getChild("right_front_leg");
|
| 43 | this.leftFrontLeg = root.getChild("left_front_leg");
|
| 44 | }
|
| 45 |
|
| 46 | public static LayerDefinition createSpiderBodyLayer() {
|
| 47 | MeshDefinition mesh = new MeshDefinition();
|
| 48 | PartDefinition root = mesh.getRoot();
|
| 49 | int yo = 15;
|
| 50 | root.addOrReplaceChild("head", CubeListBuilder.create().texOffs(32, 4).addBox(-4.0F, -4.0F, -8.0F, 8.0F, 8.0F, 8.0F), PartPose.offset(0.0F, 15.0F, -3.0F));
|
| 51 | root.addOrReplaceChild("body0", CubeListBuilder.create().texOffs(0, 0).addBox(-3.0F, -3.0F, -3.0F, 6.0F, 6.0F, 6.0F), PartPose.offset(0.0F, 15.0F, 0.0F));
|
| 52 | root.addOrReplaceChild("body1", CubeListBuilder.create().texOffs(0, 12).addBox(-5.0F, -4.0F, -6.0F, 10.0F, 8.0F, 12.0F), PartPose.offset(0.0F, 15.0F, 9.0F));
|
| 53 | CubeListBuilder rightLeg = CubeListBuilder.create().texOffs(18, 0).addBox(-15.0F, -1.0F, -1.0F, 16.0F, 2.0F, 2.0F);
|
| 54 | CubeListBuilder leftLeg = CubeListBuilder.create().texOffs(18, 0).mirror().addBox(-1.0F, -1.0F, -1.0F, 16.0F, 2.0F, 2.0F);
|
| 55 | float legZRot = (float) (Math.PI / 4);
|
| 56 | float legYRotSpan = (float) (Math.PI / 8);
|
| 57 | root.addOrReplaceChild("right_hind_leg", rightLeg, PartPose.offsetAndRotation(-4.0F, 15.0F, 2.0F, 0.0F, (float) (Math.PI / 4), (float) (-Math.PI / 4)));
|
| 58 | root.addOrReplaceChild("left_hind_leg", leftLeg, PartPose.offsetAndRotation(4.0F, 15.0F, 2.0F, 0.0F, (float) (-Math.PI / 4), (float) (Math.PI / 4)));
|
| 59 | root.addOrReplaceChild("right_middle_hind_leg", rightLeg, PartPose.offsetAndRotation(-4.0F, 15.0F, 1.0F, 0.0F, (float) (Math.PI / 8), -0.58119464F));
|
| 60 | root.addOrReplaceChild("left_middle_hind_leg", leftLeg, PartPose.offsetAndRotation(4.0F, 15.0F, 1.0F, 0.0F, (float) (-Math.PI / 8), 0.58119464F));
|
| 61 | root.addOrReplaceChild("right_middle_front_leg", rightLeg, PartPose.offsetAndRotation(-4.0F, 15.0F, 0.0F, 0.0F, (float) (-Math.PI / 8), -0.58119464F));
|
| 62 | root.addOrReplaceChild("left_middle_front_leg", leftLeg, PartPose.offsetAndRotation(4.0F, 15.0F, 0.0F, 0.0F, (float) (Math.PI / 8), 0.58119464F));
|
| 63 | root.addOrReplaceChild("right_front_leg", rightLeg, PartPose.offsetAndRotation(-4.0F, 15.0F, -1.0F, 0.0F, (float) (-Math.PI / 4), (float) (-Math.PI / 4)));
|
| 64 | root.addOrReplaceChild("left_front_leg", leftLeg, PartPose.offsetAndRotation(4.0F, 15.0F, -1.0F, 0.0F, (float) (Math.PI / 4), (float) (Math.PI / 4)));
|
| 65 | return LayerDefinition.create(mesh, 64, 32);
|
| 66 | }
|
| 67 |
|
| 68 | public void setupAnim(final LivingEntityRenderState state) {
|
| 69 | super.setupAnim(state);
|
| 70 | this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
|
| 71 | this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
|
| 72 | float animationPos = state.walkAnimationPos * 0.6662F;
|
| 73 | float animationSpeed = state.walkAnimationSpeed;
|
| 74 | float swingHind = -(Mth.cos(animationPos * 2.0F + 0.0F) * 0.4F) * animationSpeed;
|
| 75 | float swingMiddleHind = -(Mth.cos(animationPos * 2.0F + (float) Math.PI) * 0.4F) * animationSpeed;
|
| 76 | float swingMiddleFront = -(Mth.cos(animationPos * 2.0F + (float) (Math.PI / 2)) * 0.4F) * animationSpeed;
|
| 77 | float swingFront = -(Mth.cos(animationPos * 2.0F + (float) (Math.PI * 3.0 / 2.0)) * 0.4F) * animationSpeed;
|
| 78 | float stepHind = Math.abs(Mth.sin(animationPos + 0.0F) * 0.4F) * animationSpeed;
|
| 79 | float stepMiddleHind = Math.abs(Mth.sin(animationPos + (float) Math.PI) * 0.4F) * animationSpeed;
|
| 80 | float stepMiddleFrontHind = Math.abs(Mth.sin(animationPos + (float) (Math.PI / 2)) * 0.4F) * animationSpeed;
|
| 81 | float stepFront = Math.abs(Mth.sin(animationPos + (float) (Math.PI * 3.0 / 2.0)) * 0.4F) * animationSpeed;
|
| 82 | this.rightHindLeg.yRot += swingHind;
|
| 83 | this.leftHindLeg.yRot -= swingHind;
|
| 84 | this.rightMiddleHindLeg.yRot += swingMiddleHind;
|
| 85 | this.leftMiddleHindLeg.yRot -= swingMiddleHind;
|
| 86 | this.rightMiddleFrontLeg.yRot += swingMiddleFront;
|
| 87 | this.leftMiddleFrontLeg.yRot -= swingMiddleFront;
|
| 88 | this.rightFrontLeg.yRot += swingFront;
|
| 89 | this.leftFrontLeg.yRot -= swingFront;
|
| 90 | this.rightHindLeg.zRot += stepHind;
|
| 91 | this.leftHindLeg.zRot -= stepHind;
|
| 92 | this.rightMiddleHindLeg.zRot += stepMiddleHind;
|
| 93 | this.leftMiddleHindLeg.zRot -= stepMiddleHind;
|
| 94 | this.rightMiddleFrontLeg.zRot += stepMiddleFrontHind;
|
| 95 | this.leftMiddleFrontLeg.zRot -= stepMiddleFrontHind;
|
| 96 | this.rightFrontLeg.zRot += stepFront;
|
| 97 | this.leftFrontLeg.zRot -= stepFront;
|
| 98 | }
|
| 99 | }
|
| 100 |
|