API Surface (2) Path createAndValidatePathToStructure(final Identifier id, final FileToIdConverter converter)
Path createAndValidatePathToStructure(final Identifier resourceLocation)
String literals (3) "Invalid file path '"
"Resource path '"
"' is not portable"
Code Graph: Dependencies (6) Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.
Full Source
TemplatePathFactory.java 37 lines · Minecraft 26.3 · verbatim Copy
1 package net.minecraft.world.level.levelgen.structure.templatesystem.loader;
2
3 import java.nio.file.Path;
4 import java.util.List;
5 import net.minecraft.IdentifierException;
6 import net.minecraft.resources.FileToIdConverter;
7 import net.minecraft.resources.Identifier;
8 import net.minecraft.server.packs.PackType;
9 import net.minecraft.util.FileUtil;
10
11 public class TemplatePathFactory {
12 private final Path sourceDir;
13
14 public TemplatePathFactory(final Path sourceDir, final PackType packType) {
15 this(sourceDir.resolve(packType.getDirectory()));
16 }
17
18 public TemplatePathFactory(final Path sourceDir) {
19 this.sourceDir = sourceDir;
20 }
21
22 public Path createAndValidatePathToStructure(final Identifier id, final FileToIdConverter converter) {
23 return this.createAndValidatePathToStructure(converter.idToFile(id));
24 }
25
26 public Path createAndValidatePathToStructure(final Identifier resourceLocation) {
27 Path namespacePath = this.sourceDir.resolve(resourceLocation.getNamespace());
28 List<String> decomposedPath = FileUtil.decomposePath(resourceLocation.getPath())
29 .getOrThrow(msg -> new IdentifierException("Invalid file path '" + resourceLocation + "': " + msg));
30 if (!decomposedPath.stream().allMatch(FileUtil::isPathPartPortable)) {
31 throw new IdentifierException("Resource path '" + resourceLocation + "' is not portable");
32 } else {
33 return FileUtil.resolvePath(namespacePath, decomposedPath);
34 }
35 }
36 }
37
Decompiled Minecraft 26.3 source of TemplatePathFactory (net/minecraft/world/level/levelgen/structure/templatesystem/loader/TemplatePathFactory.java) with Mojang official mappings, stored verbatim on the site.