如何读取Minecraft .mca文件,以便在python中提取单个块? [英] How can read Minecraft .mca files so that in python I can extract individual blocks?

查看:197
本文介绍了如何读取Minecraft .mca文件,以便在python中提取单个块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我看过互联网,但找不到任何教程,只有少数图书馆声称可以做到,但实际上却行不通

来自nbt导入的

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

我希望它能正常工作,但我收到有关文件未压缩或类似问题的错误

OSError:不是压缩文件(b'\ x00 \ x00')

完整错误:比赛(最近一次通话过去):文件"C:\ Users \ rober \ Desktop \ MinePy \ MinecraftWorldReader.py",第2行,在nbtfile = nbt.NBTFile("r.0.0.mca",'rb') init 中的第628行的文件"C:\ Users \ rober \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ nbt \ nbt.py"self.parse_file()在parse_file中,文件"C:\ Users \ rober \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ nbt \ nbt.py",第652行类型= TAG_Byte(buffer = self.file) init 中的文件"C:\ Users \ rober \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ nbt \ nbt.py",第99行self._parse_buffer(缓冲区)_parse_buffer中的第105行,文件"C:\ Users \ rober \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ nbt \ nbt.py"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中的第411行的文件"C:\ Users \ rober \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ gzip.py"引发OSError('不是gzip压缩文件(%r)'%magic)OSError:不是压缩文件(b'\ x00 \ x00')[以0.2秒完成]

任何帮助,我们都会感激的,

罗伯特

解决方案

使用砧分析器.(使用 pip install anvil-parser 安装)

阅读

 导入砧区域= anvil.Region.from_file('r.0.0.mca')#您也可以提供区域文件名而不是对象块= anvil.chunk.from_region(区域,0,0)#如果未提供`section`,则将从y坐标中获取#并假设它是全球性的块= chunk.get_block(0,0,0)print(block)#< Block(minecraft:air)>打印(block.id)#空气print(block.properties)#{} 

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

I can't find a way of reading the Minecraft world files in a way that i could use in python

I've looked around the internet but can find no tutorials and only a few libraries that claim that they can do this but never actually work

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

I expected this to work but instead I got errors about the file not being compressed or something of the sort

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

Full errors: raceback (most recent call last): File "C:\Users\rober\Desktop\MinePy\MinecraftWorldReader.py", line 2, in 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') [Finished in 0.2s]

Any help would be appreciated,

Robert

解决方案

Use anvil parser. (Install with pip install anvil-parser)

Reading

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/

这篇关于如何读取Minecraft .mca文件,以便在python中提取单个块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