From 9e7bd98410b6d7d84924089d86cf738f74a14cf5 Mon Sep 17 00:00:00 2001 From: Alexander Rath Date: Fri, 22 May 2020 10:27:47 +0200 Subject: [PATCH] make 20w17a blockstate code cleaner --- overviewer_core/world.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/overviewer_core/world.py b/overviewer_core/world.py index 57620e6..c104c83 100644 --- a/overviewer_core/world.py +++ b/overviewer_core/world.py @@ -23,6 +23,7 @@ import re import locale import numpy +import math from . import nbt from . import cache @@ -1245,9 +1246,7 @@ class RegionSet(object): return result def _packed_longarray_to_shorts_v116(self, long_array, n, num_palette): - bits_per_value = 4 - while (1 << bits_per_value) < num_palette: - bits_per_value += 1 + bits_per_value = max(4, math.ceil(math.log2(num_palette))) b = numpy.asarray(long_array, dtype=numpy.uint64) result = numpy.zeros((n,), dtype=numpy.uint16) @@ -1256,7 +1255,6 @@ class RegionSet(object): for i in range(shorts_per_long): j = (n + shorts_per_long - 1 - i) // shorts_per_long - #assert j == len(result[i::shorts_per_long]) result[i::shorts_per_long] = (b[:j] >> (bits_per_value * i)) & mask return result @@ -1391,7 +1389,7 @@ class RegionSet(object): chunk_data = level longarray_unpacker = self._packed_longarray_to_shorts - if 'DataVersion' in data[1] and data[1]['DataVersion'] >= 2529: + if data[1].get('DataVersion', 0) >= 2529: # starting with 1.16 snapshot 20w17a, block states are packed differently longarray_unpacker = self._packed_longarray_to_shorts_v116