@@ -4,6 +4,7 @@ const constants = require('../common/constants')
4
4
const BitArray = require ( '../common/BitArray' )
5
5
const varInt = require ( '../common/varInt' )
6
6
const CommonChunkColumn = require ( '../common/CommonChunkColumn' )
7
+ const neededBits = require ( '../common/neededBits' )
7
8
8
9
// wrap with func to provide version specific Block
9
10
module . exports = ( Block , mcData ) => {
@@ -17,6 +18,7 @@ module.exports = (Block, mcData) => {
17
18
this . biomes = Array (
18
19
constants . SECTION_WIDTH * constants . SECTION_WIDTH
19
20
) . fill ( 1 )
21
+ this . maxBitsPerBlock = neededBits ( Object . values ( mcData . blocks ) . reduce ( ( high , block ) => Math . max ( high , block . maxStateId ) , 0 ) )
20
22
}
21
23
22
24
toJson ( ) {
@@ -139,7 +141,9 @@ module.exports = (Block, mcData) => {
139
141
if ( stateId === 0 ) {
140
142
return
141
143
}
142
- section = new ChunkSection ( )
144
+ section = new ChunkSection ( {
145
+ maxBitsPerBlock : this . maxBitsPerBlock
146
+ } )
143
147
this . sectionMask |= 1 << sectionIndex
144
148
this . sections [ sectionIndex ] = section
145
149
}
@@ -235,11 +239,10 @@ module.exports = (Block, mcData) => {
235
239
}
236
240
237
241
// number of items in data array
238
- const numLongs = varInt . read ( reader )
239
242
const dataArray = new BitArray ( {
240
- bitsPerValue : Math . ceil ( ( numLongs * 64 ) / 4096 ) ,
243
+ bitsPerValue : bitsPerBlock > constants . MAX_BITS_PER_BLOCK ? this . maxBitsPerBlock : bitsPerBlock ,
241
244
capacity : 4096
242
- } ) . readBuffer ( reader )
245
+ } ) . readBuffer ( reader , varInt . read ( reader ) * 2 )
243
246
244
247
const blockLight = new BitArray ( {
245
248
bitsPerValue : 4 ,
@@ -257,6 +260,7 @@ module.exports = (Block, mcData) => {
257
260
data : dataArray ,
258
261
palette,
259
262
blockLight,
263
+ maxBitsPerBlock : this . maxBitsPerBlock ,
260
264
...( skyLightSent ? { skyLight } : { skyLight : null } )
261
265
} )
262
266
this . sections [ y ] = section
0 commit comments