ItemBlockState.java

net.minecraft.client.renderer.item.properties.select.ItemBlockState

信息

  • 全限定名:net.minecraft.client.renderer.item.properties.select.ItemBlockState
  • 类型:public record
  • 包:net.minecraft.client.renderer.item.properties.select
  • 源码路径:src/main/java/net/minecraft/client/renderer/item/properties/select/ItemBlockState.java
  • 起始行号:L17
  • 实现:SelectItemModelProperty
  • 职责:

    TODO

字段/常量

  • VALUE_CODEC

    • 类型: PrimitiveCodec<String>
    • 修饰符: public static final
    • 源码定位: L18
    • 说明:

      TODO

  • TYPE

    • 类型: SelectItemModelProperty.Type<ItemBlockState,String>
    • 修饰符: public static final
    • 源码定位: L19
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

public String get(ItemStack itemStack, ClientLevel level, LivingEntity owner, int seed, ItemDisplayContext displayContext) @ L26

  • 方法名:get
  • 源码定位:L26
  • 返回类型:String
  • 修饰符:public

参数:

  • itemStack: ItemStack
  • level: ClientLevel
  • owner: LivingEntity
  • seed: int
  • displayContext: ItemDisplayContext

说明:

TODO

public SelectItemModelProperty.Type<ItemBlockState,String> type() @ L31

  • 方法名:type
  • 源码定位:L31
  • 返回类型:SelectItemModelProperty.Type<ItemBlockState,String>
  • 修饰符:public

参数:

说明:

TODO

public Codec<String> valueCodec() @ L36

  • 方法名:valueCodec
  • 源码定位:L36
  • 返回类型:Codec
  • 修饰符:public

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public record ItemBlockState(String property) implements SelectItemModelProperty<String> {
    public static final PrimitiveCodec<String> VALUE_CODEC = Codec.STRING;
    public static final SelectItemModelProperty.Type<ItemBlockState, String> TYPE = SelectItemModelProperty.Type.create(
        RecordCodecBuilder.mapCodec(
            i -> i.group(Codec.STRING.fieldOf("block_state_property").forGetter(ItemBlockState::property)).apply(i, ItemBlockState::new)
        ),
        VALUE_CODEC
    );
 
    public @Nullable String get(ItemStack itemStack, @Nullable ClientLevel level, @Nullable LivingEntity owner, int seed, ItemDisplayContext displayContext) {
        BlockItemStateProperties blockItemStateProperties = itemStack.get(DataComponents.BLOCK_STATE);
        return blockItemStateProperties == null ? null : blockItemStateProperties.properties().get(this.property);
    }
 
    @Override
    public SelectItemModelProperty.Type<ItemBlockState, String> type() {
        return TYPE;
    }
 
    @Override
    public Codec<String> valueCodec() {
        return VALUE_CODEC;
    }
}

引用的其他类