ItemBlockState .java

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

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

Implements

API Surface (2)

SelectItemModelProperty.Type<ItemBlockState, String> type()
Codec<String> valueCodec()

Fields & Constants (3)

VALUE_CODEC
TYPE
seed

String literals (1)

"block_state_property"

Full Source

ItemBlockState.java41 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.codecs.PrimitiveCodec;
5
import com.mojang.serialization.codecs.RecordCodecBuilder;
6
import net.fabricmc.api.EnvType;
7
import net.fabricmc.api.Environment;
8
import net.minecraft.client.multiplayer.ClientLevel;
9
import net.minecraft.core.component.DataComponents;
10
import net.minecraft.world.entity.LivingEntity;
11
import net.minecraft.world.item.ItemDisplayContext;
12
import net.minecraft.world.item.ItemStack;
13
import net.minecraft.world.item.component.BlockItemStateProperties;
14
import org.jspecify.annotations.Nullable;
15
16
@Environment(EnvType.CLIENT)
17
public record ItemBlockState(String property) implements SelectItemModelProperty<String> {
18
	public static final PrimitiveCodec<String> VALUE_CODEC = Codec.STRING;
19
	public static final SelectItemModelProperty.Type<ItemBlockState, String> TYPE = SelectItemModelProperty.Type.create(
20
		RecordCodecBuilder.mapCodec(i -> i.group(Codec.STRING.fieldOf("block_state_property").forGetter(ItemBlockState::property)).apply(i, ItemBlockState::new)),
21
		VALUE_CODEC
22
	);
23
24
	public @Nullable String get(
25
		final ItemStack itemStack, final @Nullable ClientLevel level, final @Nullable LivingEntity owner, final int seed, final ItemDisplayContext displayContext
26
	) {
27
		BlockItemStateProperties blockItemStateProperties = itemStack.get(DataComponents.BLOCK_STATE);
28
		return blockItemStateProperties == null ? null : blockItemStateProperties.properties().get(this.property);
29
	}
30
31
	@Override
32
	public SelectItemModelProperty.Type<ItemBlockState, String> type() {
33
		return TYPE;
34
	}
35
36
	@Override
37
	public Codec<String> valueCodec() {
38
		return VALUE_CODEC;
39
	}
40
}
41

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