TrimMaterialProperty .java

net.minecraft.client.renderer.item.properties.select.TrimMaterialProperty (record, 42 lines): members: VALUE_CODEC, valueCodec, seed, TYPE, get, type.

net.minecraft.client.renderer.item.properties.selectrecord42 linesclient1.7 KB

Implements

API Surface (2)

SelectItemModelProperty.Type<TrimMaterialProperty, ResourceKey<TrimMaterial>> type()
Codec<ResourceKey<TrimMaterial>> valueCodec()

Fields & Constants (3)

VALUE_CODEC
TYPE
seed

Full Source

TrimMaterialProperty.java42 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.client.renderer.item.properties.select;
2
3
import com.mojang.serialization.Codec;
4
import com.mojang.serialization.MapCodec;
5
import net.fabricmc.api.EnvType;
6
import net.fabricmc.api.Environment;
7
import net.minecraft.client.multiplayer.ClientLevel;
8
import net.minecraft.core.component.DataComponents;
9
import net.minecraft.core.registries.Registries;
10
import net.minecraft.resources.ResourceKey;
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.item.equipment.trim.ArmorTrim;
15
import net.minecraft.world.item.equipment.trim.TrimMaterial;
16
import org.jspecify.annotations.Nullable;
17
18
@Environment(EnvType.CLIENT)
19
public record TrimMaterialProperty() implements SelectItemModelProperty<ResourceKey<TrimMaterial>> {
20
	public static final Codec<ResourceKey<TrimMaterial>> VALUE_CODEC = ResourceKey.codec(Registries.TRIM_MATERIAL);
21
	public static final SelectItemModelProperty.Type<TrimMaterialProperty, ResourceKey<TrimMaterial>> TYPE = SelectItemModelProperty.Type.create(
22
		MapCodec.unit(new TrimMaterialProperty()), VALUE_CODEC
23
	);
24
25
	public @Nullable ResourceKey<TrimMaterial> get(
26
		final ItemStack itemStack, final @Nullable ClientLevel level, final @Nullable LivingEntity owner, final int seed, final ItemDisplayContext displayContext
27
	) {
28
		ArmorTrim trim = itemStack.get(DataComponents.TRIM);
29
		return trim == null ? null : trim.material().unwrapKey().orElse(null);
30
	}
31
32
	@Override
33
	public SelectItemModelProperty.Type<TrimMaterialProperty, ResourceKey<TrimMaterial>> type() {
34
		return TYPE;
35
	}
36
37
	@Override
38
	public Codec<ResourceKey<TrimMaterial>> valueCodec() {
39
		return VALUE_CODEC;
40
	}
41
}
42

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