@@ -97,9 +97,9 @@ public T loadChunk(int chunkX, int chunkZ) throws IOException {
9797 channel .position (offset );
9898 readFully (channel , chunkDataBuffer , 0 , size );
9999
100- return loadChunk (chunkDataBuffer , size );
100+ return loadChunk (chunkX , chunkZ , chunkDataBuffer , size );
101101 } catch (IOException | RuntimeException ex ) {
102- throw new IOException ("Exception trying to read chunk (%d,%d) from region '%s'" .formatted (chunkX , chunkZ , regionFile ), ex );
102+ throw new IOException ("Exception trying to read chunk (%d,%d) from region '%s': %s " .formatted (chunkX , chunkZ , regionFile , ex ), ex );
103103 }
104104 }
105105
@@ -152,7 +152,7 @@ public void iterateAllChunks(ChunkConsumer<T> consumer) throws IOException {
152152 readFully (channel , chunkDataBuffer , 0 , size );
153153
154154 try {
155- T chunk = loadChunk (chunkDataBuffer , size );
155+ T chunk = loadChunk (chunkX , chunkZ , chunkDataBuffer , size );
156156 consumer .accept (chunkX , chunkZ , chunk );
157157 } catch (IOException ex ) {
158158 consumer .fail (chunkX , chunkZ , ex );
@@ -164,7 +164,7 @@ public void iterateAllChunks(ChunkConsumer<T> consumer) throws IOException {
164164 }
165165 }
166166 } catch (IOException | RuntimeException ex ) {
167- throw new IOException ("Exception trying to iterate chunks in region '%s'" .formatted (regionFile ), ex );
167+ throw new IOException ("Exception trying to iterate chunks in region '%s': %s " .formatted (regionFile , ex ), ex );
168168 }
169169 }
170170
@@ -173,13 +173,25 @@ public T emptyChunk() {
173173 return chunkLoader .emptyChunk ();
174174 }
175175
176- private T loadChunk (byte [] data , int size ) throws IOException {
176+ private T loadChunk (int chunkX , int chunkZ , byte [] data , int size ) throws IOException {
177177 int compressionTypeId = Byte .toUnsignedInt (data [4 ]);
178+ int offset = 5 ;
179+ size -= 5 ;
180+
181+ //oversized chunks
182+ if (compressionTypeId > 127 ) {
183+ compressionTypeId -= 128 ;
184+ Path chunkFile = regionFile .getParent ().resolve ("c.%d.%d.mcc" .formatted (chunkX , chunkZ ));
185+ data = Files .readAllBytes (chunkFile );
186+ offset = 0 ;
187+ size = data .length ;
188+ }
189+
178190 Compression compression = CHUNK_COMPRESSION_MAP [compressionTypeId ];
179191 if (compression == null )
180192 throw new IOException ("Unknown chunk compression-id: " + compressionTypeId );
181193
182- return chunkLoader .load (data , 5 , size - 5 , compression );
194+ return chunkLoader .load (data , offset , size , compression );
183195 }
184196
185197 public static String getRegionFileName (int regionX , int regionZ ) {
0 commit comments