Skip to content

Commit 730ae99

Browse files
committed
Try to add support for directory resource packs.
1 parent ac1c4cc commit 730ae99

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

chunky/src/java/se/llbit/chunky/block/jsonmodels/ResourcepackBlockProvider.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.nio.file.FileSystem;
88
import java.nio.file.Files;
99
import java.nio.file.NoSuchFileException;
10+
import java.nio.file.Path;
1011
import java.util.ArrayList;
1112
import java.util.Arrays;
1213
import java.util.Collection;
@@ -27,6 +28,7 @@
2728
import se.llbit.chunky.renderer.scene.Scene;
2829
import se.llbit.chunky.resources.AnimatedTexture;
2930
import se.llbit.chunky.resources.BitmapImage;
31+
import se.llbit.chunky.resources.ResourcePackLoader;
3032
import se.llbit.chunky.resources.Texture;
3133
import se.llbit.chunky.world.Material;
3234
import se.llbit.chunky.world.material.TextureMaterial;
@@ -45,6 +47,7 @@
4547
import se.llbit.nbt.Tag;
4648
import se.llbit.resources.ImageLoader;
4749
import se.llbit.util.FileSystemUtil;
50+
import se.llbit.util.Pair;
4851

4952
public class ResourcepackBlockProvider implements BlockProvider {
5053
private final Map<String, BlockVariants> blocks = new HashMap<>();
@@ -57,16 +60,16 @@ public void loadBlocks(List<File> files) throws IOException {
5760
.map(
5861
f -> {
5962
try {
60-
return FileSystemUtil.getZipFileSystem(f);
63+
return new Pair(f, ResourcePackLoader.getPackFileSystem(f));
6164
} catch (IOException e) {
6265
throw new RuntimeException("Could not open resource pack " + f, e);
6366
}
6467
})
65-
.toArray(FileSystem[]::new))) {
68+
.toArray(Pair[]::new))) {
6669

67-
for (FileSystem resourcePack : effectiveResources.fileSystems) {
70+
for (Pair<File, FileSystem> resourcePack : effectiveResources.fileSystems) {
6871
JsonModelLoader modelLoader = new JsonModelLoader();
69-
Files.list(resourcePack.getPath("assets"))
72+
Files.list(ResourcePackLoader.getPackRootPath(resourcePack.thing1, resourcePack.thing2).resolve("assets"))
7073
.filter(Files::isDirectory)
7174
.map(assetProvider -> assetProvider.resolve("blockstates"))
7275
.filter(Files::isDirectory)
@@ -84,6 +87,7 @@ public void loadBlocks(List<File> files) throws IOException {
8487
String fqBlockName = assetsName + ":" + blockName;
8588

8689
if (blocks.containsKey(fqBlockName)) {
90+
System.out.println("Block " + fqBlockName + " already provided");
8791
// this block was already provided by a different resource pack
8892
return;
8993
}
@@ -190,13 +194,13 @@ public void loadBlocks(List<File> files) throws IOException {
190194
"Could not load block "
191195
+ fqBlockName
192196
+ " from "
193-
+ resourcePack.getFileStores().iterator().next().name());
197+
+ resourcePack.thing2.getFileStores().iterator().next().name());
194198
}
195199
});
196200
} catch (IOException e) {
197201
System.out.println(
198202
"Could not read resource pack "
199-
+ resourcePack.getFileStores().iterator().next().name());
203+
+ resourcePack.thing2.getFileStores().iterator().next().name());
200204
}
201205
});
202206
}
@@ -1101,16 +1105,16 @@ public JsonValue toJson() {
11011105
}
11021106

11031107
public static class MultiFileSystem implements AutoCloseable {
1104-
private FileSystem[] fileSystems;
1108+
private final Pair<File, FileSystem>[] fileSystems;
11051109

1106-
MultiFileSystem(FileSystem... fileSystems) {
1110+
MultiFileSystem(Pair<File, FileSystem>... fileSystems) {
11071111
this.fileSystems = fileSystems;
11081112
}
11091113

11101114
InputStream getInputStream(String... path) throws IOException {
1111-
for (FileSystem fs : fileSystems) {
1115+
for (Pair<File, FileSystem> fs : fileSystems) {
11121116
try {
1113-
return Files.newInputStream(fs.getPath("", path));
1117+
return Files.newInputStream(ResourcePackLoader.getPackRootPath(fs.thing1, fs.thing2).resolve(String.join(fs.thing2.getSeparator(), path)));
11141118
} catch (NoSuchFileException ignore) {
11151119
}
11161120
}
@@ -1119,9 +1123,9 @@ InputStream getInputStream(String... path) throws IOException {
11191123

11201124
@Override
11211125
public void close() {
1122-
for (FileSystem fs : fileSystems) {
1126+
for (Pair<File, FileSystem> fs : fileSystems) {
11231127
try {
1124-
fs.close();
1128+
fs.thing2.close();
11251129
} catch (IOException e) {
11261130
}
11271131
}

chunky/src/java/se/llbit/chunky/main/Chunky.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public static String getMainWindowTitle() {
105105

106106
public Chunky(ChunkyOptions options) {
107107
this.options = options;
108-
registerBlockProvider(new MinecraftBlockProvider());
108+
// registerBlockProvider(new MinecraftBlockProvider());
109109
// registerBlockProvider(new LegacyMinecraftBlockProvider());
110110
registerBlockProvider(new ResourcepackBlockProvider());
111111
}

0 commit comments

Comments
 (0)