EquipmentClientInfo.java

net.minecraft.client.resources.model.EquipmentClientInfo

信息

  • 全限定名:net.minecraft.client.resources.model.EquipmentClientInfo
  • 类型:public record
  • 包:net.minecraft.client.resources.model
  • 源码路径:src/main/java/net/minecraft/client/resources/model/EquipmentClientInfo.java
  • 起始行号:L20
  • 职责:

    TODO

字段/常量

  • LAYER_LIST_CODEC

    • 类型: Codec<List<EquipmentClientInfo.Layer>>
    • 修饰符: private static final
    • 源码定位: L21
    • 说明:

      TODO

  • CODEC

    • 类型: Codec<EquipmentClientInfo>
    • 修饰符: public static final
    • 源码定位: L22
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.client.resources.model.EquipmentClientInfo.Builder

    • 类型: class
    • 修饰符: public static
    • 源码定位: L40
    • 说明:

      TODO

  • net.minecraft.client.resources.model.EquipmentClientInfo.Dyeable

    • 类型: record
    • 修饰符: public
    • 源码定位: L75
    • 说明:

      TODO

  • net.minecraft.client.resources.model.EquipmentClientInfo.Layer

    • 类型: record
    • 修饰符: public
    • 源码定位: L83
    • 说明:

      TODO

  • net.minecraft.client.resources.model.EquipmentClientInfo.LayerType

    • 类型: enum
    • 修饰符: public static
    • 源码定位: L113
    • 说明:

      TODO

构造器

方法

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

public static EquipmentClientInfo.Builder builder() @ L31

  • 方法名:builder
  • 源码定位:L31
  • 返回类型:EquipmentClientInfo.Builder
  • 修饰符:public static

参数:

说明:

TODO

public List<EquipmentClientInfo.Layer> getLayers(EquipmentClientInfo.LayerType type) @ L35

  • 方法名:getLayers
  • 源码定位:L35
  • 返回类型:List<EquipmentClientInfo.Layer>
  • 修饰符:public

参数:

  • type: EquipmentClientInfo.LayerType

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public record EquipmentClientInfo(Map<EquipmentClientInfo.LayerType, List<EquipmentClientInfo.Layer>> layers) {
    private static final Codec<List<EquipmentClientInfo.Layer>> LAYER_LIST_CODEC = ExtraCodecs.nonEmptyList(EquipmentClientInfo.Layer.CODEC.listOf());
    public static final Codec<EquipmentClientInfo> CODEC = RecordCodecBuilder.create(
        i -> i.group(
                ExtraCodecs.nonEmptyMap(Codec.unboundedMap(EquipmentClientInfo.LayerType.CODEC, LAYER_LIST_CODEC))
                    .fieldOf("layers")
                    .forGetter(EquipmentClientInfo::layers)
            )
            .apply(i, EquipmentClientInfo::new)
    );
 
    public static EquipmentClientInfo.Builder builder() {
        return new EquipmentClientInfo.Builder();
    }
 
    public List<EquipmentClientInfo.Layer> getLayers(EquipmentClientInfo.LayerType type) {
        return this.layers.getOrDefault(type, List.of());
    }
 
    @OnlyIn(Dist.CLIENT)
    public static class Builder {
        private final Map<EquipmentClientInfo.LayerType, List<EquipmentClientInfo.Layer>> layersByType = new EnumMap<>(EquipmentClientInfo.LayerType.class);
 
        private Builder() {
        }
 
        public EquipmentClientInfo.Builder addHumanoidLayers(Identifier textureId) {
            return this.addHumanoidLayers(textureId, false);
        }
 
        public EquipmentClientInfo.Builder addHumanoidLayers(Identifier textureId, boolean dyeable) {
            this.addLayers(EquipmentClientInfo.LayerType.HUMANOID_LEGGINGS, EquipmentClientInfo.Layer.leatherDyeable(textureId, dyeable));
            this.addMainHumanoidLayer(textureId, dyeable);
            return this;
        }
 
        public EquipmentClientInfo.Builder addMainHumanoidLayer(Identifier textureId, boolean dyeable) {
            this.addLayers(EquipmentClientInfo.LayerType.HUMANOID, EquipmentClientInfo.Layer.leatherDyeable(textureId, dyeable));
            this.addLayers(EquipmentClientInfo.LayerType.HUMANOID_BABY, EquipmentClientInfo.Layer.leatherDyeable(textureId, dyeable));
            return this;
        }
 
        public EquipmentClientInfo.Builder addLayers(EquipmentClientInfo.LayerType type, EquipmentClientInfo.Layer... layers) {
            Collections.addAll(this.layersByType.computeIfAbsent(type, t -> new ArrayList<>()), layers);
            return this;
        }
 
        public EquipmentClientInfo build() {
            return new EquipmentClientInfo(
                this.layersByType.entrySet().stream().collect(ImmutableMap.toImmutableMap(Entry::getKey, entry -> List.copyOf(entry.getValue())))
            );
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public record Dyeable(Optional<Integer> colorWhenUndyed) {
        public static final Codec<EquipmentClientInfo.Dyeable> CODEC = RecordCodecBuilder.create(
            i -> i.group(ExtraCodecs.RGB_COLOR_CODEC.optionalFieldOf("color_when_undyed").forGetter(EquipmentClientInfo.Dyeable::colorWhenUndyed))
                .apply(i, EquipmentClientInfo.Dyeable::new)
        );
    }
 
    @OnlyIn(Dist.CLIENT)
    public record Layer(Identifier textureId, Optional<EquipmentClientInfo.Dyeable> dyeable, boolean usePlayerTexture) {
        public static final Codec<EquipmentClientInfo.Layer> CODEC = RecordCodecBuilder.create(
            i -> i.group(
                    Identifier.CODEC.fieldOf("texture").forGetter(EquipmentClientInfo.Layer::textureId),
                    EquipmentClientInfo.Dyeable.CODEC.optionalFieldOf("dyeable").forGetter(EquipmentClientInfo.Layer::dyeable),
                    Codec.BOOL.optionalFieldOf("use_player_texture", false).forGetter(EquipmentClientInfo.Layer::usePlayerTexture)
                )
                .apply(i, EquipmentClientInfo.Layer::new)
        );
 
        public Layer(Identifier textureId) {
            this(textureId, Optional.empty(), false);
        }
 
        public static EquipmentClientInfo.Layer leatherDyeable(Identifier textureId, boolean dyeable) {
            return new EquipmentClientInfo.Layer(
                textureId, dyeable ? Optional.of(new EquipmentClientInfo.Dyeable(Optional.of(-6265536))) : Optional.empty(), false
            );
        }
 
        public static EquipmentClientInfo.Layer onlyIfDyed(Identifier textureId, boolean dyeable) {
            return new EquipmentClientInfo.Layer(textureId, dyeable ? Optional.of(new EquipmentClientInfo.Dyeable(Optional.empty())) : Optional.empty(), false);
        }
 
        public Identifier getTextureLocation(EquipmentClientInfo.LayerType type) {
            return this.textureId.withPath(path -> "textures/entity/equipment/" + type.getSerializedName() + "/" + path + ".png");
        }
    }
 
    @OnlyIn(Dist.CLIENT)
    public static enum LayerType implements StringRepresentable {
        HUMANOID("humanoid"),
        HUMANOID_LEGGINGS("humanoid_leggings"),
        HUMANOID_BABY("humanoid_baby"),
        WINGS("wings"),
        WOLF_BODY("wolf_body"),
        HORSE_BODY("horse_body"),
        LLAMA_BODY("llama_body"),
        PIG_SADDLE("pig_saddle"),
        STRIDER_SADDLE("strider_saddle"),
        CAMEL_SADDLE("camel_saddle"),
        CAMEL_HUSK_SADDLE("camel_husk_saddle"),
        HORSE_SADDLE("horse_saddle"),
        DONKEY_SADDLE("donkey_saddle"),
        MULE_SADDLE("mule_saddle"),
        ZOMBIE_HORSE_SADDLE("zombie_horse_saddle"),
        SKELETON_HORSE_SADDLE("skeleton_horse_saddle"),
        HAPPY_GHAST_BODY("happy_ghast_body"),
        NAUTILUS_SADDLE("nautilus_saddle"),
        NAUTILUS_BODY("nautilus_body");
 
        public static final Codec<EquipmentClientInfo.LayerType> CODEC = StringRepresentable.fromEnum(EquipmentClientInfo.LayerType::values);
        private final String id;
 
        private LayerType(String id) {
            this.id = id;
        }
 
        @Override
        public String getSerializedName() {
            return this.id;
        }
 
        public String trimAssetPrefix() {
            return "trims/entity/" + this.id;
        }
    }
}

引用的其他类

  • ExtraCodecs

    • 引用位置: 方法调用
    • 关联成员: ExtraCodecs.nonEmptyList(), ExtraCodecs.nonEmptyMap()
  • StringRepresentable

    • 引用位置: 方法调用
    • 关联成员: StringRepresentable.fromEnum()