DataComponentPredicate.java

net.minecraft.core.component.predicates.DataComponentPredicate

信息

  • 全限定名:net.minecraft.core.component.predicates.DataComponentPredicate
  • 类型:public interface
  • 包:net.minecraft.core.component.predicates
  • 源码路径:src/main/java/net/minecraft/core/component/predicates/DataComponentPredicate.java
  • 起始行号:L18
  • 职责:

    TODO

字段/常量

  • CODEC

    • 类型: Codec<Map<DataComponentPredicate.Type<?>,DataComponentPredicate>>
    • 修饰符: package-private
    • 源码定位: L19
    • 说明:

      TODO

  • SINGLE_STREAM_CODEC

    • 类型: StreamCodec<RegistryFriendlyByteBuf,DataComponentPredicate.Single<?>>
    • 修饰符: package-private
    • 源码定位: L22
    • 说明:

      TODO

  • STREAM_CODEC

    • 类型: StreamCodec<RegistryFriendlyByteBuf,Map<DataComponentPredicate.Type<?>,DataComponentPredicate>>
    • 修饰符: package-private
    • 源码定位: L24
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.core.component.predicates.DataComponentPredicate.AnyValueType

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

      TODO

  • net.minecraft.core.component.predicates.DataComponentPredicate.ConcreteType

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

      TODO

  • net.minecraft.core.component.predicates.DataComponentPredicate.Single

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

      TODO

  • net.minecraft.core.component.predicates.DataComponentPredicate.Type

    • 类型: interface
    • 修饰符: public
    • 源码定位: L80
    • 说明:

      TODO

  • net.minecraft.core.component.predicates.DataComponentPredicate.TypeBase

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

      TODO

构造器

方法

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

static MapCodec<DataComponentPredicate.Single<?>> singleCodec(String name) @ L32

  • 方法名:singleCodec
  • 源码定位:L32
  • 返回类型:MapCodec<DataComponentPredicate.Single<?>>
  • 修饰符:static

参数:

  • name: String

说明:

TODO

boolean matches(DataComponentGetter components) @ L36

  • 方法名:matches
  • 源码定位:L36
  • 返回类型:boolean
  • 修饰符:package-private

参数:

  • components: DataComponentGetter

说明:

TODO

代码

public interface DataComponentPredicate {
    Codec<Map<DataComponentPredicate.Type<?>, DataComponentPredicate>> CODEC = Codec.dispatchedMap(
        DataComponentPredicate.Type.CODEC, DataComponentPredicate.Type::codec
    );
    StreamCodec<RegistryFriendlyByteBuf, DataComponentPredicate.Single<?>> SINGLE_STREAM_CODEC = DataComponentPredicate.Type.STREAM_CODEC
        .dispatch(DataComponentPredicate.Single::type, DataComponentPredicate.Type::singleStreamCodec);
    StreamCodec<RegistryFriendlyByteBuf, Map<DataComponentPredicate.Type<?>, DataComponentPredicate>> STREAM_CODEC = SINGLE_STREAM_CODEC.apply(
            ByteBufCodecs.list(64)
        )
        .map(
            singles -> singles.stream().collect(Collectors.toMap(DataComponentPredicate.Single::type, DataComponentPredicate.Single::predicate)),
            map -> map.entrySet().stream().<DataComponentPredicate.Single<?>>map(DataComponentPredicate.Single::fromEntry).toList()
        );
 
    static MapCodec<DataComponentPredicate.Single<?>> singleCodec(String name) {
        return DataComponentPredicate.Type.CODEC.dispatchMap(name, DataComponentPredicate.Single::type, DataComponentPredicate.Type::wrappedCodec);
    }
 
    boolean matches(DataComponentGetter components);
 
    public static final class AnyValueType extends DataComponentPredicate.TypeBase<AnyValue> {
        private final AnyValue predicate;
 
        public AnyValueType(AnyValue predicate) {
            super(MapCodec.unitCodec(predicate));
            this.predicate = predicate;
        }
 
        public AnyValue predicate() {
            return this.predicate;
        }
 
        public DataComponentType<?> componentType() {
            return this.predicate.type();
        }
 
