VillagerRenderer .java

net.minecraft.client.renderer.entity.VillagerRenderer (class, 57 lines): members: VILLAGER_BABY_LOCATION, VILLAGER_BASE_LOCATION, CUSTOM_HEAD_TRANSFORMS.

net.minecraft.client.renderer.entityclass57 linesclientextends AgeableMobRenderer<Villager2.7 KB

API Surface (4)

Identifier getTextureLocation(final VillagerRenderState state)
float getShadowRadius(final VillagerRenderState state)
VillagerRenderState createRenderState()
void extractRenderState(final Villager entity, final VillagerRenderState state, final float partialTicks)

Fields & Constants (3)

VILLAGER_BASE_LOCATION
VILLAGER_BABY_LOCATION
CUSTOM_HEAD_TRANSFORMS

String literals (3)

"textures/entity/villager/villager.png"
"textures/entity/villager/villager_baby.png"
"villager"

Full Source

VillagerRenderer.java57 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.entity;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.model.geom.ModelLayers;
6
import net.minecraft.client.model.npc.BabyVillagerModel;
7
import net.minecraft.client.model.npc.VillagerModel;
8
import net.minecraft.client.renderer.entity.layers.CrossedArmsItemLayer;
9
import net.minecraft.client.renderer.entity.layers.CustomHeadLayer;
10
import net.minecraft.client.renderer.entity.layers.VillagerProfessionLayer;
11
import net.minecraft.client.renderer.entity.state.HoldingEntityRenderState;
12
import net.minecraft.client.renderer.entity.state.VillagerRenderState;
13
import net.minecraft.resources.Identifier;
14
import net.minecraft.world.entity.npc.villager.Villager;
15
16
@Environment(EnvType.CLIENT)
17
public class VillagerRenderer extends AgeableMobRenderer<Villager, VillagerRenderState, VillagerModel> {
18
	private static final Identifier VILLAGER_BASE_LOCATION = Identifier.withDefaultNamespace("textures/entity/villager/villager.png");
19
	private static final Identifier VILLAGER_BABY_LOCATION = Identifier.withDefaultNamespace("textures/entity/villager/villager_baby.png");
20
	public static final CustomHeadLayer.Transforms CUSTOM_HEAD_TRANSFORMS = new CustomHeadLayer.Transforms(-0.1171875F, -0.07421875F, 1.0F);
21
22
	public VillagerRenderer(final EntityRendererProvider.Context context) {
23
		super(context, new VillagerModel(context.bakeLayer(ModelLayers.VILLAGER)), new BabyVillagerModel(context.bakeLayer(ModelLayers.VILLAGER_BABY)), 0.5F);
24
		this.addLayer(new CustomHeadLayer<>(this, context.getModelSet(), context.getPlayerSkinRenderCache(), CUSTOM_HEAD_TRANSFORMS));
25
		this.addLayer(
26
			new VillagerProfessionLayer<>(
27
				this,
28
				context.getResourceManager(),
29
				"villager",
30
				new VillagerModel(context.bakeLayer(ModelLayers.VILLAGER_NO_HAT)),
31
				new BabyVillagerModel(context.bakeLayer(ModelLayers.VILLAGER_BABY_NO_HAT))
32
			)
33
		);
34
		this.addLayer(new CrossedArmsItemLayer<>(this));
35
	}
36
37
	public Identifier getTextureLocation(final VillagerRenderState state) {
38
		return state.isBaby ? VILLAGER_BABY_LOCATION : VILLAGER_BASE_LOCATION;
39
	}
40
41
	protected float getShadowRadius(final VillagerRenderState state) {
42
		float radius = super.getShadowRadius(state);
43
		return state.isBaby ? radius * 0.5F : radius;
44
	}
45
46
	public VillagerRenderState createRenderState() {
47
		return new VillagerRenderState();
48
	}
49
50
	public void extractRenderState(final Villager entity, final VillagerRenderState state, final float partialTicks) {
51
		super.extractRenderState(entity, state, partialTicks);
52
		HoldingEntityRenderState.extractHoldingEntityRenderState(entity, state, this.itemModelResolver);
53
		state.isUnhappy = entity.getUnhappyCounter() > 0;
54
		state.villagerData = entity.getVillagerData();
55
	}
56
}
57

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