VanillaPackResources.java
net.minecraft.server.packs.VanillaPackResources
信息
- 全限定名:net.minecraft.server.packs.VanillaPackResources
- 类型:public class
- 包:net.minecraft.server.packs
- 源码路径:src/main/java/net/minecraft/server/packs/VanillaPackResources.java
- 起始行号:L23
- 实现:PackResources
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
-
location- 类型:
PackLocationInfo - 修饰符:
private final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
builtInMetadata- 类型:
ResourceMetadata - 修饰符:
private final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
resourceMetadata- 类型:
ResourceMetadata - 修饰符:
private - 源码定位:
L27 - 说明:
TODO
- 类型:
-
namespaces- 类型:
Set<String> - 修饰符:
private final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
rootPaths- 类型:
List<Path> - 修饰符:
private final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
pathsForType- 类型:
Map<PackType,List<Path>> - 修饰符:
private final - 源码定位:
L30 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
VanillaPackResources(PackLocationInfo location, ResourceMetadata metadata, Set<String> namespaces, List<Path> rootPaths, Map<PackType,List<Path>> pathsForType) @ L32
- 构造器名:VanillaPackResources
- 源码定位:L32
- 修饰符:package-private
参数:
- location: PackLocationInfo
- metadata: ResourceMetadata
- namespaces: Set
- rootPaths: List
- pathsForType: Map<PackType,List
>
说明:
TODO
方法
下面的方法块按源码顺序生成。
public IoSupplier<InputStream> getRootResource(String... path) @ L42
- 方法名:getRootResource
- 源码定位:L42
- 返回类型:IoSupplier
- 修饰符:public
参数:
- path: String…
说明:
TODO
public void listRawPaths(PackType type, Identifier resource, Consumer<Path> output) @ L57
- 方法名:listRawPaths
- 源码定位:L57
- 返回类型:void
- 修饰符:public
参数:
- type: PackType
- resource: Identifier
- output: Consumer
说明:
TODO
public void listResources(PackType type, String namespace, String directory, PackResources.ResourceOutput output) @ L68
- 方法名:listResources
- 源码定位:L68
- 返回类型:void
- 修饰符:public
参数:
- type: PackType
- namespace: String
- directory: String
- output: PackResources.ResourceOutput
说明:
TODO
private static void getResources(PackResources.ResourceOutput result, String namespace, Path root, List<String> directory) @ L93
- 方法名:getResources
- 源码定位:L93
- 返回类型:void
- 修饰符:private static
参数:
- result: PackResources.ResourceOutput
- namespace: String
- root: Path
- directory: List
说明:
TODO
public IoSupplier<InputStream> getResource(PackType type, Identifier location) @ L98
- 方法名:getResource
- 源码定位:L98
- 返回类型:IoSupplier
- 修饰符:public
参数:
- type: PackType
- location: Identifier
说明:
TODO
public Set<String> getNamespaces(PackType type) @ L117
- 方法名:getNamespaces
- 源码定位:L117
- 返回类型:Set
- 修饰符:public
参数:
- type: PackType
说明:
TODO
public <T> T getMetadataSection(MetadataSectionType<T> metadataSerializer) @ L122
- 方法名:getMetadataSection
- 源码定位:L122
- 返回类型:
T - 修饰符:public
参数:
- metadataSerializer: MetadataSectionType
说明:
TODO
public PackLocationInfo location() @ L140
- 方法名:location
- 源码定位:L140
- 返回类型:PackLocationInfo
- 修饰符:public
参数:
- 无
说明:
TODO
public void close() @ L145
- 方法名:close
- 源码定位:L145
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public ResourceProvider asProvider() @ L149
- 方法名:asProvider
- 源码定位:L149
- 返回类型:ResourceProvider
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class VanillaPackResources implements PackResources {
private static final Logger LOGGER = LogUtils.getLogger();
private final PackLocationInfo location;
private final ResourceMetadata builtInMetadata;
private @Nullable ResourceMetadata resourceMetadata;
private final Set<String> namespaces;
private final List<Path> rootPaths;
private final Map<PackType, List<Path>> pathsForType;
VanillaPackResources(
PackLocationInfo location, ResourceMetadata metadata, Set<String> namespaces, List<Path> rootPaths, Map<PackType, List<Path>> pathsForType
) {
this.location = location;
this.builtInMetadata = metadata;
this.namespaces = namespaces;
this.rootPaths = rootPaths;
this.pathsForType = pathsForType;
}
@Override
public @Nullable IoSupplier<InputStream> getRootResource(String... path) {
FileUtil.validatePath(path);
List<String> pathList = List.of(path);
for (Path rootPath : this.rootPaths) {
Path pathInRoot = FileUtil.resolvePath(rootPath, pathList);
if (Files.exists(pathInRoot) && PathPackResources.validatePath(pathInRoot)) {
return IoSupplier.create(pathInRoot);
}
}
return null;
}
public void listRawPaths(PackType type, Identifier resource, Consumer<Path> output) {
FileUtil.decomposePath(resource.getPath()).ifSuccess(decomposedPath -> {
String namespace = resource.getNamespace();
for (Path typePath : this.pathsForType.get(type)) {
Path namespacedPath = typePath.resolve(namespace);
output.accept(FileUtil.resolvePath(namespacedPath, (List<String>)decomposedPath));
}
}).ifError(error -> LOGGER.error("Invalid path {}: {}", resource, error.message()));
}
@Override
public void listResources(PackType type, String namespace, String directory, PackResources.ResourceOutput output) {
FileUtil.decomposePath(directory).ifSuccess(decomposedPath -> {
List<Path> paths = this.pathsForType.get(type);
int pathsSize = paths.size();
if (pathsSize == 1) {
getResources(output, namespace, paths.get(0), (List<String>)decomposedPath);
} else if (pathsSize > 1) {
Map<Identifier, IoSupplier<InputStream>> resources = new HashMap<>();
for (int i = 0; i < pathsSize - 1; i++) {
getResources(resources::putIfAbsent, namespace, paths.get(i), (List<String>)decomposedPath);
}
Path lastPath = paths.get(pathsSize - 1);
if (resources.isEmpty()) {
getResources(output, namespace, lastPath, (List<String>)decomposedPath);
} else {
getResources(resources::putIfAbsent, namespace, lastPath, (List<String>)decomposedPath);
resources.forEach(output);
}
}
}).ifError(error -> LOGGER.error("Invalid path {}: {}", directory, error.message()));
}
private static void getResources(PackResources.ResourceOutput result, String namespace, Path root, List<String> directory) {
Path namespaceDir = root.resolve(namespace);
PathPackResources.listPath(namespace, namespaceDir, directory, result);
}
@Override
public @Nullable IoSupplier<InputStream> getResource(PackType type, Identifier location) {
return FileUtil.decomposePath(location.getPath()).mapOrElse(decomposedPath -> {
String namespace = location.getNamespace();
for (Path typePath : this.pathsForType.get(type)) {
Path resource = FileUtil.resolvePath(typePath.resolve(namespace), (List<String>)decomposedPath);
if (Files.exists(resource) && PathPackResources.validatePath(resource)) {
return IoSupplier.create(resource);
}
}
return null;
}, error -> {
LOGGER.error("Invalid path {}: {}", location, error.message());
return null;
});
}
@Override
public Set<String> getNamespaces(PackType type) {
return this.namespaces;
}
@Override
public <T> @Nullable T getMetadataSection(MetadataSectionType<T> metadataSerializer) {
try {
if (this.resourceMetadata == null) {
this.resourceMetadata = AbstractPackResources.loadMetadata(this);
}
Optional<T> section = this.resourceMetadata.getSection(metadataSerializer);
if (section.isPresent()) {
return section.get();
}
} catch (Exception var3) {
LOGGER.warn("Failed to parse vanilla pack metadata", (Throwable)var3);
}
return this.builtInMetadata.getSection(metadataSerializer).orElse(null);
}
@Override
public PackLocationInfo location() {
return this.location;
}
@Override
public void close() {
}
public ResourceProvider asProvider() {
return location -> Optional.ofNullable(this.getResource(PackType.CLIENT_RESOURCES, location)).map(s -> new Resource(this, (IoSupplier<InputStream>)s));
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
AbstractPackResources.loadMetadata()
- 引用位置:
-
- 引用位置:
参数/字段/返回值
- 引用位置:
-
- 引用位置:
参数/实现
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
PathPackResources.listPath(), PathPackResources.validatePath()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用/返回值 - 关联成员:
IoSupplier.create()
- 引用位置:
-
- 引用位置:
构造调用 - 关联成员:
Resource()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FileUtil.decomposePath(), FileUtil.resolvePath(), FileUtil.validatePath()
- 引用位置: