python - 如何读取 Minecraft .mca 文件以便在 python 中提取单个块?
问题描述
我找不到一种可以在 python 中使用的方式来读取 Minecraft 世界文件的方法
我环顾了互联网,但找不到任何教程,只有少数图书馆声称他们可以做到这一点,但实际上从来没有工作过
from nbt import *
nbtfile = nbt.NBTFile("r.0.0.mca",'rb')
我希望这可以工作,但我收到有关文件未压缩或类似问题的错误
OSError: 不是压缩文件 (b'\x00\x00')
完整错误:raceback(最近一次通话最后):文件“C:\Users\rober\Desktop\MinePy\MinecraftWorldReader.py”,第 2 行,在 nbtfile = nbt.NBTFile("r.0.0.mca",'rb' ) 文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py”,第 628 行,在init self.parse_file() 文件“C:\ Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py”,第 652 行,在 parse_file 类型 = TAG_Byte(buffer=self.file) 文件“C:\Users \rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py",第 99 行,在init self._parse_buffer(buffer) 文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nbt\nbt.py”,第 105 行,在 _parse_buffer 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 行,在 readinto data = self.read(len( byte_view)) 文件“C:\Users\rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py”,第 463 行,如果不是 self._read_gzip_header(),则在读取:文件“C:\Users \rober\AppData\Local\Programs\Python\Python36-32\lib\gzip.py",第 411 行,在 _read_gzip_header 中引发 OSError('Not a gzipped file (%r)' % magic) OSError:不是 gzip 文件 (b'\x00\x00') [在 0.2s 内完成]
任何帮助,将不胜感激,
罗伯特
解决方案
使用砧解析器。(安装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) # {}
推荐阅读
- asp.net - 在asp.net核心中将一组对象从视图发布到控制器
- c# - 我在 ASP.NET MVC 应用程序的控制器上收到服务器错误
- javascript - 我怎么知道下载文件的总数类型=“文件”倍数?
- sql - 如何在 SQL Server 中创建数据透视表
- elasticsearch - 如果同义词是多词,Elasticsearch 同义词标记过滤器如何工作?
- reactjs - 测试时如何在我的组件之外设置 Formik isSubmitting?
- python - 如何使用 conda 查看已在开发人员模式下安装的所有软件包?
- python - python中的应用函数LabelEncoder().fit_transform
- php - 有人可以解释通过 smsgateway.me api 发送短信时的错误吗?
- assembly - 在汇编中有效地存储数据并使用它进行计算