ComponentContents.java

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

信息

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

    TODO

字段/常量

  • TYPE
    • 类型: SelectItemModelProperty.Type<?extends ComponentContents<?>,?>
    • 修饰符: private static final
    • 源码定位: L20
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

private static <T> SelectItemModelProperty.Type<ComponentContents<T>,T> createType() @ L22

  • 方法名:createType
  • 源码定位:L22
  • 返回类型: SelectItemModelProperty.Type<ComponentContents,T>
  • 修饰符:private static

参数:

说明:

TODO

public static <T> SelectItemModelProperty.Type<ComponentContents<T>,T> castType() @ L40

  • 方法名:castType
  • 源码定位:L40
  • 返回类型: SelectItemModelProperty.Type<ComponentContents,T>
  • 修饰符:public static

参数:

说明:

TODO

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

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

参数:

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

说明:

TODO

public SelectItemModelProperty.Type<ComponentContents<T>,T> type() @ L49

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

参数:

说明:

TODO

public Codec<T> valueCodec() @ L54

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

参数:

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public record ComponentContents<T>(DataComponentType<T> componentType) implements SelectItemModelProperty<T> {
    private static final SelectItemModelProperty.Type<? extends ComponentContents<?>, ?> TYPE = createType();
 
    private static <T> SelectItemModelProperty.Type<ComponentContents<T>, T> createType() {
        Codec<? extends DataComponentType<?>> rawComponentCodec = BuiltInRegistries.DATA_COMPONENT_TYPE
            .byNameCodec()
            .validate(t -> t.isTransient() ? DataResult.error(() -> "Component can't be serialized") : DataResult.success(t));
        MapCodec<SelectItemModel.UnbakedSwitch<ComponentContents<T>, T>> switchCodec = ((Codec<DataComponentType<T>>)rawComponentCodec).dispatchMap(
            "component",
            switchObject -> switchObject.property().componentType,
            componentType -> SelectItemModelProperty.Type.createCasesFieldCodec(componentType.codecOrThrow())
                .xmap(
                    cases -> new SelectItemModel.UnbakedSwitch<>(
                        new ComponentContents<>((DataComponentType<T>)componentType), (List<SelectItemModel.SwitchCase<T>>)cases
                    ),
                    SelectItemModel.UnbakedSwitch::cases
                )
        );
        return new SelectItemModelProperty.Type<>(switchCodec);
    }
 
    public static <T> SelectItemModelProperty.Type<ComponentContents<T>, T> castType() {
        return (SelectItemModelProperty.Type<ComponentContents<T>, T>)TYPE;
    }
 
    @Override
    public @Nullable T get(ItemStack itemStack, @Nullable ClientLevel level, @Nullable LivingEntity owner, int seed, ItemDisplayContext displayContext) {
        return itemStack.get(this.componentType);
    }
 
    @Override
    public SelectItemModelProperty.Type<ComponentContents<T>, T> type() {
        return castType();
    }
 
    @Override
    public Codec<T> valueCodec() {
        return this.componentType.codecOrThrow();
    }
}

引用的其他类