def read(self): #print "Loading anvil region " + self.path chunk_info = [] for i in range(0, 1024): chunk_int = struct.unpack(">I", self.file.read(4))[0] chunk_loc = chunk_int >> 8 chunk_sec = chunk_int & 255 chunk_info.append((chunk_loc, chunk_sec)) for i in range(0, 1024): chunk_time = struct.unpack(">I", self.file.read(4)) chunk_info[i] = (chunk_info[i][0], chunk_info[i][1], chunk_time) for ch in chunk_info: if ch[1] == 0: continue self.file.seek(ch[0] * 4096) raw_chunk_size = struct.unpack(">I", self.file.read(4))[0] raw_chunk_type = struct.unpack("b", self.file.read(1))[0] raw_chunk_data = self.file.read(raw_chunk_size - 1) #print "-- CHUNK -- (type:" + str(raw_chunk_type) + "," + str(ch) + ") --" if raw_chunk_type > 0: chunk_data = zlib.decompress(raw_chunk_data) else: chunk_data = raw_chunk_data data_buffer = cStringIO.StringIO(chunk_data) tagReader = TagReader(data_buffer) root = tagReader.readTag() self.chunks.append((ch, root))
class MCMap: def __init__(self, path, no_read=False): self.path = path if not no_read: self.read() def read(self): self.file = gzip.open(self.path) self.tagReader = TagReader(self.file) self.root = self.tagReader.readTag() self.file.close() if self.root['data']: for tag_id in self.root['data'].value: tag = self.root['data'][tag_id] if tag.name == 'scale': self.scale = tag.value elif tag.name == 'dimension': self.dimension = tag.value elif tag.name == 'height': self.height = tag.value elif tag.name == 'width': self.width = tag.value elif tag.name == 'xCenter': self.xCenter = tag.value elif tag.name == 'zCenter': self.zCenter = tag.value elif tag.name == 'colors': self.colors = tag.value
class DATFile: def __init__(self, path, no_read=False): self.path = path if not no_read: self.read() def read(self): self.file = gzip.open(self.path) self.tagReader = TagReader(self.file) self.root = self.tagReader.readTag() self.file.close()