18
18
import os .path
19
19
import logging
20
20
import time
21
- import random
22
21
import re
23
- import locale
24
22
25
23
import numpy
26
- import math
27
24
28
25
from . import nbt
29
26
from . import cache
37
34
class ChunkDoesntExist (Exception ):
38
35
pass
39
36
40
-
41
37
class UnsupportedVersion (Exception ):
42
38
pass
43
39
40
+ class UnknownBlockException (Exception ):
41
+ pass
44
42
45
43
def log_other_exceptions (func ):
46
44
"""A decorator that prints out any errors that are not
@@ -1129,6 +1127,8 @@ def _get_block(self, palette_entry):
1129
1127
'purple' , 'blue' , 'brown' , 'green' , 'red' , 'black' ]
1130
1128
1131
1129
key = palette_entry ['Name' ]
1130
+ if key not in self ._blockmap :
1131
+ raise UnknownBlockException (key )
1132
1132
(block , data ) = self ._blockmap [key ]
1133
1133
if key in ['minecraft:redstone_ore' , 'minecraft:redstone_lamp' ]:
1134
1134
if palette_entry ['Properties' ]['lit' ] == 'true' :
@@ -1209,8 +1209,8 @@ def _get_block(self, palette_entry):
1209
1209
data = int (palette_entry ['Properties' ]['age' ])
1210
1210
elif key in ['minecraft:jigsaw' ]:
1211
1211
data = {'down_east' : 0 , 'down_east' : 0 , 'down_north' : 0 , 'down_south' : 0 , 'down_west' : 0 ,
1212
- 'up_east' : 1 , 'up_north' : 1 , 'up_south' : 1 , 'up_west' : 1 , 'north_up' : 2 , 'south_up' : 3 ,
1213
- 'west_up' : 4 , 'east_up' : 5 }[palette_entry ['Properties' ]['facing ' ]]
1212
+ 'up_east' : 1 , 'up_north' : 1 , 'up_south' : 1 , 'up_west' : 1 , 'north_up' : 2 , 'south_up' : 3 ,
1213
+ 'west_up' : 4 , 'east_up' : 5 }[palette_entry ['Properties' ]['orientation ' ]]
1214
1214
elif (key .endswith ('shulker_box' ) or key .endswith ('piston' ) or
1215
1215
key in ['minecraft:observer' , 'minecraft:dropper' , 'minecraft:dispenser' ,
1216
1216
'minecraft:piston_head' , 'minecraft:end_rod' ]):
@@ -1514,7 +1514,7 @@ def _packed_longarray_to_shorts_v116(self, long_array, n, num_palette):
1514
1514
1515
1515
return result
1516
1516
1517
- def _get_blockdata_v118 (self , section , unrecognized_block_types , longarray_unpacker ):
1517
+ def _get_blockdata_v118 (self , section , longarray_unpacker ):
1518
1518
block_states = section ['block_states' ]
1519
1519
palette = block_states .get ('palette' )
1520
1520
block_states_data = block_states .get ('data' )
@@ -1531,7 +1531,7 @@ def _get_blockdata_v118(self, section, unrecognized_block_types, longarray_unpac
1531
1531
key = palette [i ]
1532
1532
try :
1533
1533
translated_blocks [i ], translated_data [i ] = self ._get_block (key )
1534
- except KeyError :
1534
+ except UnknownBlockException as e :
1535
1535
pass # We already have initialised arrays with 0 (= air)
1536
1536
1537
1537
# Turn the BlockStates array into a 16x16x16 numpy matrix of shorts.
@@ -1547,7 +1547,7 @@ def _get_blockdata_v118(self, section, unrecognized_block_types, longarray_unpac
1547
1547
1548
1548
return (blocks , data )
1549
1549
1550
- def _get_blockdata_v113 (self , section , unrecognized_block_types , longarray_unpacker ):
1550
+ def _get_blockdata_v113 (self , section , longarray_unpacker ):
1551
1551
# Translate each entry in the palette to a 1.2-era (block, data) int pair.
1552
1552
num_palette_entries = len (section ['Palette' ])
1553
1553
translated_blocks = numpy .zeros ((num_palette_entries ,), dtype = numpy .uint16 ) # block IDs
@@ -1556,7 +1556,7 @@ def _get_blockdata_v113(self, section, unrecognized_block_types, longarray_unpac
1556
1556
key = section ['Palette' ][i ]
1557
1557
try :
1558
1558
translated_blocks [i ], translated_data [i ] = self ._get_block (key )
1559
- except KeyError :
1559
+ except UnknownBlockException as e :
1560
1560
pass # We already have initialised arrays with 0 (= air)
1561
1561
1562
1562
# Turn the BlockStates array into a 16x16x16 numpy matrix of shorts.
@@ -1719,7 +1719,6 @@ def get_chunk(self, x, z):
1719
1719
chunk_data ['Biomes' ] = biomes
1720
1720
chunk_data ['NewBiomes' ] = (len (biomes .shape ) == 3 )
1721
1721
1722
- unrecognized_block_types = {}
1723
1722
for section in chunk_data ['Sections' ]:
1724
1723
1725
1724
# Turn the skylight array into a 16x16x16 matrix. The array comes
@@ -1755,9 +1754,9 @@ def get_chunk(self, x, z):
1755
1754
section ['BlockLight' ] = blocklight_expanded
1756
1755
1757
1756
if 'block_states' in section :
1758
- (blocks , data ) = self ._get_blockdata_v118 (section , unrecognized_block_types , longarray_unpacker )
1757
+ (blocks , data ) = self ._get_blockdata_v118 (section , longarray_unpacker )
1759
1758
elif 'Palette' in section :
1760
- (blocks , data ) = self ._get_blockdata_v113 (section , unrecognized_block_types , longarray_unpacker )
1759
+ (blocks , data ) = self ._get_blockdata_v113 (section , longarray_unpacker )
1761
1760
elif 'Data' in section :
1762
1761
(blocks , data ) = self ._get_blockdata_v112 (section )
1763
1762
else : # Special case introduced with 1.14
@@ -1773,9 +1772,6 @@ def get_chunk(self, x, z):
1773
1772
logging .debug ("Full traceback:" , exc_info = 1 )
1774
1773
raise nbt .CorruptChunkError ()
1775
1774
1776
- for k in unrecognized_block_types :
1777
- logging .debug ("Found %d blocks of unknown type %s" % (unrecognized_block_types [k ], k ))
1778
-
1779
1775
return chunk_data
1780
1776
1781
1777
0 commit comments