我找不到一种可以在Python中使用的方式来阅读Minecraft世界文件
我在互联网上找过,但是没有找到教程,只有少数几个库声称他们可以做到这一点,但实际上从来没有工作过
from nbt import *
nbtfile = nbt.NBTFile("r.0.0.mca",'rb')
我期望这个工作,但相反,我得到了关于文件没有被压缩或类似的错误
完整错误:
Traceback (most recent call last):
File "C:\Users\rober\Desktop\MinePy\MinecraftWorldReader.py", line 2, in <module>
nbtfile = nbt.NBTFile("r.0.0.mca",'rb')
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 628, in __init__
self.parse_file()
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 652, in parse_file
type = TAG_Byte(buffer=self.file)
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 99, in __init__
self._parse_buffer(buffer)
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py", line 105, in _parse_buffer
self.value = self.fmt.unpack(buffer.read(self.fmt.size))[0]
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py", line 276, in read
return self._buffer.read(size)
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\_compression.py", line 68, in readinto
data = self.read(len(byte_view))
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py", line 463, in read
if not self._read_gzip_header():
File "C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py", line 411, in _read_gzip_header
raise OSError('Not a gzipped file (%r)' % magic)
OSError: Not a gzipped file (b'\x00\x00')
2条答案
按热度按时间kb5ga3dv1#
使用砧座解析器。(使用
pip install anvil-parser
安装)阅读
https://pypi.org/project/anvil-parser/
x6492ojm2#
根据this page,.mca文件并不完全是NBT文件。它以一个8KiB的头文件开始,其中包括区域文件本身中块的偏移量和这些块的最后更新时间戳。我建议您查看the offical announcement和this page以了解更多信息。