GuardianModel .java

net.minecraft.client.model.monster.guardian.GuardianModel (class): members: createElderGuardianLayer, ELDER_GUARDIAN_SCALE, SPIKE_X_ROT, SPIKE_Y_ROT, eye.

net.minecraft.client.model.monster.guardianclass157 linesclientextends EntityModel<GuardianRenderState>6.7 KB

API Surface (3)

LayerDefinition createBodyLayer()
LayerDefinition createElderGuardianLayer()
void setupAnim(final GuardianRenderState state)

Fields & Constants (15)

ELDER_GUARDIAN_SCALE
SPIKE_X_ROT
SPIKE_Y_ROT
SPIKE_Z_ROT
SPIKE_X
SPIKE_Y
SPIKE_Z
EYE
TAIL_0
TAIL_1
TAIL_2
head
eye
spikeParts
tailParts

String literals (5)

"tail0"
"tail1"
"tail2"
"head"
"spike"

Full Source

GuardianModel.java157 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.model.monster.guardian;
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.MeshTransformer;
12
import net.minecraft.client.model.geom.builders.PartDefinition;
13
import net.minecraft.client.renderer.entity.state.GuardianRenderState;
14
import net.minecraft.util.Mth;
15
import net.minecraft.world.phys.Vec3;
16
17
@Environment(EnvType.CLIENT)
18
public class GuardianModel extends EntityModel<GuardianRenderState> {
19
	public static final MeshTransformer ELDER_GUARDIAN_SCALE = MeshTransformer.scaling(2.35F);
20
	private static final float[] SPIKE_X_ROT = new float[]{1.75F, 0.25F, 0.0F, 0.0F, 0.5F, 0.5F, 0.5F, 0.5F, 1.25F, 0.75F, 0.0F, 0.0F};
21
	private static final float[] SPIKE_Y_ROT = new float[]{0.0F, 0.0F, 0.0F, 0.0F, 0.25F, 1.75F, 1.25F, 0.75F, 0.0F, 0.0F, 0.0F, 0.0F};
22
	private static final float[] SPIKE_Z_ROT = new float[]{0.0F, 0.0F, 0.25F, 1.75F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.75F, 1.25F};
23
	private static final float[] SPIKE_X = new float[]{0.0F, 0.0F, 8.0F, -8.0F, -8.0F, 8.0F, 8.0F, -8.0F, 0.0F, 0.0F, 8.0F, -8.0F};
24
	private static final float[] SPIKE_Y = new float[]{-8.0F, -8.0F, -8.0F, -8.0F, 0.0F, 0.0F, 0.0F, 0.0F, 8.0F, 8.0F, 8.0F, 8.0F};
25
	private static final float[] SPIKE_Z = new float[]{8.0F, -8.0F, 0.0F, 0.0F, -8.0F, -8.0F, 8.0F, 8.0F, 8.0F, -8.0F, 0.0F, 0.0F};
26
	private static final String EYE = "eye";
27
	private static final String TAIL_0 = "tail0";
28
	private static final String TAIL_1 = "tail1";
29
	private static final String TAIL_2 = "tail2";
30
	private final ModelPart head;
31
	private final ModelPart eye;
32
	private final ModelPart[] spikeParts = new ModelPart[12];
33
	private final ModelPart[] tailParts;
34
35
	public GuardianModel(final ModelPart root) {
36
		super(root);
37
		this.head = root.getChild("head");
38
39
		for (int i = 0; i < this.spikeParts.length; i++) {
40
			this.spikeParts[i] = this.head.getChild(createSpikeName(i));
41
		}
42
43
		this.eye = this.head.getChild("eye");
44
		this.tailParts = new ModelPart[3];
45
		this.tailParts[0] = this.head.getChild("tail0");
46
		this.tailParts[1] = this.tailParts[0].getChild("tail1");
47
		this.tailParts[2] = this.tailParts[1].getChild("tail2");
48
	}
49
50
	private static String createSpikeName(final int i) {
51
		return "spike" + i;
52
	}
53
54
	public static LayerDefinition createBodyLayer() {
55
		MeshDefinition mesh = new MeshDefinition();
56
		PartDefinition root = mesh.getRoot();
57
		PartDefinition head = root.addOrReplaceChild(
58
			"head",
59
			CubeListBuilder.create()
60
				.texOffs(0, 0)
61
				.addBox(-6.0F, 10.0F, -8.0F, 12.0F, 12.0F, 16.0F)
62
				.texOffs(0, 28)
63
				.addBox(-8.0F, 10.0F, -6.0F, 2.0F, 12.0F, 12.0F)
64
				.texOffs(0, 28)
65
				.addBox(6.0F, 10.0F, -6.0F, 2.0F, 12.0F, 12.0F, true)
66
				.texOffs(16, 40)
67
				.addBox(-6.0F, 8.0F, -6.0F, 12.0F, 2.0F, 12.0F)
68
				.texOffs(16, 40)
69
				.addBox(-6.0F, 22.0F, -6.0F, 12.0F, 2.0F, 12.0F),
70
			PartPose.ZERO
71
		);
72
		CubeListBuilder spike = CubeListBuilder.create().texOffs(0, 0).addBox(-1.0F, -4.5F, -1.0F, 2.0F, 9.0F, 2.0F);
73
74
		for (int i = 0; i < 12; i++) {
75
			float x = getSpikeX(i, 0.0F, 0.0F);
76
			float y = getSpikeY(i, 0.0F, 0.0F);
77
			float z = getSpikeZ(i, 0.0F, 0.0F);
78
			float xRot = (float) Math.PI * SPIKE_X_ROT[i];
79
			float yRot = (float) Math.PI * SPIKE_Y_ROT[i];
80
			float zRot = (float) Math.PI * SPIKE_Z_ROT[i];
81
			head.addOrReplaceChild(createSpikeName(i), spike, PartPose.offsetAndRotation(x, y, z, xRot, yRot, zRot));
82
		}
83
84
		head.addOrReplaceChild("eye", CubeListBuilder.create().texOffs(8, 0).addBox(-1.0F, 15.0F, 0.0F, 2.0F, 2.0F, 1.0F), PartPose.offset(0.0F, 0.0F, -8.25F));
85
		PartDefinition tailPart0 = head.addOrReplaceChild(
86
			"tail0", CubeListBuilder.create().texOffs(40, 0).addBox(-2.0F, 14.0F, 7.0F, 4.0F, 4.0F, 8.0F), PartPose.ZERO
87
		);
88
		PartDefinition tailPart1 = tailPart0.addOrReplaceChild(
89
			"tail1", CubeListBuilder.create().texOffs(0, 54).addBox(0.0F, 14.0F, 0.0F, 3.0F, 3.0F, 7.0F), PartPose.offset(-1.5F, 0.5F, 14.0F)
90
		);
91
		tailPart1.addOrReplaceChild(
92
			"tail2",
93
			CubeListBuilder.create().texOffs(41, 32).addBox(0.0F, 14.0F, 0.0F, 2.0F, 2.0F, 6.0F).texOffs(25, 19).addBox(1.0F, 10.5F, 3.0F, 1.0F, 9.0F, 9.0F),
94
			PartPose.offset(0.5F, 0.5F, 6.0F)
95
		);
96
		return LayerDefinition.create(mesh, 64, 64);
97
	}
98
99
	public static LayerDefinition createElderGuardianLayer() {
100
		return createBodyLayer().apply(ELDER_GUARDIAN_SCALE);
101
	}
102
103
	public void setupAnim(final GuardianRenderState state) {
104
		super.setupAnim(state);
105
		this.head.yRot = state.yRot * (float) (Math.PI / 180.0);
106
		this.head.xRot = state.xRot * (float) (Math.PI / 180.0);
107
		float withdrawal = (1.0F - state.spikesAnimation) * 0.55F;
108
		this.setupSpikes(state.ageInTicks, withdrawal);
109
		if (state.lookAtPosition != null && state.lookDirection != null) {
110
			double dy = state.lookAtPosition.y - state.eyePosition.y;
111
			if (dy > 0.0) {
112
				this.eye.y = 0.0F;
113
			} else {
114
				this.eye.y = 1.0F;
115
			}
116
117
			Vec3 viewVector = state.lookDirection;
118
			viewVector = new Vec3(viewVector.x, 0.0, viewVector.z);
119
			Vec3 delta = new Vec3(state.eyePosition.x - state.lookAtPosition.x, 0.0, state.eyePosition.z - state.lookAtPosition.z)
120
				.normalize()
121
				.yRot((float) (Math.PI / 2));
122
			double dot = viewVector.dot(delta);
123
			this.eye.x = Mth.sqrt((float)Math.abs(dot)) * 2.0F * (float)Math.signum(dot);
124
		}
125
126
		this.eye.visible = true;
127
		float swim = state.tailAnimation;
128
		this.tailParts[0].yRot = Mth.sin(swim) * (float) Math.PI * 0.05F;
129
		this.tailParts[1].yRot = Mth.sin(swim) * (float) Math.PI * 0.1F;
130
		this.tailParts[2].yRot = Mth.sin(swim) * (float) Math.PI * 0.15F;
131
	}
132
133
	private void setupSpikes(final float ageInTicks, final float withdrawal) {
134
		for (int i = 0; i < 12; i++) {
135
			this.spikeParts[i].x = getSpikeX(i, ageInTicks, withdrawal);
136
			this.spikeParts[i].y = getSpikeY(i, ageInTicks, withdrawal);
137
			this.spikeParts[i].z = getSpikeZ(i, ageInTicks, withdrawal);
138
		}
139
	}
140
141
	private static float getSpikeOffset(final int spike, final float ageInTicks, final float withdrawal) {
142
		return 1.0F + Mth.cos(ageInTicks * 1.5F + spike) * 0.01F - withdrawal;
143
	}
144
145
	private static float getSpikeX(final int spike, final float ageInTicks, final float withdrawal) {
146
		return SPIKE_X[spike] * getSpikeOffset(spike, ageInTicks, withdrawal);
147
	}
148
149
	private static float getSpikeY(final int spike, final float ageInTicks, final float withdrawal) {
150
		return 16.0F + SPIKE_Y[spike] * getSpikeOffset(spike, ageInTicks, withdrawal);
151
	}
152
153
	private static float getSpikeZ(final int spike, final float ageInTicks, final float withdrawal) {
154
		return SPIKE_Z[spike] * getSpikeOffset(spike, ageInTicks, withdrawal);
155
	}
156
}
157

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