        public static DataComponentPredicate.AnyValueType create(DataComponentType<?> componentType) {
            return new DataComponentPredicate.AnyValueType(new AnyValue(componentType));
        }
    }
 
    public static final class ConcreteType<T extends DataComponentPredicate> extends DataComponentPredicate.TypeBase<T> {
        public ConcreteType(Codec<T> codec) {
            super(codec);
        }
    }
 
    public record Single<T extends DataComponentPredicate>(DataComponentPredicate.Type<T> type, T predicate) {
        private static <T extends DataComponentPredicate> MapCodec<DataComponentPredicate.Single<T>> wrapCodec(
            DataComponentPredicate.Type<T> type, Codec<T> codec
        ) {
            return RecordCodecBuilder.mapCodec(
                i -> i.group(codec.fieldOf("value").forGetter(DataComponentPredicate.Single::predicate))
                    .apply(i, predicate -> new DataComponentPredicate.Single<>(type, predicate))
            );
        }
 
        private static <T extends DataComponentPredicate> DataComponentPredicate.Single<T> fromEntry(Entry<DataComponentPredicate.Type<?>, T> e) {
            return new DataComponentPredicate.Single<>((DataComponentPredicate.Type<T>)e.getKey(), e.getValue());
        }
    }
 
    public interface Type<T extends DataComponentPredicate> {
        Codec<DataComponentPredicate.Type<?>> CODEC = Codec.either(
                BuiltInRegistries.DATA_COMPONENT_PREDICATE_TYPE.byNameCodec(), BuiltInRegistries.DATA_COMPONENT_TYPE.byNameCodec()
            )
            .xmap(DataComponentPredicate.Type::copyOrCreateType, DataComponentPredicate.Type::unpackType);
        StreamCodec<RegistryFriendlyByteBuf, DataComponentPredicate.Type<?>> STREAM_CODEC = ByteBufCodecs.either(
                ByteBufCodecs.registry(Registries.DATA_COMPONENT_PREDICATE_TYPE), ByteBufCodecs.registry(Registries.DATA_COMPONENT_TYPE)
            )
            .map(DataComponentPredicate.Type::copyOrCreateType, DataComponentPredicate.Type::unpackType);
 
        private static <T extends DataComponentPredicate.Type<?>> Either<T, DataComponentType<?>> unpackType(T type) {
            return type instanceof DataComponentPredicate.AnyValueType anyCheck ? Either.right(anyCheck.componentType()) : Either.left(type);
        }
 
        private static DataComponentPredicate.Type<?> copyOrCreateType(Either<DataComponentPredicate.Type<?>, DataComponentType<?>> concreteTypeOrComponent) {
            return concreteTypeOrComponent.map(concrete -> concrete, DataComponentPredicate.AnyValueType::create);
        }
 
        Codec<T> codec();
 
        MapCodec<DataComponentPredicate.Single<T>> wrappedCodec();
 
        StreamCodec<RegistryFriendlyByteBuf, DataComponentPredicate.Single<T>> singleStreamCodec();
    }
 
    public abstract static class TypeBase<T extends DataComponentPredicate> implements DataComponentPredicate.Type<T> {
        private final Codec<T> codec;
        private final MapCodec<DataComponentPredicate.Single<T>> wrappedCodec;
        private final StreamCodec<RegistryFriendlyByteBuf, DataComponentPredicate.Single<T>> singleStreamCodec;
 
        public TypeBase(Codec<T> codec) {
            this.codec = codec;
            this.wrappedCodec = DataComponentPredicate.Single.wrapCodec(this, codec);
            this.singleStreamCodec = ByteBufCodecs.fromCodecWithRegistries(codec)
                .map(v -> new DataComponentPredicate.Single<>(this, (T)v), DataComponentPredicate.Single::predicate);
        }
 
        @Override
        public Codec<T> codec() {
            return this.codec;
        }
 
        @Override
        public MapCodec<DataComponentPredicate.Single<T>> wrappedCodec() {
            return this.wrappedCodec;
        }
 
        @Override
        public StreamCodec<RegistryFriendlyByteBuf, DataComponentPredicate.Single<T>> singleStreamCodec() {
            return this.singleStreamCodec;
        }
    }
}

引用的其他类