HolderLookup.java

net.minecraft.core.HolderLookup

信息

  • 全限定名:net.minecraft.core.HolderLookup
  • 类型:public interface
  • 包:net.minecraft.core
  • 源码路径:src/main/java/net/minecraft/core/HolderLookup.java
  • 起始行号:L17
  • 继承:HolderGetter
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

  • net.minecraft.core.HolderLookup.Provider

    • 类型: interface
    • 修饰符: public
    • 源码定位: L30
    • 说明:

      TODO

  • net.minecraft.core.HolderLookup.RegistryLookup

    • 类型: interface
    • 修饰符: public
    • 源码定位: L70
    • 说明:

      TODO

  • net.minecraft.core.HolderLookup.RegistryLookup.Delegate

    • 类型: interface
    • 修饰符: public
    • 源码定位: L102
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

Stream<Holder.Reference<T>> listElements() @ L18

  • 方法名:listElements
  • 源码定位:L18
  • 返回类型:Stream<Holder.Reference>
  • 修饰符:package-private

参数:

说明:

TODO

default Stream<ResourceKey<T>> listElementIds() @ L20

  • 方法名:listElementIds
  • 源码定位:L20
  • 返回类型:Stream<ResourceKey>
  • 修饰符:default

参数:

说明:

TODO

Stream<HolderSet.Named<T>> listTags() @ L24

  • 方法名:listTags
  • 源码定位:L24
  • 返回类型:Stream<HolderSet.Named>
  • 修饰符:package-private

参数:

说明:

TODO

default Stream<TagKey<T>> listTagIds() @ L26

  • 方法名:listTagIds
  • 源码定位:L26
  • 返回类型:Stream<TagKey>
  • 修饰符:default

参数:

说明:

TODO

代码

public interface HolderLookup<T> extends HolderGetter<T> {
    Stream<Holder.Reference<T>> listElements();
 
    default Stream<ResourceKey<T>> listElementIds() {
        return this.listElements().map(Holder.Reference::key);
    }
 
    Stream<HolderSet.Named<T>> listTags();
 
    default Stream<TagKey<T>> listTagIds() {
        return this.listTags().map(HolderSet.Named::key);
    }
 
    public interface Provider extends HolderGetter.Provider {
        Stream<ResourceKey<? extends Registry<?>>> listRegistryKeys();
 
        default Stream<HolderLookup.RegistryLookup<?>> listRegistries() {
            return this.listRegistryKeys().map(this::lookupOrThrow);
        }
 
        @Override
        <T> Optional<? extends HolderLookup.RegistryLookup<T>> lookup(final ResourceKey<? extends Registry<? extends T>> key);
 
        default <T> HolderLookup.RegistryLookup<T> lookupOrThrow(ResourceKey<? extends Registry<? extends T>> key) {
            return this.lookup(key).orElseThrow(() -> new IllegalStateException("Registry " + key.identifier() + " not found"));
        }
 
        default <V> RegistryOps<V> createSerializationContext(DynamicOps<V> parent) {
            return RegistryOps.create(parent, this);
        }
 
        static HolderLookup.Provider create(Stream<HolderLookup.RegistryLookup<?>> lookups) {
            final Map<ResourceKey<? extends Registry<?>>, HolderLookup.RegistryLookup<?>> map = lookups.collect(
                Collectors.toUnmodifiableMap(HolderLookup.RegistryLookup::key, e -> e)
            );
            return new HolderLookup.Provider() {
                @Override
                public Stream<ResourceKey<? extends Registry<?>>> listRegistryKeys() {
                    return map.keySet().stream();
                }
 
                @Override
                public <T> Optional<HolderLookup.RegistryLookup<T>> lookup(ResourceKey<? extends Registry<? extends T>> key) {
                    return Optional.ofNullable((HolderLookup.RegistryLookup<T>)map.get(key));
                }
            };
        }
 
        default Lifecycle allRegistriesLifecycle() {
            return this.listRegistries().map(HolderLookup.RegistryLookup::registryLifecycle).reduce(Lifecycle.stable(), Lifecycle::add);
        }
    }
 
    public interface RegistryLookup<T> extends HolderLookup<T>, HolderOwner<T> {
        ResourceKey<? extends Registry<? extends T>> key();
 
        Lifecycle registryLifecycle();
 
        default HolderLookup.RegistryLookup<T> filterFeatures(FeatureFlagSet enabledFeatures) {
            return FeatureElement.FILTERED_REGISTRIES.contains(this.key()) ? this.filterElements(t -> ((FeatureElement)t).isEnabled(enabledFeatures)) : this;
        }
 
        default HolderLookup.RegistryLookup<T> filterElements(Predicate<T> filter) {
            return new HolderLookup.RegistryLookup.Delegate<T>() {
                {
                    Objects.requireNonNull(RegistryLookup.this);
                }
 
                @Override
                public HolderLookup.RegistryLookup<T> parent() {
                    return RegistryLookup.this;
                }
 
                @Override
                public Optional<Holder.Reference<T>> get(ResourceKey<T> id) {
                    return this.parent().get(id).filter(holder -> filter.test(holder.value()));
                }
 
                @Override
                public Stream<Holder.Reference<T>> listElements() {
                    return this.parent().listElements().filter(e -> filter.test(e.value()));
                }
            };
        }
 
        public interface Delegate<T> extends HolderLookup.RegistryLookup<T> {
            HolderLookup.RegistryLookup<T> parent();
 
            @Override
            default ResourceKey<? extends Registry<? extends T>> key() {
                return this.parent().key();
            }
 
            @Override
            default Lifecycle registryLifecycle() {
                return this.parent().registryLifecycle();
            }
 
            @Override
            default Optional<Holder.Reference<T>> get(ResourceKey<T> id) {
                return this.parent().get(id);
            }
 
            @Override
            default Stream<Holder.Reference<T>> listElements() {
                return this.parent().listElements();
            }
 
            @Override
            default Optional<HolderSet.Named<T>> get(TagKey<T> id) {
                return this.parent().get(id);
            }
 
            @Override
            default Stream<HolderSet.Named<T>> listTags() {
                return this.parent().listTags();
            }
        }
    }
}

引用的其他类