TagPredicate.java

net.minecraft.advancements.criterion.TagPredicate

信息

  • 全限定名:net.minecraft.advancements.criterion.TagPredicate
  • 类型:public record
  • 包:net.minecraft.advancements.criterion
  • 源码路径:src/main/java/net/minecraft/advancements/criterion/TagPredicate.java
  • 起始行号:L10
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

方法

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

public static <T> Codec<TagPredicate<T>> codec(ResourceKey<?extends Registry<T>> registryKey) @ L11

  • 方法名:codec
  • 源码定位:L11
  • 返回类型: Codec<TagPredicate>
  • 修饰符:public static

参数:

  • registryKey: ResourceKey<?extends Registry>

说明:

TODO

public static <T> TagPredicate<T> is(TagKey<T> tag) @ L18

  • 方法名:is
  • 源码定位:L18
  • 返回类型: TagPredicate
  • 修饰符:public static

参数:

  • tag: TagKey

说明:

TODO

public static <T> TagPredicate<T> isNot(TagKey<T> tag) @ L22

  • 方法名:isNot
  • 源码定位:L22
  • 返回类型: TagPredicate
  • 修饰符:public static

参数:

  • tag: TagKey

说明:

TODO

public boolean matches(Holder<T> holder) @ L26

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

参数:

  • holder: Holder

说明:

TODO

代码

public record TagPredicate<T>(TagKey<T> tag, boolean expected) {
    public static <T> Codec<TagPredicate<T>> codec(ResourceKey<? extends Registry<T>> registryKey) {
        return RecordCodecBuilder.create(
            i -> i.group(TagKey.codec(registryKey).fieldOf("id").forGetter(TagPredicate::tag), Codec.BOOL.fieldOf("expected").forGetter(TagPredicate::expected))
                .apply(i, TagPredicate::new)
        );
    }
 
    public static <T> TagPredicate<T> is(TagKey<T> tag) {
        return new TagPredicate<>(tag, true);
    }
 
    public static <T> TagPredicate<T> isNot(TagKey<T> tag) {
        return new TagPredicate<>(tag, false);
    }
 
    public boolean matches(Holder<T> holder) {
        return holder.is(this.tag) == this.expected;
    }
}

引用的其他类

  • Holder

    • 引用位置: 参数
  • Registry

    • 引用位置: 参数
  • ResourceKey

    • 引用位置: 参数
  • TagKey

    • 引用位置: 参数/方法调用
    • 关联成员: TagKey.codec()