예제 #1
0
 def __init__(self, chkx, chkz, path, ext):
     filename = os.path.join(path,
         "r.{}.{}.{}".format(chkx//32, chkz//32, ext))
     with open(filename, "rb") as f:
         ofs = ((chkx%32) + 32*(chkz%32))*4
         f.seek(ofs)
         offset = bytesToInt(f.read(3)) << 12
         f.seek(offset)
         length = bytesToInt(f.read(4))
         compression_type = bytesToInt(f.read(1))
         data = f.read(length - 1) # 1 byte for compression_type
     if compression_type == 1: # Gzip
         udata = zlib.decompress(data, 15+16)
     elif compression_type == 2: # Zlib
         udata = zlib.decompress(data)
     else:
         raise ValueError("Unsupported compression type")
     raw_data = nbt.read(udata)['']['Level']
     self.blocks = []
     if ext == "mca":
         # Anvil file format
         for section in raw_data["Sections"]:
             self.blocks.append(MCBlock(raw_data, (chkx, chkz), section["Y"], True))
     else:
         for yslice in range(8):
             self.blocks.append(MCBlock(raw_data, (chkx, chkz), yslice, False))
예제 #2
0
파일: block.py 프로젝트: fling-/mcimport
 def __init__(self, chkx, chkz, path, ext):
     filename = os.path.join(path,
         "r.{}.{}.{}".format(chkx//32, chkz//32, ext))
     with open(filename, "rb") as f:
         ofs = ((chkx%32) + 32*(chkz%32))*4
         f.seek(ofs)
         offset = bytesToInt(f.read(3)) << 12
         f.seek(offset)
         length = bytesToInt(f.read(4))
         compression_type = bytesToInt(f.read(1))
         data = f.read(length - 1) # 1 byte for compression_type
     if compression_type == 1: # Gzip
         udata = zlib.decompress(data, 15+16)
     elif compression_type == 2: # Zlib
         udata = zlib.decompress(data)
     else:
         raise ValueError("Unsupported compression type")
     raw_data = nbt.read(udata)['']['Level']
     self.blocks = []
     if ext == "mca":
         # Anvil file format
         for section in raw_data["Sections"]:
             self.blocks.append(MCBlock(raw_data, (chkx, chkz), section["Y"], True))
     else:
         for yslice in range(8):
             self.blocks.append(MCBlock(raw_data, (chkx, chkz), yslice, False))
예제 #3
0
    def __init__(self, x, z, path, ext):
        filename = os.path.join(path, "r.{}.{}.{}".format(x // mcvars.REGION_CHUNK_LENGTH, z // mcvars.REGION_CHUNK_LENGTH, ext))
        with open(filename, "rb") as f:
            offset1 = ((x % mcvars.REGION_CHUNK_LENGTH) + mcvars.REGION_CHUNK_LENGTH * (z % mcvars.REGION_CHUNK_LENGTH)) * 4
            f.seek(offset1)
            offset2 = serialize.bytesToInt(f.read(3)) << 12
            f.seek(offset2)
            length = serialize.bytesToInt(f.read(4))
            compression_type = serialize.bytesToInt(f.read(1))
            # 1 byte for compression_type
            data = f.read(length - 1)
        # Gzip
        if compression_type == 1:
            unpackedData = zlib.decompress(data, 15 + 16)
        # Zlib
        elif compression_type == 2:
            unpackedData = zlib.decompress(data)
        else:
            raise ValueError("Unsupported compression type")

        nbt_data = nbt.read(unpackedData)
        level_data = nbt_data[""]["Level"]
        #with open("chunk.json", "w") as jsonf:
            #jsonf.write(json.dumps(nbt_data, indent=4))
        #sys.exit(0)

        self.blocks = []

        if ext == "mca":
            # Anvil file format
            for section in level_data["Sections"]:
                self.blocks.append(MCSection(level_data, section, x, z, section["Y"], True))
        elif ext == "mcr":
            # Old file format
            for yslice in range(8):
                self.blocks.append(MCSection(nbt_data, section, x, z, yslice, False))
예제 #4
0
파일: lazynbt.py 프로젝트: L3viathan/nbt
 def _read(self):
     mtime = os.path.getmtime(self.filename)
     if mtime > self.mtime:
         self.cache = nbt.read(self.filename)
         self.mtime = mtime