Skip to content

Commit

Permalink
NBT objects are now iterable themselves; packing and unpacking is no …
Browse files Browse the repository at this point in the history
…longer needed, and gives an error for TAG_Byte_Array which is stored as a bytearray() since b1110
  • Loading branch information
macfreek committed Mar 5, 2012
1 parent ccca64e commit c0aa823
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/biome_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def main(world_folder):

try:
for chunk in world.iter_nbt():
for biomeid in unpack("256B", chunk["Level"]["Biomes"].value):
for biomeid in chunk["Level"]["Biomes"]:
biome_totals[biomeid] += 1

except KeyboardInterrupt:
Expand Down
10 changes: 8 additions & 2 deletions nbt/chunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ def __repr__(self):
class BlockArray(object):
def __init__(self, blocksBytes=None, dataBytes=None):
if (blocksBytes != None):
self.blocksList = list(unpack("32768B", blocksBytes)) # A list of bytes
if isinstance(blocksBytes, (bytearray, array.array)):
self.blocksList = list(blocksBytes)
else: # blockList is a string
self.blocksList = list(unpack("32768B", blocksBytes)) # A list of bytes
else:
self.blocksList = [0]*32768 # Create an empty block list (32768 entries of zero (air))

if (dataBytes != None):
self.dataList = list(unpack("16384B", dataBytes))
if isinstance(dataBytes, (bytearray, array.array)):
self.dataList = list(dataBytes)
else: # dataBytes is a string
self.dataList = list(unpack("16384B", dataBytes))
else:
self.dataList = [0]*16384 # Create an empty data list (32768 4-bit entries of zero make 16384 byte entries)

Expand Down

0 comments on commit c0aa823

Please sign in to comment.