/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.ImmutableMap * com.mojang.logging.LogUtils * org.slf4j.Logger */ package net.minecraft.core; import com.google.common.collect.ImmutableMap; import com.mojang.logging.LogUtils; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; import net.minecraft.core.HolderLookup; import net.minecraft.core.Registry; import net.minecraft.resources.ResourceKey; import org.slf4j.Logger; public interface RegistryAccess extends HolderLookup.Provider { public static final Logger LOGGER = LogUtils.getLogger(); public static final Frozen EMPTY = new ImmutableRegistryAccess(Map.of()).freeze(); public Optional> lookup(ResourceKey> var1); default public Registry lookupOrThrow(ResourceKey> name) { return this.lookup(name).orElseThrow(() -> new IllegalStateException("Missing registry: " + String.valueOf(name))); } public Stream> registries(); @Override default public Stream>> listRegistryKeys() { return this.registries().map(e -> e.key); } public static Frozen fromRegistryOfRegistries(final Registry> registries) { return new Frozen(){ public Optional> lookup(ResourceKey> registryKey) { Registry registry = registries; return registry.getOptional(registryKey); } @Override public Stream> registries() { return registries.entrySet().stream().map(RegistryEntry::fromMapEntry); } @Override public Frozen freeze() { return this; } }; } default public Frozen freeze() { class FrozenAccess extends ImmutableRegistryAccess implements Frozen { protected FrozenAccess(RegistryAccess this$0, Stream> entries) { super(entries); } } return new FrozenAccess(this, this.registries().map(RegistryEntry::freeze)); } public record RegistryEntry(ResourceKey> key, Registry value) { private static > RegistryEntry fromMapEntry(Map.Entry>, R> e) { return RegistryEntry.fromUntyped(e.getKey(), (Registry)e.getValue()); } private static RegistryEntry fromUntyped(ResourceKey> key, Registry value) { return new RegistryEntry(key, value); } private RegistryEntry freeze() { return new RegistryEntry(this.key, this.value.freeze()); } } public static class ImmutableRegistryAccess implements RegistryAccess { private final Map>, ? extends Registry> registries; public ImmutableRegistryAccess(List> registries) { this.registries = registries.stream().collect(Collectors.toUnmodifiableMap(Registry::key, v -> v)); } public ImmutableRegistryAccess(Map>, ? extends Registry> registries) { this.registries = Map.copyOf(registries); } public ImmutableRegistryAccess(Stream> entries) { this.registries = (Map)entries.collect(ImmutableMap.toImmutableMap(RegistryEntry::key, RegistryEntry::value)); } @Override public Optional> lookup(ResourceKey> registryKey) { return Optional.ofNullable(this.registries.get(registryKey)).map(r -> r); } @Override public Stream> registries() { return this.registries.entrySet().stream().map(RegistryEntry::fromMapEntry); } } public static interface Frozen extends RegistryAccess { } }