Skip to content

Commit b483ab6

Browse files
Add compatibility for post 21w39a and 21w43a snapshots
1 parent 2402e41 commit b483ab6

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

overviewer_core/world.py

+47-3
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,39 @@ def _packed_longarray_to_shorts_v116(self, long_array, n, num_palette):
15091509

15101510
return result
15111511

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+
15121545
def _get_blockdata_v113(self, section, unrecognized_block_types, longarray_unpacker):
15131546
# Translate each entry in the palette to a 1.2-era (block, data) int pair.
15141547
num_palette_entries = len(section['Palette'])
@@ -1634,8 +1667,15 @@ def get_chunk(self, x, z):
16341667
if data is None:
16351668
raise ChunkDoesntExist("Chunk %s,%s doesn't exist" % (x,z))
16361669

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']
16391679

16401680
longarray_unpacker = self._packed_longarray_to_shorts
16411681
if data[1].get('DataVersion', 0) >= 2529:
@@ -1668,6 +1708,8 @@ def get_chunk(self, x, z):
16681708
# Worlds converted by Jeb's program may be missing the Biomes key.
16691709
# Additionally, 19w09a worlds have an empty array as biomes key
16701710
# in some cases.
1711+
1712+
# TODO: Implement paletted biomes for >21w39a
16711713
biomes = numpy.zeros((16, 16), dtype=numpy.uint8)
16721714
chunk_data['Biomes'] = biomes
16731715
chunk_data['NewBiomes'] = (len(biomes.shape) == 3)
@@ -1707,7 +1749,9 @@ def get_chunk(self, x, z):
17071749
del blocklight
17081750
section['BlockLight'] = blocklight_expanded
17091751

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:
17111755
(blocks, data) = self._get_blockdata_v113(section, unrecognized_block_types, longarray_unpacker)
17121756
elif 'Data' in section:
17131757
(blocks, data) = self._get_blockdata_v112(section)

0 commit comments

Comments
 (0)