【问题标题】:How can read Minecraft .mca files so that in python I can extract individual blocks?如何读取 Minecraft .mca 文件以便在 python 中提取单个块?
【发布时间】:2019-08-07 15:36:03
【问题描述】:

我找不到一种可以在 python 中使用的方式来读取 Minecraft 世界文件

我浏览了互联网,但找不到任何教程,只有少数图书馆声称他们可以做到这一点,但实际上从未工作过

from nbt import *
nbtfile = nbt.NBTFile("r.0.0.mca",'rb')

我希望这可以工作,但我收到了有关文件未压缩或类似问题的错误

OSError: Not a gzipped file (b'\x00\x00')

完整错误: 赛跑(最近一次通话最后): 文件“C:\Users\rober\Desktop\MinePy\MinecraftWorldReader.py”,第 2 行,在 nbtfile = nbt.NBTFile("r.0.0.mca",'rb') init 中的文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py”,第 628 行 self.parse_file() 文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py”,第 652 行,在 parse_file 类型 = TAG_Byte(缓冲区 = self.file) init 中的文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py”,第 99 行 self._parse_buffer(缓冲区) _parse_buffer 中的文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py”,第 105 行 self.value = self.fmt.unpack(buffer.read(self.fmt.size))[0] 文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py”,第 276 行,正在读取 返回 self._buffer.read(size) 文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib_compression.py”,第 68 行,读入 数据 = self.read(len(byte_view)) 文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py”,第 463 行,已读取 如果不是 self._read_gzip_header(): _read_gzip_header 中的文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py”,第 411 行 raise OSError('不是压缩文件 (%r)' % magic) OSError: 不是压缩文件 (b'\x00\x00') [0.2s完成]

任何帮助将不胜感激,

罗伯特

【问题讨论】:

    标签: python minecraft file-handling


    【解决方案1】:

    使用砧解析器。 (使用pip install anvil-parser 安装)

    阅读

    import anvil
    
    region = anvil.Region.from_file('r.0.0.mca')
    
    # You can also provide the region file name instead of the object
    chunk = anvil.Chunk.from_region(region, 0, 0)
    
    # If `section` is not provided, will get it from the y coords
    # and assume it's global
    block = chunk.get_block(0, 0, 0)
    
    print(block) # <Block(minecraft:air)>
    print(block.id) # air
    print(block.properties) # {}
    

    https://pypi.org/project/anvil-parser/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-28
      • 1970-01-01
      • 1970-01-01
      • 2017-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多