Fix assumption in FIND_RESOURCE handler. Closes #7

This commit is contained in:
JFronny 2021-08-24 13:02:54 +02:00
parent 6101eafe77
commit 27fcbcd13e
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
3 changed files with 9 additions and 5 deletions

View File

@ -22,9 +22,11 @@ public class FilterProvider {
return previous;
});
UserResourceEvents.FIND_RESOURCE.register((type, namespace, prefix, maxDepth, pathFilter, previous, pack) -> {
// Warning: the Identifiers here DON'T CONTAIN THE TYPE! Therefore, it needs to be added when calling a method that generates a ResourcePath!
if (skip(pack)) return previous;
previous.removeIf(s -> ResourcePackFilter.fileHidden(pack, s.getPath()) && !FallbackFilter.fileVisible(pack, namespace));
FallbackFilter.addFallbackResources(pack, previous, namespace);
previous.removeIf(s -> ResourcePackFilter.fileHidden(pack, type.getDirectory() + "/" + s.getPath()) && !FallbackFilter.fileVisible(pack, namespace));
// Completion of the path is handled separately here
FallbackFilter.addFallbackResources(pack, previous, namespace, type);
return previous;
});
UserResourceEvents.CONTAINS.register((type, id, previous, pack) -> {

View File

@ -19,7 +19,7 @@ public class ResourcePackFilter {
if (!pack.contains(rpoPath.getType(), rpoPath.getId()))
return false;
} catch (Throwable e) {
Respackopts.LOGGER.error(e);
Respackopts.LOGGER.error("Could not check file filter status", e);
return false;
}
try (InputStream stream = pack.open(rpoPath.getType(), rpoPath.getId()); Reader w = new InputStreamReader(stream)) {

View File

@ -4,6 +4,7 @@ import io.gitlab.jfronny.libjf.data.ResourcePath;
import io.gitlab.jfronny.libjf.data.WrappedPack;
import io.gitlab.jfronny.respackopts.Respackopts;
import io.gitlab.jfronny.respackopts.data.Rpo;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import java.io.IOException;
@ -54,12 +55,13 @@ public class FallbackFilter {
throw ex;
}
public static void addFallbackResources(WrappedPack pack, Collection<Identifier> ret, String namespace) {
public static void addFallbackResources(WrappedPack pack, Collection<Identifier> ret, String namespace, ResourceType type) {
// Warning: the Identifiers here DON'T CONTAIN THE TYPE! Therefore, it needs to be added when calling a method that generates a ResourcePath!
for (Identifier identifier : ret) {
String path = identifier.getPath();
if (path.endsWith(Respackopts.FILE_EXTENSION)) {
String expectedTarget = path.substring(0, path.length() - Respackopts.FILE_EXTENSION.length());
if (ret.stream().noneMatch(s -> s.getPath().equals(expectedTarget)) && fileVisible(pack, expectedTarget)) {
if (ret.stream().noneMatch(s -> s.getPath().equals(expectedTarget)) && fileVisible(pack, type.getDirectory() + "/" + expectedTarget)) {
ret.add(new Identifier(namespace, expectedTarget));
}
}