/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.serialization.DynamicOps * com.mojang.serialization.Lifecycle */ package net.minecraft.core; import com.mojang.serialization.DynamicOps; import com.mojang.serialization.Lifecycle; import java.util.Map; import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; import net.minecraft.core.Holder; import net.minecraft.core.HolderGetter; import net.minecraft.core.HolderOwner; import net.minecraft.core.HolderSet; import net.minecraft.core.Registry; import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.TagKey; import net.minecraft.world.flag.FeatureElement; import net.minecraft.world.flag.FeatureFlagSet; public interface HolderLookup extends HolderGetter { public Stream> listElements(); default public Stream> listElementIds() { return this.listElements().map(Holder.Reference::key); } public Stream> listTags(); default public Stream> listTagIds() { return this.listTags().map(HolderSet.Named::key); } public static interface Provider extends HolderGetter.Provider { public Stream>> listRegistryKeys(); default public Stream> listRegistries() { return this.listRegistryKeys().map(resourceKey -> this.lookupOrThrow((ResourceKey)resourceKey)); } public Optional> lookup(ResourceKey> var1); default public RegistryLookup lookupOrThrow(ResourceKey> key) { return this.lookup(key).orElseThrow(() -> new IllegalStateException("Registry " + String.valueOf(key.identifier()) + " not found")); } default public RegistryOps createSerializationContext(DynamicOps parent) { return RegistryOps.create(parent, this); } public static Provider create(Stream> lookups) { final Map map = lookups.collect(Collectors.toUnmodifiableMap(RegistryLookup::key, e -> e)); return new Provider(){ @Override public Stream>> listRegistryKeys() { return map.keySet().stream(); } public Optional> lookup(ResourceKey> key) { return Optional.ofNullable((RegistryLookup)map.get(key)); } }; } default public Lifecycle allRegistriesLifecycle() { return this.listRegistries().map(RegistryLookup::registryLifecycle).reduce(Lifecycle.stable(), Lifecycle::add); } } public static interface RegistryLookup extends HolderLookup, HolderOwner { public ResourceKey> key(); public Lifecycle registryLifecycle(); default public RegistryLookup filterFeatures(FeatureFlagSet enabledFeatures) { if (FeatureElement.FILTERED_REGISTRIES.contains(this.key())) { return this.filterElements(t -> ((FeatureElement)t).isEnabled(enabledFeatures)); } return this; } default public RegistryLookup filterElements(final Predicate filter) { return new Delegate(){ @Override public RegistryLookup parent() { return this; } @Override public Optional> get(ResourceKey id) { return this.parent().get(id).filter(holder -> filter.test(holder.value())); } @Override public Stream> listElements() { return this.parent().listElements().filter(e -> filter.test(e.value())); } }; } public static interface Delegate extends RegistryLookup { public RegistryLookup parent(); @Override default public ResourceKey> key() { return this.parent().key(); } @Override default public Lifecycle registryLifecycle() { return this.parent().registryLifecycle(); } @Override default public Optional> get(ResourceKey id) { return this.parent().get(id); } @Override default public Stream> listElements() { return this.parent().listElements(); } @Override default public Optional> get(TagKey id) { return this.parent().get(id); } @Override default public Stream> listTags() { return this.parent().listTags(); } } } }