WrittenBookPredicate.java

net.minecraft.core.component.predicates.WrittenBookPredicate

信息

  • 全限定名:net.minecraft.core.component.predicates.WrittenBookPredicate
  • 类型:public record
  • 包:net.minecraft.core.component.predicates
  • 源码路径:src/main/java/net/minecraft/core/component/predicates/WrittenBookPredicate.java
  • 起始行号:L17
  • 实现:SingleComponentItemPredicate
  • 职责:

    TODO

字段/常量

  • CODEC
    • 类型: Codec<WrittenBookPredicate>
    • 修饰符: public static final
    • 源码定位: L24
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.core.component.predicates.WrittenBookPredicate.PagePredicate
    • 类型: record
    • 修饰符: public
    • 源码定位: L56
    • 说明:

      TODO

构造器

方法

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

public DataComponentType<WrittenBookContent> componentType() @ L37

  • 方法名:componentType
  • 源码定位:L37
  • 返回类型:DataComponentType
  • 修饰符:public

参数:

说明:

TODO

public boolean matches(WrittenBookContent value) @ L42

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

参数:

  • value: WrittenBookContent

说明:

TODO

代码

public record WrittenBookPredicate(
    Optional<CollectionPredicate<Filterable<Component>, WrittenBookPredicate.PagePredicate>> pages,
    Optional<String> author,
    Optional<String> title,
    MinMaxBounds.Ints generation,
    Optional<Boolean> resolved
) implements SingleComponentItemPredicate<WrittenBookContent> {
    public static final Codec<WrittenBookPredicate> CODEC = RecordCodecBuilder.create(
        i -> i.group(
                CollectionPredicate.<Filterable<Component>, WrittenBookPredicate.PagePredicate>codec(WrittenBookPredicate.PagePredicate.CODEC)
                    .optionalFieldOf("pages")
                    .forGetter(WrittenBookPredicate::pages),
                Codec.STRING.optionalFieldOf("author").forGetter(WrittenBookPredicate::author),
                Codec.STRING.optionalFieldOf("title").forGetter(WrittenBookPredicate::title),
                MinMaxBounds.Ints.CODEC.optionalFieldOf("generation", MinMaxBounds.Ints.ANY).forGetter(WrittenBookPredicate::generation),
                Codec.BOOL.optionalFieldOf("resolved").forGetter(WrittenBookPredicate::resolved)
            )
            .apply(i, WrittenBookPredicate::new)
    );
 
    @Override
    public DataComponentType<WrittenBookContent> componentType() {
        return DataComponents.WRITTEN_BOOK_CONTENT;
    }
 
    public boolean matches(WrittenBookContent value) {
        if (this.author.isPresent() && !this.author.get().equals(value.author())) {
            return false;
        } else if (this.title.isPresent() && !this.title.get().equals(value.title().raw())) {
            return false;
        } else if (!this.generation.matches(value.generation())) {
            return false;
        } else {
            return this.resolved.isPresent() && this.resolved.get() != value.resolved()
                ? false
                : !this.pages.isPresent() || this.pages.get().test(value.pages());
        }
    }
 
    public record PagePredicate(Component contents) implements Predicate<Filterable<Component>> {
        public static final Codec<WrittenBookPredicate.PagePredicate> CODEC = ComponentSerialization.CODEC
            .xmap(WrittenBookPredicate.PagePredicate::new, WrittenBookPredicate.PagePredicate::contents);
 
        public boolean test(Filterable<Component> value) {
            return value.raw().equals(this.contents);
        }
    }
}

引用的其他类