Skip to content

Commit

Permalink
Fixed server resources loading on client
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocelot5836 committed Nov 2, 2024
1 parent ba822a6 commit d38479c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ public void addLoader(VeilResourceLoader loader) {
this.loaders.add(loader);
}

private void loadPack(ResourceManager resourceManager, VeilPackResources resources, Object2ObjectMap<Path, PackResourceListener> watchers, PackResources packResources) {
private void loadPack(ResourceManager resourceManager, VeilPackResources resources, Object2ObjectMap<Path, PackResourceListener> watchers, PackType type, PackResources packResources) {
if (packResources instanceof PackResourcesExtension ext) {
try {
ext.veil$listResources((packType, loc, packPath, path, modResourcePath) -> {
if (packType != type) {
return;
}

try {
VeilResource<?> resource = this.visitResource(packType, resourceManager, loc, path, modResourcePath);
resources.add(packType, loc, resource);
Expand All @@ -99,16 +103,14 @@ private void loadPack(ResourceManager resourceManager, VeilPackResources resourc
}
}

for (PackType packType : PackType.values()) {
for (String namespace : packResources.getNamespaces(PackType.CLIENT_RESOURCES)) {
packResources.listResources(packType, namespace, "", (loc, inputStreamIoSupplier) -> {
try {
resources.add(packType, loc, this.visitResource(packType, resourceManager, loc, null, null));
} catch (Exception e) {
Veil.LOGGER.error("Error loading resource: {}", loc, e);
}
});
}
for (String namespace : packResources.getNamespaces(type)) {
packResources.listResources(type, namespace, "", (loc, inputStreamIoSupplier) -> {
try {
resources.add(type, loc, this.visitResource(type, resourceManager, loc, null, null));
} catch (Exception e) {
Veil.LOGGER.error("Error loading resource: {}", loc, e);
}
});
}
}

Expand Down Expand Up @@ -153,7 +155,7 @@ private CompletableFuture<Void> reloadClient(PreparableReloadListener.Preparatio
Object2ObjectMap<Path, PackResourceListener> watchers = new Object2ObjectArrayMap<>();
resourceManager.listPacks().flatMap(pack -> pack instanceof PackResourcesExtension extension ? extension.veil$listPacks() : Stream.of(pack)).forEach(pack -> {
VeilPackResources resources = new VeilPackResources(pack.packId());
this.loadPack(resourceManager, resources, watchers, pack);
this.loadPack(resourceManager, resources, watchers, PackType.CLIENT_RESOURCES, pack);
packs.add(resources);

if (pack instanceof PackResourcesExtension extension) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public abstract class ModNioResourcePackMixin implements ModResourcePack, PackRe

@Override
public void veil$listResources(PackResourceConsumer consumer) {
String packId = this.packId();

for (Path basePath : this.basePaths) {
String separator = basePath.getFileSystem().getSeparator();

Expand All @@ -55,6 +53,9 @@ public abstract class ModNioResourcePackMixin implements ModResourcePack, PackRe

for (String namespace : entry.getValue()) {
Path nsPath = basePath.resolve(type.getDirectory()).resolve(namespace);
if (!Files.exists(nsPath)) {
continue;
}

try {
Files.walkFileTree(nsPath, new SimpleFileVisitor<>() {
Expand Down

0 comments on commit d38479c

Please sign in to comment.