/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.annotations.VisibleForTesting * com.mojang.datafixers.util.Either * org.jspecify.annotations.Nullable */ package net.minecraft.core; import com.google.common.annotations.VisibleForTesting; import com.mojang.datafixers.util.Either; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.Optional; import java.util.Set; import java.util.Spliterator; import java.util.function.Function; import java.util.stream.Stream; import net.minecraft.core.Holder; import net.minecraft.core.HolderOwner; import net.minecraft.tags.TagKey; import net.minecraft.util.RandomSource; import net.minecraft.util.Util; import org.jspecify.annotations.Nullable; public interface HolderSet extends Iterable> { public Stream> stream(); public int size(); public boolean isBound(); public Either, List>> unwrap(); public Optional> getRandomElement(RandomSource var1); public Holder get(int var1); public boolean contains(Holder var1); public boolean canSerializeIn(HolderOwner var1); public Optional> unwrapKey(); @Deprecated @VisibleForTesting public static Named emptyNamed(HolderOwner owner, TagKey key) { return new Named((HolderOwner)owner, (TagKey)key){ @Override protected List> contents() { throw new UnsupportedOperationException("Tag " + String.valueOf(this.key()) + " can't be dereferenced during construction"); } }; } public static HolderSet empty() { return Direct.EMPTY; } @SafeVarargs public static Direct direct(Holder ... values) { return new Direct(List.of(values)); } public static Direct direct(List> values) { return new Direct(List.copyOf(values)); } @SafeVarargs public static Direct direct(Function> holderGetter, E ... elements) { return HolderSet.direct(Stream.of(elements).map(holderGetter).toList()); } public static Direct direct(Function> holderGetter, Collection elements) { return HolderSet.direct(elements.stream().map(holderGetter).toList()); } public static final class Direct extends ListBacked { private static final Direct EMPTY = new Direct(List.of()); private final List> contents; private @Nullable Set> contentsSet; private Direct(List> contents) { this.contents = contents; } @Override protected List> contents() { return this.contents; } @Override public boolean isBound() { return true; } @Override public Either, List>> unwrap() { return Either.right(this.contents); } @Override public Optional> unwrapKey() { return Optional.empty(); } @Override public boolean contains(Holder value) { if (this.contentsSet == null) { this.contentsSet = Set.copyOf(this.contents); } return this.contentsSet.contains(value); } public String toString() { return "DirectSet[" + String.valueOf(this.contents) + "]"; } /* * Enabled force condition propagation * Lifted jumps to return sites */ public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof Direct)) return false; Direct direct = (Direct)obj; if (!this.contents.equals(direct.contents)) return false; return true; } public int hashCode() { return this.contents.hashCode(); } } public static class Named extends ListBacked { private final HolderOwner owner; private final TagKey key; private @Nullable List> contents; Named(HolderOwner owner, TagKey key) { this.owner = owner; this.key = key; } void bind(List> contents) { this.contents = List.copyOf(contents); } public TagKey key() { return this.key; } @Override protected List> contents() { if (this.contents == null) { throw new IllegalStateException("Trying to access unbound tag '" + String.valueOf(this.key) + "' from registry " + String.valueOf(this.owner)); } return this.contents; } @Override public boolean isBound() { return this.contents != null; } @Override public Either, List>> unwrap() { return Either.left(this.key); } @Override public Optional> unwrapKey() { return Optional.of(this.key); } @Override public boolean contains(Holder value) { return value.is(this.key); } public String toString() { return "NamedSet(" + String.valueOf(this.key) + ")[" + String.valueOf(this.contents) + "]"; } @Override public boolean canSerializeIn(HolderOwner context) { return this.owner.canSerializeIn(context); } } public static abstract class ListBacked implements HolderSet { protected abstract List> contents(); @Override public int size() { return this.contents().size(); } @Override public Spliterator> spliterator() { return this.contents().spliterator(); } @Override public Iterator> iterator() { return this.contents().iterator(); } @Override public Stream> stream() { return this.contents().stream(); } @Override public Optional> getRandomElement(RandomSource random) { return Util.getRandomSafe(this.contents(), random); } @Override public Holder get(int index) { return this.contents().get(index); } @Override public boolean canSerializeIn(HolderOwner owner) { return true; } } }