CollectionCountsPredicate.java
net.minecraft.advancements.criterion.CollectionCountsPredicate
信息
- 全限定名:net.minecraft.advancements.criterion.CollectionCountsPredicate
- 类型:public interface
- 包:net.minecraft.advancements.criterion
- 源码路径:src/main/java/net/minecraft/advancements/criterion/CollectionCountsPredicate.java
- 起始行号:L8
- 继承:Predicate<Iterable<?extends T>>
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
-
net.minecraft.advancements.criterion.CollectionCountsPredicate.Entry- 类型:
record - 修饰符:
public - 源码定位:
L28 - 说明:
TODO
- 类型:
-
net.minecraft.advancements.criterion.CollectionCountsPredicate.Multiple- 类型:
record - 修饰符:
public - 源码定位:
L52 - 说明:
TODO
- 类型:
-
net.minecraft.advancements.criterion.CollectionCountsPredicate.Single- 类型:
record - 修饰符:
public - 源码定位:
L69 - 说明:
TODO
- 类型:
-
net.minecraft.advancements.criterion.CollectionCountsPredicate.Zero- 类型:
class - 修饰符:
public static - 源码定位:
L80 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
List<CollectionCountsPredicate.Entry<T,P>> unpack() @ L9
- 方法名:unpack
- 源码定位:L9
- 返回类型:List<CollectionCountsPredicate.Entry<T,P>>
- 修饰符:package-private
参数:
- 无
说明:
TODO
static <T,P extends Predicate<T>> Codec<CollectionCountsPredicate<T,P>> codec(Codec<P> elementCodec) @ L11
- 方法名:codec
- 源码定位:L11
- 返回类型:<T,P extends Predicate
> Codec<CollectionCountsPredicate<T,P>> - 修饰符:static
参数:
- elementCodec: Codec
说明:
TODO
static <T,P extends Predicate<T>> CollectionCountsPredicate<T,P> of(CollectionCountsPredicate.Entry<T,P>... predicates) @ L15
- 方法名:of
- 源码定位:L15
- 返回类型:<T,P extends Predicate
> CollectionCountsPredicate<T,P> - 修饰符:static
参数:
- predicates: CollectionCountsPredicate.Entry<T,P>…
说明:
TODO
static <T,P extends Predicate<T>> CollectionCountsPredicate<T,P> of(List<CollectionCountsPredicate.Entry<T,P>> predicates) @ L20
- 方法名:of
- 源码定位:L20
- 返回类型:<T,P extends Predicate
> CollectionCountsPredicate<T,P> - 修饰符:static
参数:
- predicates: List<CollectionCountsPredicate.Entry<T,P>>
说明:
TODO
代码
public interface CollectionCountsPredicate<T, P extends Predicate<T>> extends Predicate<Iterable<? extends T>> {
List<CollectionCountsPredicate.Entry<T, P>> unpack();
static <T, P extends Predicate<T>> Codec<CollectionCountsPredicate<T, P>> codec(Codec<P> elementCodec) {
return CollectionCountsPredicate.Entry.<T, P>codec(elementCodec).listOf().xmap(CollectionCountsPredicate::of, CollectionCountsPredicate::unpack);
}
@SafeVarargs
static <T, P extends Predicate<T>> CollectionCountsPredicate<T, P> of(CollectionCountsPredicate.Entry<T, P>... predicates) {
return of(List.of(predicates));
}
static <T, P extends Predicate<T>> CollectionCountsPredicate<T, P> of(List<CollectionCountsPredicate.Entry<T, P>> predicates) {
return (CollectionCountsPredicate<T, P>)(switch (predicates.size()) {
case 0 -> new CollectionCountsPredicate.Zero();
case 1 -> new CollectionCountsPredicate.Single(predicates.getFirst());
default -> new CollectionCountsPredicate.Multiple(predicates);
});
}
public record Entry<T, P extends Predicate<T>>(P test, MinMaxBounds.Ints count) {
public static <T, P extends Predicate<T>> Codec<CollectionCountsPredicate.Entry<T, P>> codec(Codec<P> elementCodec) {
return RecordCodecBuilder.create(
i -> i.group(
elementCodec.fieldOf("test").forGetter(CollectionCountsPredicate.Entry::test),
MinMaxBounds.Ints.CODEC.fieldOf("count").forGetter(CollectionCountsPredicate.Entry::count)
)
.apply(i, CollectionCountsPredicate.Entry::new)
);
}
public boolean test(Iterable<? extends T> values) {
int count = 0;
for (T value : values) {
if (this.test.test(value)) {
count++;
}
}
return this.count.matches(count);
}
}
public record Multiple<T, P extends Predicate<T>>(List<CollectionCountsPredicate.Entry<T, P>> entries) implements CollectionCountsPredicate<T, P> {
public boolean test(Iterable<? extends T> values) {
for (CollectionCountsPredicate.Entry<T, P> entry : this.entries) {
if (!entry.test(values)) {
return false;
}
}
return true;
}
@Override
public List<CollectionCountsPredicate.Entry<T, P>> unpack() {
return this.entries;
}
}
public record Single<T, P extends Predicate<T>>(CollectionCountsPredicate.Entry<T, P> entry) implements CollectionCountsPredicate<T, P> {
public boolean test(Iterable<? extends T> values) {
return this.entry.test(values);
}
@Override
public List<CollectionCountsPredicate.Entry<T, P>> unpack() {
return List.of(this.entry);
}
}
public static class Zero<T, P extends Predicate<T>> implements CollectionCountsPredicate<T, P> {
public boolean test(Iterable<? extends T> values) {
return true;
}
@Override
public List<CollectionCountsPredicate.Entry<T, P>> unpack() {
return List.of();
}
}
}引用的其他类
- 无