/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.Sets * com.google.common.collect.Sets$SetView * com.mojang.serialization.Codec * com.mojang.serialization.DataResult * it.unimi.dsi.fastutil.objects.ObjectOpenHashSet */ package net.minecraft.advancements; import com.google.common.collect.Sets; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import java.util.Collection; import java.util.List; import java.util.Set; import java.util.function.Predicate; import net.minecraft.network.FriendlyByteBuf; public record AdvancementRequirements(List> requirements) { public static final Codec CODEC = Codec.STRING.listOf().listOf().xmap(AdvancementRequirements::new, AdvancementRequirements::requirements); public static final AdvancementRequirements EMPTY = new AdvancementRequirements(List.of()); public AdvancementRequirements(FriendlyByteBuf input) { this(input.readList(in -> in.readList(FriendlyByteBuf::readUtf))); } public void write(FriendlyByteBuf output) { output.writeCollection(this.requirements, (out, set) -> out.writeCollection(set, FriendlyByteBuf::writeUtf)); } public static AdvancementRequirements allOf(Collection criteria) { return new AdvancementRequirements(criteria.stream().map(List::of).toList()); } public static AdvancementRequirements anyOf(Collection criteria) { return new AdvancementRequirements(List.of(List.copyOf(criteria))); } public int size() { return this.requirements.size(); } public boolean test(Predicate predicate) { if (this.requirements.isEmpty()) { return false; } for (List set : this.requirements) { if (AdvancementRequirements.anyMatch(set, predicate)) continue; return false; } return true; } public int count(Predicate predicate) { int count = 0; for (List set : this.requirements) { if (!AdvancementRequirements.anyMatch(set, predicate)) continue; ++count; } return count; } private static boolean anyMatch(List criteria, Predicate predicate) { for (String criterion : criteria) { if (!predicate.test(criterion)) continue; return true; } return false; } public DataResult validate(Set expectedCriteria) { ObjectOpenHashSet referencedCriteria = new ObjectOpenHashSet(); for (List set : this.requirements) { if (set.isEmpty() && expectedCriteria.isEmpty()) { return DataResult.error(() -> "Requirement entry cannot be empty"); } referencedCriteria.addAll(set); } if (!expectedCriteria.equals(referencedCriteria)) { Sets.SetView missingCriteria = Sets.difference(expectedCriteria, (Set)referencedCriteria); Sets.SetView unknownCriteria = Sets.difference((Set)referencedCriteria, expectedCriteria); return DataResult.error(() -> AdvancementRequirements.lambda$validate$3((Set)missingCriteria, (Set)unknownCriteria)); } return DataResult.success((Object)this); } public boolean isEmpty() { return this.requirements.isEmpty(); } @Override public String toString() { return this.requirements.toString(); } public Set names() { ObjectOpenHashSet names = new ObjectOpenHashSet(); for (List set : this.requirements) { names.addAll(set); } return names; } private static /* synthetic */ String lambda$validate$3(Set missingCriteria, Set unknownCriteria) { return "Advancement completion requirements did not exactly match specified criteria. Missing: " + String.valueOf(missingCriteria) + ". Unknown: " + String.valueOf(unknownCriteria); } public static interface Strategy { public static final Strategy AND = AdvancementRequirements::allOf; public static final Strategy OR = AdvancementRequirements::anyOf; public AdvancementRequirements create(Collection var1); } }