/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.datafixers.DataFixUtils * com.mojang.serialization.Codec * com.mojang.serialization.DataResult * com.mojang.serialization.DynamicOps * com.mojang.serialization.Keyable * com.mojang.serialization.Lifecycle * org.jspecify.annotations.Nullable */ package net.minecraft.core; import com.mojang.datafixers.DataFixUtils; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; import com.mojang.serialization.DynamicOps; import com.mojang.serialization.Keyable; import com.mojang.serialization.Lifecycle; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Stream; import java.util.stream.StreamSupport; import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderSet; import net.minecraft.core.IdMap; import net.minecraft.core.RegistrationInfo; import net.minecraft.core.WritableRegistry; import net.minecraft.resources.Identifier; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; import net.minecraft.tags.TagLoader; import net.minecraft.util.ExtraCodecs; import net.minecraft.util.RandomSource; import org.jspecify.annotations.Nullable; public interface Registry extends IdMap, Keyable, HolderLookup.RegistryLookup { @Override public ResourceKey> key(); default public Codec byNameCodec() { return this.referenceHolderWithLifecycle().flatComapMap(Holder.Reference::value, value -> this.safeCastToReference(this.wrapAsHolder(value))); } default public Codec> holderByNameCodec() { return this.referenceHolderWithLifecycle().flatComapMap(holder -> holder, this::safeCastToReference); } private Codec> referenceHolderWithLifecycle() { Codec referenceCodec = Identifier.CODEC.comapFlatMap(name -> this.get((Identifier)name).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "Unknown registry key in " + String.valueOf(this.key()) + ": " + String.valueOf(name))), holder -> holder.key().identifier()); return ExtraCodecs.overrideLifecycle(referenceCodec, e -> this.registrationInfo(e.key()).map(RegistrationInfo::lifecycle).orElse(Lifecycle.experimental())); } private DataResult> safeCastToReference(Holder holder) { DataResult dataResult; if (holder instanceof Holder.Reference) { Holder.Reference reference = (Holder.Reference)holder; dataResult = DataResult.success((Object)reference); } else { dataResult = DataResult.error(() -> "Unregistered holder in " + String.valueOf(this.key()) + ": " + String.valueOf(holder)); } return dataResult; } default public Stream keys(DynamicOps ops) { return this.keySet().stream().map(k -> ops.createString(k.toString())); } public @Nullable Identifier getKey(T var1); public Optional> getResourceKey(T var1); @Override public int getId(@Nullable T var1); public @Nullable T getValue(@Nullable ResourceKey var1); public @Nullable T getValue(@Nullable Identifier var1); public Optional registrationInfo(ResourceKey var1); default public Optional getOptional(@Nullable Identifier key) { return Optional.ofNullable(this.getValue(key)); } default public Optional getOptional(@Nullable ResourceKey key) { return Optional.ofNullable(this.getValue(key)); } public Optional> getAny(); default public T getValueOrThrow(ResourceKey key) { T value = this.getValue(key); if (value == null) { throw new IllegalStateException("Missing key in " + String.valueOf(this.key()) + ": " + String.valueOf(key)); } return value; } public Set keySet(); public Set, T>> entrySet(); public Set> registryKeySet(); public Optional> getRandom(RandomSource var1); default public Stream stream() { return StreamSupport.stream(this.spliterator(), false); } public boolean containsKey(Identifier var1); public boolean containsKey(ResourceKey var1); public static T register(Registry registry, String name, T value) { return Registry.register(registry, Identifier.parse(name), value); } public static T register(Registry registry, Identifier location, T value) { return Registry.register(registry, ResourceKey.create(registry.key(), location), value); } public static T register(Registry registry, ResourceKey key, T value) { ((WritableRegistry)registry).register(key, value, RegistrationInfo.BUILT_IN); return value; } public static Holder.Reference registerForHolder(Registry registry, ResourceKey key, T value) { return ((WritableRegistry)registry).register(key, value, RegistrationInfo.BUILT_IN); } public static Holder.Reference registerForHolder(Registry registry, Identifier location, T value) { return Registry.registerForHolder(registry, ResourceKey.create(registry.key(), location), value); } public Registry freeze(); public Holder.Reference createIntrusiveHolder(T var1); public Optional> get(int var1); public Optional> get(Identifier var1); public Holder wrapAsHolder(T var1); default public Iterable> getTagOrEmpty(TagKey id) { return (Iterable)DataFixUtils.orElse((Optional)this.get(id), List.of()); } public Stream> getTags(); default public IdMap> asHolderIdMap() { return new IdMap>(){ @Override public int getId(Holder thing) { return Registry.this.getId(thing.value()); } @Override public @Nullable Holder byId(int id) { return Registry.this.get(id).orElse(null); } @Override public int size() { return Registry.this.size(); } @Override public Iterator> iterator() { return Registry.this.listElements().map(e -> e).iterator(); } }; } public PendingTags prepareTagReload(TagLoader.LoadResult var1); public static interface PendingTags { public ResourceKey> key(); public HolderLookup.RegistryLookup lookup(); public void apply(); public int size(); } }