package net.minecraft.advancements.critereon; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder.Instance; import java.util.List; import java.util.function.Predicate; public interface CollectionCountsPredicate> extends Predicate> { List> unpack(); static > Codec> codec(Codec

p_335836_) { return CollectionCountsPredicate.Entry.codec(p_335836_) .listOf() .xmap(CollectionCountsPredicate::of, CollectionCountsPredicate::unpack); } @SafeVarargs static > CollectionCountsPredicate of(CollectionCountsPredicate.Entry... p_332496_) { return of(List.of(p_332496_)); } static > CollectionCountsPredicate of(List> p_334665_) { return (CollectionCountsPredicate)(switch (p_334665_.size()) { case 0 -> new CollectionCountsPredicate.Zero(); case 1 -> new CollectionCountsPredicate.Single(p_334665_.getFirst()); default -> new CollectionCountsPredicate.Multiple(p_334665_); }); } public static record Entry>(P test, MinMaxBounds.Ints count) { public static > Codec> codec(Codec

p_334145_) { return RecordCodecBuilder.create( p_334567_ -> p_334567_.group( p_334145_.fieldOf("test").forGetter(CollectionCountsPredicate.Entry::test), MinMaxBounds.Ints.CODEC.fieldOf("count").forGetter(CollectionCountsPredicate.Entry::count) ) .apply(p_334567_, CollectionCountsPredicate.Entry::new) ); } public boolean test(Iterable p_329726_) { int i = 0; for (T t : p_329726_) { if (this.test.test(t)) { i++; } } return this.count.matches(i); } } public static record Multiple>(List> entries) implements CollectionCountsPredicate { public boolean test(Iterable p_329412_) { for (CollectionCountsPredicate.Entry entry : this.entries) { if (!entry.test(p_329412_)) { return false; } } return true; } @Override public List> unpack() { return this.entries; } } public static record Single>(CollectionCountsPredicate.Entry entry) implements CollectionCountsPredicate { public boolean test(Iterable p_333879_) { return this.entry.test(p_333879_); } @Override public List> unpack() { return List.of(this.entry); } } public static class Zero> implements CollectionCountsPredicate { public boolean test(Iterable p_329157_) { return true; } @Override public List> unpack() { return List.of(); } } }