VanillaPackResourcesBuilder.java
net.minecraft.server.packs.VanillaPackResourcesBuilder
信息
- 全限定名:net.minecraft.server.packs.VanillaPackResourcesBuilder
- 类型:public class
- 包:net.minecraft.server.packs
- 源码路径:src/main/java/net/minecraft/server/packs/VanillaPackResourcesBuilder.java
- 起始行号:L29
- 职责:
TODO
字段/常量
-
LOGGER- 类型:
Logger - 修饰符:
private static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
developmentConfig- 类型:
Consumer<VanillaPackResourcesBuilder> - 修饰符:
public static - 源码定位:
L31 - 说明:
TODO
- 类型:
-
ROOT_DIR_BY_TYPE- 类型:
Map<PackType,Path> - 修饰符:
private static final synchronized - 源码定位:
L32 - 说明:
TODO
- 类型:
-
rootPaths- 类型:
Set<Path> - 修饰符:
private final - 源码定位:
L60 - 说明:
TODO
- 类型:
-
pathsForType- 类型:
Map<PackType,Set<Path>> - 修饰符:
private final - 源码定位:
L61 - 说明:
TODO
- 类型:
-
metadata- 类型:
ResourceMetadata - 修饰符:
private - 源码定位:
L62 - 说明:
TODO
- 类型:
-
namespaces- 类型:
Set<String> - 修饰符:
private final - 源码定位:
L63 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
private boolean validateDirPath(Path path) @ L65
- 方法名:validateDirPath
- 源码定位:L65
- 返回类型:boolean
- 修饰符:private
参数:
- path: Path
说明:
TODO
private void pushRootPath(Path path) @ L75
- 方法名:pushRootPath
- 源码定位:L75
- 返回类型:void
- 修饰符:private
参数:
- path: Path
说明:
TODO
private void pushPathForType(PackType packType, Path path) @ L81
- 方法名:pushPathForType
- 源码定位:L81
- 返回类型:void
- 修饰符:private
参数:
- packType: PackType
- path: Path
说明:
TODO
public VanillaPackResourcesBuilder pushJarResources() @ L87
- 方法名:pushJarResources
- 源码定位:L87
- 返回类型:VanillaPackResourcesBuilder
- 修饰符:public
参数:
- 无
说明:
TODO
public VanillaPackResourcesBuilder pushClasspathResources(PackType packType, Class<?> source) @ L95
- 方法名:pushClasspathResources
- 源码定位:L95
- 返回类型:VanillaPackResourcesBuilder
- 修饰符:public
参数:
- packType: PackType
- source: Class<?>
说明:
TODO
public VanillaPackResourcesBuilder applyDevelopmentConfig() @ L121
- 方法名:applyDevelopmentConfig
- 源码定位:L121
- 返回类型:VanillaPackResourcesBuilder
- 修饰符:public
参数:
- 无
说明:
TODO
public VanillaPackResourcesBuilder pushUniversalPath(Path path) @ L126
- 方法名:pushUniversalPath
- 源码定位:L126
- 返回类型:VanillaPackResourcesBuilder
- 修饰符:public
参数:
- path: Path
说明:
TODO
public VanillaPackResourcesBuilder pushAssetPath(PackType packType, Path path) @ L136
- 方法名:pushAssetPath
- 源码定位:L136
- 返回类型:VanillaPackResourcesBuilder
- 修饰符:public
参数:
- packType: PackType
- path: Path
说明:
TODO
public VanillaPackResourcesBuilder setMetadata(ResourceMetadata metadata) @ L142
- 方法名:setMetadata
- 源码定位:L142
- 返回类型:VanillaPackResourcesBuilder
- 修饰符:public
参数:
- metadata: ResourceMetadata
说明:
TODO
public VanillaPackResourcesBuilder exposeNamespace(String... namespaces) @ L147
- 方法名:exposeNamespace
- 源码定位:L147
- 返回类型:VanillaPackResourcesBuilder
- 修饰符:public
参数:
- namespaces: String…
说明:
TODO
public VanillaPackResources build(PackLocationInfo location) @ L152
- 方法名:build
- 源码定位:L152
- 返回类型:VanillaPackResources
- 修饰符:public
参数:
- location: PackLocationInfo
说明:
TODO
private static List<Path> copyAndReverse(Collection<Path> input) @ L162
- 方法名:copyAndReverse
- 源码定位:L162
- 返回类型:List
- 修饰符:private static
参数:
- input: Collection
说明:
TODO
代码
public class VanillaPackResourcesBuilder {
private static final Logger LOGGER = LogUtils.getLogger();
public static Consumer<VanillaPackResourcesBuilder> developmentConfig = builder -> {};
private static final Map<PackType, Path> ROOT_DIR_BY_TYPE = Util.make(() -> {
synchronized (VanillaPackResources.class) {
Builder<PackType, Path> result = ImmutableMap.builder();
for (PackType type : PackType.values()) {
String probeName = "/" + type.getDirectory() + "/.mcassetsroot";
URL probeUrl = VanillaPackResources.class.getResource(probeName);
if (probeUrl == null) {
LOGGER.error("File {} does not exist in classpath", probeName);
} else {
try {
URI probeUri = probeUrl.toURI();
String scheme = probeUri.getScheme();
if (!"jar".equals(scheme) && !"file".equals(scheme)) {
LOGGER.warn("Assets URL '{}' uses unexpected schema", probeUri);
}
Path probePath = FileSystemUtil.safeGetPath(probeUri);
result.put(type, probePath.getParent());
} catch (Exception var12) {
LOGGER.error("Couldn't resolve path to vanilla assets", (Throwable)var12);
}
}
}
return result.build();
}
});
private final Set<Path> rootPaths = new LinkedHashSet<>();
private final Map<PackType, Set<Path>> pathsForType = new EnumMap<>(PackType.class);
private ResourceMetadata metadata = ResourceMetadata.EMPTY;
private final Set<String> namespaces = new HashSet<>();
private boolean validateDirPath(Path path) {
if (!Files.exists(path)) {
return false;
} else if (!Files.isDirectory(path)) {
throw new IllegalArgumentException("Path " + path.toAbsolutePath() + " is not directory");
} else {
return true;
}
}
private void pushRootPath(Path path) {
if (this.validateDirPath(path)) {
this.rootPaths.add(path);
}
}
private void pushPathForType(PackType packType, Path path) {
if (this.validateDirPath(path)) {
this.pathsForType.computeIfAbsent(packType, k -> new LinkedHashSet<>()).add(path);
}
}
public VanillaPackResourcesBuilder pushJarResources() {
ROOT_DIR_BY_TYPE.forEach((packType, path) -> {
this.pushRootPath(path.getParent());
this.pushPathForType(packType, path);
});
return this;
}
public VanillaPackResourcesBuilder pushClasspathResources(PackType packType, Class<?> source) {
Enumeration<URL> resources = null;
try {
resources = source.getClassLoader().getResources(packType.getDirectory() + "/");
} catch (IOException var8) {
}
while (resources != null && resources.hasMoreElements()) {
URL url = resources.nextElement();
try {
URI uri = url.toURI();
if ("file".equals(uri.getScheme())) {
Path assetsPath = Paths.get(uri);
this.pushRootPath(assetsPath.getParent());
this.pushPathForType(packType, assetsPath);
}
} catch (Exception var7) {
LOGGER.error("Failed to extract path from {}", url, var7);
}
}
return this;
}
public VanillaPackResourcesBuilder applyDevelopmentConfig() {
developmentConfig.accept(this);
return this;
}
public VanillaPackResourcesBuilder pushUniversalPath(Path path) {
this.pushRootPath(path);
for (PackType packType : PackType.values()) {
this.pushPathForType(packType, path.resolve(packType.getDirectory()));
}
return this;
}
public VanillaPackResourcesBuilder pushAssetPath(PackType packType, Path path) {
this.pushRootPath(path);
this.pushPathForType(packType, path);
return this;
}
public VanillaPackResourcesBuilder setMetadata(ResourceMetadata metadata) {
this.metadata = metadata;
return this;
}
public VanillaPackResourcesBuilder exposeNamespace(String... namespaces) {
this.namespaces.addAll(Arrays.asList(namespaces));
return this;
}
public VanillaPackResources build(PackLocationInfo location) {
return new VanillaPackResources(
location,
this.metadata,
Set.copyOf(this.namespaces),
copyAndReverse(this.rootPaths),
Util.makeEnumMap(PackType.class, packType -> copyAndReverse(this.pathsForType.getOrDefault(packType, Set.of())))
);
}
private static List<Path> copyAndReverse(Collection<Path> input) {
List<Path> paths = new ArrayList<>(input);
Collections.reverse(paths);
return List.copyOf(paths);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/方法调用 - 关联成员:
PackType.values()
- 引用位置:
-
- 引用位置:
构造调用/返回值 - 关联成员:
VanillaPackResources()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FileSystemUtil.safeGetPath()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.make(), Util.makeEnumMap()
- 引用位置: