@@ -874,43 +874,45 @@ public static bool GetBlockByName([CanBeNull] World world, [NotNull] string bloc
874874 }
875875
876876 const int bufferSize = 64 * 1024 ;
877- internal void CompressMap ( Player dst ) {
878- byte [ ] array = Blocks ;
879- using ( LevelChunkStream ms = new LevelChunkStream ( dst ) )
880- using ( GZipStream compressor = new GZipStream ( ms , CompressionMode . Compress , true ) )
881- {
882- int count = IPAddress . HostToNetworkOrder ( array . Length ) ; // convert to big endian
877+ internal Stream CompressMapHeader ( Player player , LevelChunkStream dst ) {
878+ Stream compressor = null ;
879+ if ( player . Supports ( CpeExt . FastMap ) ) {
880+ compressor = new DeflateStream ( dst , CompressionMode . Compress , true ) ;
881+ } else {
882+ compressor = new GZipStream ( dst , CompressionMode . Compress , true ) ;
883+ int count = IPAddress . HostToNetworkOrder ( Volume ) ; // convert to big endian
883884 compressor . Write ( BitConverter . GetBytes ( count ) , 0 , 4 ) ;
884- ms . length = array . Length ;
885-
886- for ( int i = 0 ; i < array . Length ; i += bufferSize ) {
887- int len = Math . Min ( bufferSize , array . Length - i ) ;
888- ms . position = i ;
889- compressor . Write ( array , i , len ) ;
890- }
885+ }
886+ return compressor ;
887+ }
888+
889+ internal void CompressMap ( LevelChunkStream dst , Stream compressor ) {
890+ byte [ ] array = Blocks ;
891+ float progScale = 100.0f / array . Length ;
892+
893+ for ( int i = 0 ; i < array . Length ; i += bufferSize ) {
894+ int len = Math . Min ( bufferSize , array . Length - i ) ;
895+ dst . chunkValue = ( byte ) ( i * progScale ) ;
896+ compressor . Write ( array , i , len ) ;
891897 }
892898 }
893899
894- internal void CompressAndConvertMap ( byte maxLegal , Player dst ) {
900+ internal void CompressAndConvertMap ( byte maxLegal , LevelChunkStream dst , Stream compressor ) {
895901 byte [ ] array = Blocks ;
902+ float progScale = 100.0f / array . Length ;
903+
896904 byte * fallback = stackalloc byte [ 256 ] ;
897905 MakeFallbacks ( fallback , maxLegal , World ) ;
898- using ( LevelChunkStream ms = new LevelChunkStream ( dst ) )
899- using ( GZipStream compressor = new GZipStream ( ms , CompressionMode . Compress , true ) )
900- {
901- int count = IPAddress . HostToNetworkOrder ( array . Length ) ; // convert to big endian
902- compressor . Write ( BitConverter . GetBytes ( count ) , 0 , 4 ) ;
903- ms . length = array . Length ;
904-
905- byte [ ] buffer = new byte [ bufferSize ] ;
906- for ( int i = 0 ; i < array . Length ; i += bufferSize ) {
907- int len = Math . Min ( bufferSize , array . Length - i ) ;
908- for ( int j = 0 ; j < len ; j ++ )
909- buffer [ j ] = fallback [ array [ i + j ] ] ;
910-
911- ms . position = i ;
912- compressor . Write ( buffer , 0 , len ) ;
906+ byte [ ] buffer = new byte [ bufferSize ] ;
907+
908+ for ( int i = 0 ; i < array . Length ; i += bufferSize ) {
909+ int len = Math . Min ( bufferSize , array . Length - i ) ;
910+ for ( int j = 0 ; j < len ; j ++ ) {
911+ buffer [ j ] = fallback [ array [ i + j ] ] ;
913912 }
913+
914+ dst . chunkValue = ( byte ) ( i * progScale ) ;
915+ compressor . Write ( buffer , 0 , len ) ;
914916 }
915917 }
916918
0 commit comments