Simple parser for the Minecraft anvil file format
This project is available on PyPI and can be installed with pip
pip install anvil-parser
or directly from github
pip install git+https://github.com/matcool/anvil-parser.git
```python import anvil
region = anvil.Region.from_file('r.0.0.mca')
chunk = anvil.Chunk.from_region(region, 0, 0)
section
is not provided, will get it from the y coordsblock = chunk.get_block(0, 0, 0)
print(block) #
```python import anvil from random import choice
EmptyRegion
class at 0, 0 (in region coords)region = anvil.EmptyRegion(0, 0)
Block
objects that are used to set blocksstone = anvil.Block('minecraft', 'stone') dirt = anvil.Block('minecraft', 'dirt')
for y in range(16): for z in range(16): for x in range(16): region.set_block(choice((stone, dirt)), x, y, z)
region.save('r.0.0.mca') ```
things to do before 1.0.0 - [x] Proper documentation - [ ] Biomes - [x] CI - [ ] More tests - [ ] Tests for 20w17a+ BlockStates format
Testing done in 1.14.4 and 1.15.2, should work fine for other versions.
Why. I wanna write to existing regions and change them.
Hey again, I'm struggling to find any documentation on how to read from other locations in a .mca file. How would I go about say... retrieving the command from a command block??
Getting errors that, after looking at other bug reports, seem to originate from minecraft versions. the .mca file im trying to use is in 1.19.2. getting the following eror:
Traceback (most recent call last):
File "c:\Users\Zoe\Desktop\projects\minecraft related\<redacted project name>\scripts\main.py", line 49, in <module>
chunk = anvil.Chunk.from_region(region, 0, 0)
File "C:\Users\Zoe\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\anvil\chunk.py", line 382, in from_region
return cls(nbt_data)
File "C:\Users\Zoe\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\anvil\chunk.py", line 55, in __init__
self.data = nbt_data['Level']
File "C:\Users\Zoe\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\nbt\nbt.py", line 543, in __getitem__
raise KeyError("Tag %s does not exist" % key)
KeyError: 'Tag Level does not exist'
The code:
``` import anvil
region = anvil.Region.from_file('r.0.0.mca') # line 48 chunk = anvil.Chunk.from_region(region, 0, 0) block = chunk.get_block(0, 60, 0) print(block) print(block.id) print(block.properties) ```
* EDIT * anvil-new (pip install anvil-new) works for this mca file
Shouldn't anvil.Chunk.from_region(region, x, z) have 32x32 limit similar to other functions? It seems like it can accept things well beyond those values. I have no idea where do the results come from.
Thanks.
Hey all,
I forked the package and updated what I could to make it 1.18+ compatible. If anyone wants to access it, here's the repo, and here's the PyPi link. You can install it with "pip install anvil-new", and for now the import is still "import anvil" (but I might change that). My fork does only support versions 1.16 and above AFAIK.
All credit to matcool, and if there's anything I forgot to do to give them credit let me know.
minecraft minecraft-saves parser minecraft-anvil