77import java .nio .file .FileSystem ;
88import java .nio .file .Files ;
99import java .nio .file .NoSuchFileException ;
10+ import java .nio .file .Path ;
1011import java .util .ArrayList ;
1112import java .util .Arrays ;
1213import java .util .Collection ;
2728import se .llbit .chunky .renderer .scene .Scene ;
2829import se .llbit .chunky .resources .AnimatedTexture ;
2930import se .llbit .chunky .resources .BitmapImage ;
31+ import se .llbit .chunky .resources .ResourcePackLoader ;
3032import se .llbit .chunky .resources .Texture ;
3133import se .llbit .chunky .world .Material ;
3234import se .llbit .chunky .world .material .TextureMaterial ;
4547import se .llbit .nbt .Tag ;
4648import se .llbit .resources .ImageLoader ;
4749import se .llbit .util .FileSystemUtil ;
50+ import se .llbit .util .Pair ;
4851
4952public 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 }
0 commit comments