0

Fixed get_chunks, simplified get_chunk_info

This commit is contained in:
Xon
2011-03-23 18:49:26 +08:00
parent 8cfa50087a
commit c700afb012

17
nbt.py
View File

@@ -281,12 +281,15 @@ class MCRFileReader(object):
as a list of (x, y) coordinate tuples. To load these chunks, as a list of (x, y) coordinate tuples. To load these chunks,
provide these coordinates to load_chunk().""" provide these coordinates to load_chunk()."""
if self._chunks: if self._chunks is not None:
return self._chunks return self._chunks
if self._locations is None: if self._locations is None:
self.get_chunk_info() self.get_chunk_info()
self._chunks = filter(None,self._locations) self._chunks = []
for x in xrange(32):
for y in xrange(32):
if self._locations[x + y * 32] is not None:
self._chunks.append((x,y))
return self._chunks return self._chunks
def get_chunk_info(self,closeFile = True): def get_chunk_info(self,closeFile = True):
@@ -296,7 +299,7 @@ class MCRFileReader(object):
return return
if self._file is None: if self._file is None:
self._file = open(self._filename,'rb'); self._file = open(self._filename,'rb')
self._chunks = None self._chunks = None
self._locations = [] self._locations = []
@@ -307,13 +310,13 @@ class MCRFileReader(object):
# read chunk location table # read chunk location table
locations_append = self._locations.append locations_append = self._locations.append
for x, y in [(x,y) for x in xrange(32) for y in xrange(32)]: for _ in xrange(32*32):
locations_append(self._read_chunk_location()) locations_append(self._read_chunk_location())
# read chunk timestamp table # read chunk timestamp table
timestamp_append = self._timestamps.append timestamp_append = self._timestamps.append
for x, y in [(x,y) for x in xrange(32) for y in xrange(32)]: for _ in xrange(32*32):
timestamp_append(self._read_chunk_timestamp()) timestamp_append(self._read_chunk_timestamp())
if closeFile: if closeFile:
#free the file object since it isn't safe to be reused in child processes (seek point goes wonky!) #free the file object since it isn't safe to be reused in child processes (seek point goes wonky!)