diff --git a/modules/data/src/main/java/io/github/fabricators_of_create/porting_lib/resources/ModPathPackResources.java b/modules/data/src/main/java/io/github/fabricators_of_create/porting_lib/resources/ModPathPackResources.java new file mode 100644 index 000000000..407b3f686 --- /dev/null +++ b/modules/data/src/main/java/io/github/fabricators_of_create/porting_lib/resources/ModPathPackResources.java @@ -0,0 +1,23 @@ +package io.github.fabricators_of_create.porting_lib.resources; + +import net.fabricmc.loader.api.ModContainer; + +import java.nio.file.Path; +import java.util.NoSuchElementException; + +public class ModPathPackResources extends PathPackResources { + + private final ModContainer mf; + + public ModPathPackResources(ModContainer mf) { + super(mf.getMetadata().getName(), false, mf.getRootPath()); + this.mf = mf; + } + + @Override + protected Path resolve(String... paths) { + String path = String.join("/", paths); + return mf.findPath(path).orElseThrow(() -> new NoSuchElementException("Path " + path + " not found")); + } + +} diff --git a/modules/data/src/main/java/io/github/fabricators_of_create/porting_lib/resources/PathPackResources.java b/modules/data/src/main/java/io/github/fabricators_of_create/porting_lib/resources/PathPackResources.java index 25dc4f051..9918dece5 100644 --- a/modules/data/src/main/java/io/github/fabricators_of_create/porting_lib/resources/PathPackResources.java +++ b/modules/data/src/main/java/io/github/fabricators_of_create/porting_lib/resources/PathPackResources.java @@ -10,7 +10,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -import net.fabricmc.loader.api.FabricLoader; import net.fabricmc.loader.api.ModContainer; import org.jetbrains.annotations.NotNull; @@ -25,8 +24,6 @@ import net.minecraft.server.packs.PackType; import net.minecraft.server.packs.resources.IoSupplier; -import javax.annotation.Nonnull; - /** * Defines a resource pack from an arbitrary Path. *
@@ -41,10 +38,10 @@ public class PathPackResources extends AbstractPackResources {
/**
* Constructs a java.nio.Path-based resource pack.
*
- * @param packId the identifier of the pack.
- * This identifier should be unique within the pack finder, preferably the name of the file or folder containing the resources.
+ * @param packId the identifier of the pack.
+ * This identifier should be unique within the pack finder, preferably the name of the file or folder containing the resources.
* @param isBuiltin whether this pack resources should be considered builtin
- * @param source the root path of the pack. This needs to point to the folder that contains "assets" and/or "data", not the asset folder itself!
+ * @param source the root path of the pack. This needs to point to the folder that contains "assets" and/or "data", not the asset folder itself!
*/
public PathPackResources(String packId, boolean isBuiltin, final Path source) {
super(packId, isBuiltin);
@@ -67,18 +64,21 @@ public Path getSource() {
* @param paths One or more path strings to resolve. Can include slash-separated paths.
* @return the resulting path, which may not exist.
*/
+ @Nullable
protected Path resolve(String... paths) {
Path path = getSource();
for (String name : paths)
path = path.resolve(name);
- return path;
+ if (Files.exists(path))
+ return path;
+ return null;
}
@Nullable
@Override
public IoSupplier