PandaRenderer .java

net.minecraft.client.renderer.entity.PandaRenderer (class, 153 lines): members: BABY_TEXTURES, TEXTURES, setupRotations, getTextureLocation. imports: Gene.

net.minecraft.client.renderer.entityclass153 linesclientextends AgeableMobRenderer<Panda6.9 KB

API Surface (4)

Identifier getTextureLocation(final PandaRenderState state)
PandaRenderState createRenderState()
void extractRenderState(final Panda entity, final PandaRenderState state, final float partialTicks)
void setupRotations(final PandaRenderState state, final PoseStack poseStack, final float bodyRot, final float entityScale)

Fields & Constants (2)

TEXTURES
BABY_TEXTURES

String literals (14)

"textures/entity/panda/panda.png"
"textures/entity/panda/panda_lazy.png"
"textures/entity/panda/panda_worried.png"
"textures/entity/panda/panda_playful.png"
"textures/entity/panda/panda_brown.png"
"textures/entity/panda/panda_weak.png"
"textures/entity/panda/panda_aggressive.png"
"textures/entity/panda/panda_baby.png"
"textures/entity/panda/lazy_panda_baby.png"
"textures/entity/panda/worried_panda_baby.png"
"textures/entity/panda/playful_panda_baby.png"
"textures/entity/panda/brown_panda_baby.png"
"textures/entity/panda/weak_panda_baby.png"
"textures/entity/panda/aggressive_panda_baby.png"

Full Source

PandaRenderer.java153 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.entity;
2
3
import com.google.common.collect.Maps;
4
import com.mojang.blaze3d.vertex.PoseStack;
5
import com.mojang.math.Axis;
6
import java.util.Map;
7
import net.fabricmc.api.EnvType;
8
import net.fabricmc.api.Environment;
9
import net.minecraft.client.model.animal.panda.BabyPandaModel;
10
import net.minecraft.client.model.animal.panda.PandaModel;
11
import net.minecraft.client.model.geom.ModelLayers;
12
import net.minecraft.client.renderer.entity.layers.PandaHoldsItemLayer;
13
import net.minecraft.client.renderer.entity.state.HoldingEntityRenderState;
14
import net.minecraft.client.renderer.entity.state.PandaRenderState;
15
import net.minecraft.resources.Identifier;
16
import net.minecraft.util.Mth;
17
import net.minecraft.world.entity.animal.panda.Panda;
18
import net.minecraft.world.entity.animal.panda.Panda.Gene;
19
20
@Environment(EnvType.CLIENT)
21
public class PandaRenderer extends AgeableMobRenderer<Panda, PandaRenderState, PandaModel> {
22
	private static final Map<Gene, Identifier> TEXTURES = Maps.newEnumMap(
23
		Map.of(
24
			Gene.NORMAL,
25
			Identifier.withDefaultNamespace("textures/entity/panda/panda.png"),
26
			Gene.LAZY,
27
			Identifier.withDefaultNamespace("textures/entity/panda/panda_lazy.png"),
28
			Gene.WORRIED,
29
			Identifier.withDefaultNamespace("textures/entity/panda/panda_worried.png"),
30
			Gene.PLAYFUL,
31
			Identifier.withDefaultNamespace("textures/entity/panda/panda_playful.png"),
32
			Gene.BROWN,
33
			Identifier.withDefaultNamespace("textures/entity/panda/panda_brown.png"),
34
			Gene.WEAK,
35
			Identifier.withDefaultNamespace("textures/entity/panda/panda_weak.png"),
36
			Gene.AGGRESSIVE,
37
			Identifier.withDefaultNamespace("textures/entity/panda/panda_aggressive.png")
38
		)
39
	);
40
	private static final Map<Gene, Identifier> BABY_TEXTURES = Maps.newEnumMap(
41
		Map.of(
42
			Gene.NORMAL,
43
			Identifier.withDefaultNamespace("textures/entity/panda/panda_baby.png"),
44
			Gene.LAZY,
45
			Identifier.withDefaultNamespace("textures/entity/panda/lazy_panda_baby.png"),
46
			Gene.WORRIED,
47
			Identifier.withDefaultNamespace("textures/entity/panda/worried_panda_baby.png"),
48
			Gene.PLAYFUL,
49
			Identifier.withDefaultNamespace("textures/entity/panda/playful_panda_baby.png"),
50
			Gene.BROWN,
51
			Identifier.withDefaultNamespace("textures/entity/panda/brown_panda_baby.png"),
52
			Gene.WEAK,
53
			Identifier.withDefaultNamespace("textures/entity/panda/weak_panda_baby.png"),
54
			Gene.AGGRESSIVE,
55
			Identifier.withDefaultNamespace("textures/entity/panda/aggressive_panda_baby.png")
56
		)
57
	);
58
59
	public PandaRenderer(final EntityRendererProvider.Context context) {
60
		super(context, new PandaModel(context.bakeLayer(ModelLayers.PANDA)), new BabyPandaModel(context.bakeLayer(ModelLayers.PANDA_BABY)), 0.9F);
61
		this.addLayer(new PandaHoldsItemLayer(this));
62
	}
63
64
	public Identifier getTextureLocation(final PandaRenderState state) {
65
		Map<Gene, Identifier> textures = state.isBaby ? BABY_TEXTURES : TEXTURES;
66
		return textures.getOrDefault(state.variant, textures.get(Gene.NORMAL));
67
	}
68
69
	public PandaRenderState createRenderState() {
70
		return new PandaRenderState();
71
	}
72
73
	public void extractRenderState(final Panda entity, final PandaRenderState state, final float partialTicks) {
74
		super.extractRenderState(entity, state, partialTicks);
75
		HoldingEntityRenderState.extractHoldingEntityRenderState(entity, state, this.itemModelResolver);
76
		state.variant = entity.getVariant();
77
		state.isUnhappy = entity.getUnhappyCounter() > 0;
78
		state.isSneezing = entity.isSneezing();
79
		state.sneezeTime = entity.getSneezeCounter();
80
		state.isEating = entity.isEating();
81
		state.isScared = entity.isScared();
82
		state.isSitting = entity.isSitting();
83
		state.sitAmount = entity.getSitAmount(partialTicks);
84
		state.lieOnBackAmount = entity.getLieOnBackAmount(partialTicks);
85
		state.rollAmount = entity.isBaby() ? 0.0F : entity.getRollAmount(partialTicks);
86
		state.rollTime = entity.rollCounter > 0 ? entity.rollCounter + partialTicks : 0.0F;
87
	}
88
89
	protected void setupRotations(final PandaRenderState state, final PoseStack poseStack, final float bodyRot, final float entityScale) {
90
		super.setupRotations(state, poseStack, bodyRot, entityScale);
91
		if (state.rollTime > 0.0F) {
92
			float rollTransitionTime = Mth.frac(state.rollTime);
93
			int rollPos = Mth.floor(state.rollTime);
94
			int nextRollPos = rollPos + 1;
95
			float divider = 7.0F;
96
			float y = state.isBaby ? 0.3F : 0.8F;
97
			if (rollPos < 8.0F) {
98
				float thisAngle = 90.0F * rollPos / 7.0F;
99
				float nextAngle = 90.0F * nextRollPos / 7.0F;
100
				float angle = this.getAngle(thisAngle, nextAngle, nextRollPos, rollTransitionTime, 8.0F);
101
				poseStack.translate(0.0F, (y + 0.2F) * (angle / 90.0F), 0.0F);
102
				poseStack.rotateDegrees(Axis.XP, -angle);
103
			} else if (rollPos < 16.0F) {
104
				float internalRollCounter = (rollPos - 8.0F) / 7.0F;
105
				float thisAngle = 90.0F + 90.0F * internalRollCounter;
106
				float nextAngle = 90.0F + 90.0F * (nextRollPos - 8.0F) / 7.0F;
107
				float angle = this.getAngle(thisAngle, nextAngle, nextRollPos, rollTransitionTime, 16.0F);
108
				poseStack.translate(0.0F, y + 0.2F + (y - 0.2F) * (angle - 90.0F) / 90.0F, 0.0F);
109
				poseStack.rotateDegrees(Axis.XP, -angle);
110
			} else if (rollPos < 24.0F) {
111
				float internalRollCounter = (rollPos - 16.0F) / 7.0F;
112
				float thisAngle = 180.0F + 90.0F * internalRollCounter;
113
				float nextAngle = 180.0F + 90.0F * (nextRollPos - 16.0F) / 7.0F;
114
				float angle = this.getAngle(thisAngle, nextAngle, nextRollPos, rollTransitionTime, 24.0F);
115
				poseStack.translate(0.0F, y + y * (270.0F - angle) / 90.0F, 0.0F);
116
				poseStack.rotateDegrees(Axis.XP, -angle);
117
			} else if (rollPos < 32) {
118
				float internalRollCounter = (rollPos - 24.0F) / 7.0F;
119
				float thisAngle = 270.0F + 90.0F * internalRollCounter;
120
				float nextAngle = 270.0F + 90.0F * (nextRollPos - 24.0F) / 7.0F;
121
				float angle = this.getAngle(thisAngle, nextAngle, nextRollPos, rollTransitionTime, 32.0F);
122
				poseStack.translate(0.0F, y * ((360.0F - angle) / 90.0F), 0.0F);
123
				poseStack.rotateDegrees(Axis.XP, -angle);
124
			}
125
		}
126
127
		float sitAmount = state.sitAmount;
128
		if (sitAmount > 0.0F) {
129
			poseStack.translate(0.0F, 0.8F * sitAmount, 0.0F);
130
			poseStack.rotateDegrees(Axis.XP, Mth.lerp(sitAmount, state.xRot, state.xRot + 90.0F));
131
			poseStack.translate(0.0F, -1.0F * sitAmount, 0.0F);
132
			if (state.isScared) {
133
				float shakeRot = (float)(Math.cos(state.ageInTicks * 1.25F) * Math.PI * 0.05F);
134
				poseStack.rotateDegrees(Axis.YP, shakeRot);
135
				if (state.isBaby) {
136
					poseStack.translate(0.0F, 0.8F, 0.55F);
137
				}
138
			}
139
		}
140
141
		float lieOnBackAmount = state.lieOnBackAmount;
142
		if (lieOnBackAmount > 0.0F) {
143
			float y = state.isBaby ? 0.5F : 1.3F;
144
			poseStack.translate(0.0F, y * lieOnBackAmount, 0.0F);
145
			poseStack.rotateDegrees(Axis.XP, Mth.lerp(lieOnBackAmount, state.xRot, state.xRot + 180.0F));
146
		}
147
	}
148
149
	private float getAngle(final float thisAngle, final float nextAngle, final int nextRollPos, final float rollTransitionTime, final float threshold) {
150
		return nextRollPos < threshold ? Mth.lerp(rollTransitionTime, thisAngle, nextAngle) : thisAngle;
151
	}
152
}
153

Decompiled Minecraft 26.3 source of PandaRenderer (net/minecraft/client/renderer/entity/PandaRenderer.java) with Mojang official mappings, stored verbatim on the site.