ItemModelResolver .java

net.minecraft.client.renderer.item.ItemModelResolver (class, 81 lines): members: shouldPlaySwapAnimation, swapAnimationScale, updateForNonLiving, owner.

net.minecraft.client.renderer.itemclass81 linesclient2.9 KB

API Surface (6)

void updateForLiving(final ItemStackRenderState output, final ItemStack item, final ItemDisplayContext displayContext, final LivingEntity entity)
void updateForNonLiving(final ItemStackRenderState output, final ItemStack item, final ItemDisplayContext displayContext, final Entity entity)
void updateForTopItem(final ItemStackRenderState output, final ItemStack item, final ItemDisplayContext displayContext, final @Nullable Level level, final @Nullable ItemOwner owner, final int seed)
void appendItemLayers(final ItemStackRenderState output, final ItemStack item, final ItemDisplayContext displayContext, final @Nullable Level level, final @Nullable ItemOwner owner, final int seed)
boolean shouldPlaySwapAnimation(final ItemStack stack)
float swapAnimationScale(final ItemStack stack)

Fields & Constants (6)

modelManager
output
item
displayContext
level
owner

Full Source

ItemModelResolver.java81 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.item;
2
3
import net.fabricmc.api.EnvType;
4
import net.fabricmc.api.Environment;
5
import net.minecraft.client.multiplayer.ClientLevel;
6
import net.minecraft.client.resources.model.ModelManager;
7
import net.minecraft.core.component.DataComponents;
8
import net.minecraft.resources.Identifier;
9
import net.minecraft.world.entity.Entity;
10
import net.minecraft.world.entity.ItemOwner;
11
import net.minecraft.world.entity.LivingEntity;
12
import net.minecraft.world.item.ItemDisplayContext;
13
import net.minecraft.world.item.ItemStack;
14
import net.minecraft.world.level.Level;
15
import org.jspecify.annotations.Nullable;
16
17
@Environment(EnvType.CLIENT)
18
public class ItemModelResolver {
19
	private final ModelManager modelManager;
20
21
	public ItemModelResolver(final ModelManager modelManager) {
22
		this.modelManager = modelManager;
23
	}
24
25
	private ClientItem.Properties getItemProperties(final Identifier modelId) {
26
		return this.modelManager.getItemProperties(modelId);
27
	}
28
29
	private ItemModel getItemModel(final Identifier modelId) {
30
		return this.modelManager.getItemModel(modelId);
31
	}
32
33
	public void updateForLiving(final ItemStackRenderState output, final ItemStack item, final ItemDisplayContext displayContext, final LivingEntity entity) {
34
		this.updateForTopItem(output, item, displayContext, entity.level(), entity, entity.getId() + displayContext.ordinal());
35
	}
36
37
	public void updateForNonLiving(final ItemStackRenderState output, final ItemStack item, final ItemDisplayContext displayContext, final Entity entity) {
38
		this.updateForTopItem(output, item, displayContext, entity.level(), entity, entity.getId());
39
	}
40
41
	public void updateForTopItem(
42
		final ItemStackRenderState output,
43
		final ItemStack item,
44
		final ItemDisplayContext displayContext,
45
		final @Nullable Level level,
46
		final @Nullable ItemOwner owner,
47
		final int seed
48
	) {
49
		output.clear();
50
		if (!item.isEmpty()) {
51
			output.displayContext = displayContext;
52
			this.appendItemLayers(output, item, displayContext, level, owner, seed);
53
		}
54
	}
55
56
	public void appendItemLayers(
57
		final ItemStackRenderState output,
58
		final ItemStack item,
59
		final ItemDisplayContext displayContext,
60
		final @Nullable Level level,
61
		final @Nullable ItemOwner owner,
62
		final int seed
63
	) {
64
		Identifier modelId = item.get(DataComponents.ITEM_MODEL);
65
		if (modelId != null) {
66
			output.setOversizedInGui(this.getItemProperties(modelId).oversizedInGui());
67
			this.getItemModel(modelId).update(output, item, this, displayContext, level instanceof ClientLevel clientLevel ? clientLevel : null, owner, seed);
68
		}
69
	}
70
71
	public boolean shouldPlaySwapAnimation(final ItemStack stack) {
72
		Identifier modelId = stack.get(DataComponents.ITEM_MODEL);
73
		return modelId == null ? true : this.getItemProperties(modelId).handAnimationOnSwap();
74
	}
75
76
	public float swapAnimationScale(final ItemStack stack) {
77
		Identifier modelId = stack.get(DataComponents.ITEM_MODEL);
78
		return modelId == null ? 1.0F : this.getItemProperties(modelId).swapAnimationScale();
79
	}
80
}
81

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