@@ -1509,6 +1509,39 @@ def _packed_longarray_to_shorts_v116(self, long_array, n, num_palette):
1509
1509
1510
1510
return result
1511
1511
1512
+ def _get_blockdata_v2840 (self , section , unrecognized_block_types , longarray_unpacker ):
1513
+ block_states = section ['block_states' ]
1514
+ palette = block_states .get ('palette' )
1515
+ block_states_data = block_states .get ('data' )
1516
+
1517
+ # Translate each entry in the palette to a 1.2-era (block, data) int pair.
1518
+ num_palette_entries = len (palette )
1519
+ translated_blocks = numpy .zeros ((num_palette_entries ,), dtype = numpy .uint16 ) # block IDs
1520
+ translated_data = numpy .zeros ((num_palette_entries ,), dtype = numpy .uint8 ) # block data
1521
+ for i in range (num_palette_entries ):
1522
+ key = palette [i ]
1523
+ try :
1524
+ translated_blocks [i ], translated_data [i ] = self ._get_block (key )
1525
+ except KeyError :
1526
+ pass # We already have initialised arrays with 0 (= air)
1527
+
1528
+ if not block_states_data :
1529
+ # This chunk is missing its block data, assume its all air
1530
+ block_states_data = numpy .zeros ((256 ,), dtype = numpy .uint16 )
1531
+
1532
+ # Turn the BlockStates array into a 16x16x16 numpy matrix of shorts.
1533
+ blocks = numpy .empty ((4096 ,), dtype = numpy .uint16 )
1534
+ data = numpy .empty ((4096 ,), dtype = numpy .uint8 )
1535
+ block_states = longarray_unpacker (block_states_data , 4096 , num_palette_entries )
1536
+ blocks [:] = translated_blocks [block_states ]
1537
+ data [:] = translated_data [block_states ]
1538
+
1539
+ # Turn the Data array into a 16x16x16 matrix, same as SkyLight
1540
+ blocks = blocks .reshape ((16 , 16 , 16 ))
1541
+ data = data .reshape ((16 , 16 , 16 ))
1542
+
1543
+ return (blocks , data )
1544
+
1512
1545
def _get_blockdata_v113 (self , section , unrecognized_block_types , longarray_unpacker ):
1513
1546
# Translate each entry in the palette to a 1.2-era (block, data) int pair.
1514
1547
num_palette_entries = len (section ['Palette' ])
@@ -1634,8 +1667,15 @@ def get_chunk(self, x, z):
1634
1667
if data is None :
1635
1668
raise ChunkDoesntExist ("Chunk %s,%s doesn't exist" % (x ,z ))
1636
1669
1637
- level = data [1 ]['Level' ]
1638
- chunk_data = level
1670
+ chunk_data = data [1 ]
1671
+
1672
+ if not 'sections' in chunk_data :
1673
+ # This world was generated pre 21w43a and thus most chunk data is contained
1674
+ # in the "Level" key
1675
+ chunk_data = chunk_data ['Level' ]
1676
+ else :
1677
+ # This world was generated post 21w43a
1678
+ chunk_data ['Sections' ] = chunk_data ['sections' ]
1639
1679
1640
1680
longarray_unpacker = self ._packed_longarray_to_shorts
1641
1681
if data [1 ].get ('DataVersion' , 0 ) >= 2529 :
@@ -1668,6 +1708,8 @@ def get_chunk(self, x, z):
1668
1708
# Worlds converted by Jeb's program may be missing the Biomes key.
1669
1709
# Additionally, 19w09a worlds have an empty array as biomes key
1670
1710
# in some cases.
1711
+
1712
+ # TODO: Implement paletted biomes for >21w39a
1671
1713
biomes = numpy .zeros ((16 , 16 ), dtype = numpy .uint8 )
1672
1714
chunk_data ['Biomes' ] = biomes
1673
1715
chunk_data ['NewBiomes' ] = (len (biomes .shape ) == 3 )
@@ -1707,7 +1749,9 @@ def get_chunk(self, x, z):
1707
1749
del blocklight
1708
1750
section ['BlockLight' ] = blocklight_expanded
1709
1751
1710
- if 'Palette' in section :
1752
+ if 'block_states' in section :
1753
+ (blocks , data ) = self ._get_blockdata_v2840 (section , unrecognized_block_types , longarray_unpacker )
1754
+ elif 'Palette' in section :
1711
1755
(blocks , data ) = self ._get_blockdata_v113 (section , unrecognized_block_types , longarray_unpacker )
1712
1756
elif 'Data' in section :
1713
1757
(blocks , data ) = self ._get_blockdata_v112 (section )
0 commit comments