/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.util.Either * org.jspecify.annotations.Nullable */ package net.minecraft.core; import com.mojang.datafixers.util.Either; import java.util.Collection; import java.util.Optional; import java.util.Set; import java.util.function.Predicate; import java.util.stream.Stream; import net.minecraft.core.HolderOwner; import net.minecraft.resources.Identifier; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; import org.jspecify.annotations.Nullable; public interface Holder { public T value(); public boolean isBound(); public boolean is(Identifier var1); public boolean is(ResourceKey var1); public boolean is(Predicate> var1); public boolean is(TagKey var1); @Deprecated public boolean is(Holder var1); public Stream> tags(); public Either, T> unwrap(); public Optional> unwrapKey(); public Kind kind(); public boolean canSerializeIn(HolderOwner var1); default public String getRegisteredName() { return this.unwrapKey().map(key -> key.identifier().toString()).orElse("[unregistered]"); } public static Holder direct(T value) { return new Direct(value); } public record Direct(T value) implements Holder { @Override public boolean isBound() { return true; } @Override public boolean is(Identifier key) { return false; } @Override public boolean is(ResourceKey key) { return false; } @Override public boolean is(TagKey tag) { return false; } @Override public boolean is(Holder holder) { return this.value.equals(holder.value()); } @Override public boolean is(Predicate> predicate) { return false; } @Override public Either, T> unwrap() { return Either.right(this.value); } @Override public Optional> unwrapKey() { return Optional.empty(); } @Override public Kind kind() { return Kind.DIRECT; } @Override public String toString() { return "Direct{" + String.valueOf(this.value) + "}"; } @Override public boolean canSerializeIn(HolderOwner registry) { return true; } @Override public Stream> tags() { return Stream.of(new TagKey[0]); } } public static class Reference implements Holder { private final HolderOwner owner; private @Nullable Set> tags; private final Type type; private @Nullable ResourceKey key; private @Nullable T value; protected Reference(Type type, HolderOwner owner, @Nullable ResourceKey key, @Nullable T value) { this.owner = owner; this.type = type; this.key = key; this.value = value; } public static Reference createStandAlone(HolderOwner owner, ResourceKey key) { return new Reference(Type.STAND_ALONE, owner, key, null); } @Deprecated public static Reference createIntrusive(HolderOwner owner, @Nullable T value) { return new Reference(Type.INTRUSIVE, owner, null, value); } public ResourceKey key() { if (this.key == null) { throw new IllegalStateException("Trying to access unbound value '" + String.valueOf(this.value) + "' from registry " + String.valueOf(this.owner)); } return this.key; } @Override public T value() { if (this.value == null) { throw new IllegalStateException("Trying to access unbound value '" + String.valueOf(this.key) + "' from registry " + String.valueOf(this.owner)); } return this.value; } @Override public boolean is(Identifier key) { return this.key().identifier().equals(key); } @Override public boolean is(ResourceKey key) { return this.key() == key; } private Set> boundTags() { if (this.tags == null) { throw new IllegalStateException("Tags not bound"); } return this.tags; } @Override public boolean is(TagKey tag) { return this.boundTags().contains(tag); } @Override public boolean is(Holder holder) { return holder.is(this.key()); } @Override public boolean is(Predicate> predicate) { return predicate.test(this.key()); } @Override public boolean canSerializeIn(HolderOwner context) { return this.owner.canSerializeIn(context); } @Override public Either, T> unwrap() { return Either.left(this.key()); } @Override public Optional> unwrapKey() { return Optional.of(this.key()); } @Override public Kind kind() { return Kind.REFERENCE; } @Override public boolean isBound() { return this.key != null && this.value != null; } void bindKey(ResourceKey key) { if (this.key != null && key != this.key) { throw new IllegalStateException("Can't change holder key: existing=" + String.valueOf(this.key) + ", new=" + String.valueOf(key)); } this.key = key; } protected void bindValue(T value) { if (this.type == Type.INTRUSIVE && this.value != value) { throw new IllegalStateException("Can't change holder " + String.valueOf(this.key) + " value: existing=" + String.valueOf(this.value) + ", new=" + String.valueOf(value)); } this.value = value; } void bindTags(Collection> tags) { this.tags = Set.copyOf(tags); } @Override public Stream> tags() { return this.boundTags().stream(); } public String toString() { return "Reference{" + String.valueOf(this.key) + "=" + String.valueOf(this.value) + "}"; } protected static enum Type { STAND_ALONE, INTRUSIVE; } } public static enum Kind { REFERENCE, DIRECT; } }