| 1 | package net.minecraft.client.model.monster.endermite;
|
| 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.EntityRenderState;
|
| 13 | import net.minecraft.util.Mth;
|
| 14 |
|
| 15 | @Environment(EnvType.CLIENT)
|
| 16 | public class EndermiteModel extends EntityModel<EntityRenderState> {
|
| 17 | private static final int BODY_COUNT = 4;
|
| 18 | private static final int[][] BODY_SIZES = new int[][]{{4, 3, 2}, {6, 4, 5}, {3, 3, 1}, {1, 2, 1}};
|
| 19 | private static final int[][] BODY_TEXS = new int[][]{{0, 0}, {0, 5}, {0, 14}, {0, 18}};
|
| 20 | private final ModelPart[] bodyParts = new ModelPart[4];
|
| 21 |
|
| 22 | public EndermiteModel(final ModelPart root) {
|
| 23 | super(root);
|
| 24 |
|
| 25 | for (int i = 0; i < 4; i++) {
|
| 26 | this.bodyParts[i] = root.getChild(createSegmentName(i));
|
| 27 | }
|
| 28 | }
|
| 29 |
|
| 30 | private static String createSegmentName(final int i) {
|
| 31 | return "segment" + i;
|
| 32 | }
|
| 33 |
|
| 34 | public static LayerDefinition createBodyLayer() {
|
| 35 | MeshDefinition mesh = new MeshDefinition();
|
| 36 | PartDefinition root = mesh.getRoot();
|
| 37 | float placement = -3.5F;
|
| 38 |
|
| 39 | for (int i = 0; i < 4; i++) {
|
| 40 | root.addOrReplaceChild(
|
| 41 | createSegmentName(i),
|
| 42 | CubeListBuilder.create()
|
| 43 | .texOffs(BODY_TEXS[i][0], BODY_TEXS[i][1])
|
| 44 | .addBox(BODY_SIZES[i][0] * -0.5F, 0.0F, BODY_SIZES[i][2] * -0.5F, BODY_SIZES[i][0], BODY_SIZES[i][1], BODY_SIZES[i][2]),
|
| 45 | PartPose.offset(0.0F, 24 - BODY_SIZES[i][1], placement)
|
| 46 | );
|
| 47 | if (i < 3) {
|
| 48 | placement += (BODY_SIZES[i][2] + BODY_SIZES[i + 1][2]) * 0.5F;
|
| 49 | }
|
| 50 | }
|
| 51 |
|
| 52 | return LayerDefinition.create(mesh, 64, 32);
|
| 53 | }
|
| 54 |
|
| 55 | public void setupAnim(final EntityRenderState state) {
|
| 56 | super.setupAnim(state);
|
| 57 |
|
| 58 | for (int i = 0; i < this.bodyParts.length; i++) {
|
| 59 | this.bodyParts[i].yRot = Mth.cos(state.ageInTicks * 0.9F + i * 0.15F * (float) Math.PI) * (float) Math.PI * 0.01F * (1 + Math.abs(i - 2));
|
| 60 | this.bodyParts[i].x = Mth.sin(state.ageInTicks * 0.9F + i * 0.15F * (float) Math.PI) * (float) Math.PI * 0.1F * Math.abs(i - 2);
|
| 61 | }
|
| 62 | }
|
| 63 | }
|
| 64 |
|