CompositePackResources.java

net.minecraft.server.packs.CompositePackResources

信息

  • 全限定名:net.minecraft.server.packs.CompositePackResources
  • 类型:public class
  • 包:net.minecraft.server.packs
  • 源码路径:src/main/java/net/minecraft/server/packs/CompositePackResources.java
  • 起始行号:L17
  • 实现:PackResources
  • 职责:

    TODO

字段/常量

  • primaryPackResources

    • 类型: PackResources
    • 修饰符: private final
    • 源码定位: L18
    • 说明:

      TODO

  • packResourcesStack

    • 类型: List<PackResources>
    • 修饰符: private final
    • 源码定位: L19
    • 说明:

      TODO

内部类/嵌套类型

构造器

public CompositePackResources(PackResources primaryPackResources, List<PackResources> overlayPackResources) @ L21

  • 构造器名:CompositePackResources
  • 源码定位:L21
  • 修饰符:public

参数:

  • primaryPackResources: PackResources
  • overlayPackResources: List

说明:

TODO

方法

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

public IoSupplier<InputStream> getRootResource(String... path) @ L29

  • 方法名:getRootResource
  • 源码定位:L29
  • 返回类型:IoSupplier
  • 修饰符:public

参数:

  • path: String…

说明:

TODO

public IoSupplier<InputStream> getResource(PackType type, Identifier location) @ L34

  • 方法名:getResource
  • 源码定位:L34
  • 返回类型:IoSupplier
  • 修饰符:public

参数:

  • type: PackType
  • location: Identifier

说明:

TODO

public void listResources(PackType type, String namespace, String directory, PackResources.ResourceOutput output) @ L46

  • 方法名:listResources
  • 源码定位:L46
  • 返回类型:void
  • 修饰符:public

参数:

  • type: PackType
  • namespace: String
  • directory: String
  • output: PackResources.ResourceOutput

说明:

TODO

public Set<String> getNamespaces(PackType type) @ L57

  • 方法名:getNamespaces
  • 源码定位:L57
  • 返回类型:Set
  • 修饰符:public

参数:

  • type: PackType

说明:

TODO

public <T> T getMetadataSection(MetadataSectionType<T> metadataSerializer) @ L68

  • 方法名:getMetadataSection
  • 源码定位:L68
  • 返回类型: T
  • 修饰符:public

参数:

  • metadataSerializer: MetadataSectionType

说明:

TODO

public PackLocationInfo location() @ L73

  • 方法名:location
  • 源码定位:L73
  • 返回类型:PackLocationInfo
  • 修饰符:public

参数:

说明:

TODO

public void close() @ L78

  • 方法名:close
  • 源码定位:L78
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

代码

public class CompositePackResources implements PackResources {
    private final PackResources primaryPackResources;
    private final List<PackResources> packResourcesStack;
 
    public CompositePackResources(PackResources primaryPackResources, List<PackResources> overlayPackResources) {
        this.primaryPackResources = primaryPackResources;
        List<PackResources> stack = new ArrayList<>(overlayPackResources.size() + 1);
        stack.addAll(Lists.reverse(overlayPackResources));
        stack.add(primaryPackResources);
        this.packResourcesStack = List.copyOf(stack);
    }
 
    @Override
    public @Nullable IoSupplier<InputStream> getRootResource(String... path) {
        return this.primaryPackResources.getRootResource(path);
    }
 
    @Override
    public @Nullable IoSupplier<InputStream> getResource(PackType type, Identifier location) {
        for (PackResources packResources : this.packResourcesStack) {
            IoSupplier<InputStream> resource = packResources.getResource(type, location);
            if (resource != null) {
                return resource;
            }
        }
 
        return null;
    }
 
    @Override
    public void listResources(PackType type, String namespace, String directory, PackResources.ResourceOutput output) {
        Map<Identifier, IoSupplier<InputStream>> result = new HashMap<>();
 
        for (PackResources packResources : this.packResourcesStack) {
            packResources.listResources(type, namespace, directory, result::putIfAbsent);
        }
 
        result.forEach(output);
    }
 
    @Override
    public Set<String> getNamespaces(PackType type) {
        Set<String> result = new HashSet<>();
 
        for (PackResources overlayPackResource : this.packResourcesStack) {
            result.addAll(overlayPackResource.getNamespaces(type));
        }
 
        return result;
    }
 
    @Override
    public <T> @Nullable T getMetadataSection(MetadataSectionType<T> metadataSerializer) throws IOException {
        return this.primaryPackResources.getMetadataSection(metadataSerializer);
    }
 
    @Override
    public PackLocationInfo location() {
        return this.primaryPackResources.location();
    }
 
    @Override
    public void close() {
        this.packResourcesStack.forEach(PackResources::close);
    }
}

引用的其他类