SilverfishModel .java

net.minecraft.client.model.monster.silverfish.SilverfishModel (class): members: bodyLayers, BODY_COUNT, BODY_SIZES, BODY_TEXS, bodyParts, setupAnim.

net.minecraft.client.model.monster.silverfishclass91 linesclientextends EntityModel<EntityRenderState>3.5 KB

API Surface (2)

LayerDefinition createBodyLayer()
void setupAnim(final EntityRenderState state)

Fields & Constants (5)

BODY_COUNT
BODY_SIZES
BODY_TEXS
bodyParts
bodyLayers

String literals (2)

"layer"
"segment"

Same Package (1)

Full Source

SilverfishModel.java91 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.model.monster.silverfish;
2
3
import java.util.Arrays;
4
import net.fabricmc.api.EnvType;
5
import net.fabricmc.api.Environment;
6
import net.minecraft.client.model.EntityModel;
7
import net.minecraft.client.model.geom.ModelPart;
8
import net.minecraft.client.model.geom.PartPose;
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.EntityRenderState;
14
import net.minecraft.util.Mth;
15
16
@Environment(EnvType.CLIENT)
17
public class SilverfishModel extends EntityModel<EntityRenderState> {
18
	private static final int BODY_COUNT = 7;
19
	private final ModelPart[] bodyParts = new ModelPart[7];
20
	private final ModelPart[] bodyLayers = new ModelPart[3];
21
	private static final int[][] BODY_SIZES = new int[][]{{3, 2, 2}, {4, 3, 2}, {6, 4, 3}, {3, 3, 3}, {2, 2, 3}, {2, 1, 2}, {1, 1, 2}};
22
	private static final int[][] BODY_TEXS = new int[][]{{0, 0}, {0, 4}, {0, 9}, {0, 16}, {0, 22}, {11, 0}, {13, 4}};
23
24
	public SilverfishModel(final ModelPart root) {
25
		super(root);
26
		Arrays.setAll(this.bodyParts, i -> root.getChild(getSegmentName(i)));
27
		Arrays.setAll(this.bodyLayers, i -> root.getChild(getLayerName(i)));
28
	}
29
30
	private static String getLayerName(final int i) {
31
		return "layer" + i;
32
	}
33
34
	private static String getSegmentName(final int i) {
35
		return "segment" + i;
36
	}
37
38
	public static LayerDefinition createBodyLayer() {
39
		MeshDefinition mesh = new MeshDefinition();
40
		PartDefinition root = mesh.getRoot();
41
		float[] zPlacement = new float[7];
42
		float placement = -3.5F;
43
44
		for (int i = 0; i < 7; i++) {
45
			root.addOrReplaceChild(
46
				getSegmentName(i),
47
				CubeListBuilder.create()
48
					.texOffs(BODY_TEXS[i][0], BODY_TEXS[i][1])
49
					.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]),
50
				PartPose.offset(0.0F, 24 - BODY_SIZES[i][1], placement)
51
			);
52
			zPlacement[i] = placement;
53
			if (i < 6) {
54
				placement += (BODY_SIZES[i][2] + BODY_SIZES[i + 1][2]) * 0.5F;
55
			}
56
		}
57
58
		root.addOrReplaceChild(
59
			getLayerName(0),
60
			CubeListBuilder.create().texOffs(20, 0).addBox(-5.0F, 0.0F, BODY_SIZES[2][2] * -0.5F, 10.0F, 8.0F, BODY_SIZES[2][2]),
61
			PartPose.offset(0.0F, 16.0F, zPlacement[2])
62
		);
63
		root.addOrReplaceChild(
64
			getLayerName(1),
65
			CubeListBuilder.create().texOffs(20, 11).addBox(-3.0F, 0.0F, BODY_SIZES[4][2] * -0.5F, 6.0F, 4.0F, BODY_SIZES[4][2]),
66
			PartPose.offset(0.0F, 20.0F, zPlacement[4])
67
		);
68
		root.addOrReplaceChild(
69
			getLayerName(2),
70
			CubeListBuilder.create().texOffs(20, 18).addBox(-3.0F, 0.0F, BODY_SIZES[4][2] * -0.5F, 6.0F, 5.0F, BODY_SIZES[1][2]),
71
			PartPose.offset(0.0F, 19.0F, zPlacement[1])
72
		);
73
		return LayerDefinition.create(mesh, 64, 32);
74
	}
75
76
	public void setupAnim(final EntityRenderState state) {
77
		super.setupAnim(state);
78
79
		for (int i = 0; i < this.bodyParts.length; i++) {
80
			this.bodyParts[i].yRot = Mth.cos(state.ageInTicks * 0.9F + i * 0.15F * (float) Math.PI) * (float) Math.PI * 0.05F * (1 + Math.abs(i - 2));
81
			this.bodyParts[i].x = Mth.sin(state.ageInTicks * 0.9F + i * 0.15F * (float) Math.PI) * (float) Math.PI * 0.2F * Math.abs(i - 2);
82
		}
83
84
		this.bodyLayers[0].yRot = this.bodyParts[2].yRot;
85
		this.bodyLayers[1].yRot = this.bodyParts[4].yRot;
86
		this.bodyLayers[1].x = this.bodyParts[4].x;
87
		this.bodyLayers[2].yRot = this.bodyParts[1].yRot;
88
		this.bodyLayers[2].x = this.bodyParts[1].x;
89
	}
90
}
91

Decompiled Minecraft 26.3 source of SilverfishModel (net/minecraft/client/model/monster/silverfish/SilverfishModel.java) with Mojang official mappings, stored verbatim on the site.