A Minecraft anvil file format parser

matcool, updated 🕥 2022-06-18 20:28:19

anvil-parser

CodeFactor Documentation Status Tests PyPI - Downloads

Simple parser for the Minecraft anvil file format

Installation

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

Usage

Reading

```python 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) # print(block.id) # air print(block.properties) # {} ```

Making own regions

```python import anvil from random import choice

Create a new region with the EmptyRegion class at 0, 0 (in region coords)

region = anvil.EmptyRegion(0, 0)

Create Block objects that are used to set blocks

stone = anvil.Block('minecraft', 'stone') dirt = anvil.Block('minecraft', 'dirt')

Make a 16x16x16 cube of either stone or dirt blocks

for y in range(16): for z in range(16): for x in range(16): region.set_block(choice((stone, dirt)), x, y, z)

Save to a file

region.save('r.0.0.mca') ```

Todo

things to do before 1.0.0 - [x] Proper documentation - [ ] Biomes - [x] CI - [ ] More tests - [ ] Tests for 20w17a+ BlockStates format

Note

Testing done in 1.14.4 and 1.15.2, should work fine for other versions.

Issues

Existing regions are read-only

opened on 2022-12-22 04:21:01 by 9NONAGON

Why. I wanna write to existing regions and change them.

Viewing Block NBT

opened on 2022-11-30 23:43:30 by ZMP-Productions

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??

1.19.x support?

opened on 2022-11-30 01:11:59 by ZMP-Productions

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

KeyError: 'Tag DataVersion does not exist'

opened on 2022-09-03 14:08:02 by SakPetios None

Limit for anvil.Chunk.from_region(region, x, z)

opened on 2022-07-17 15:45:08 by bartnikj

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.

Solution for 1.18+ support

opened on 2022-07-02 16:12:24 by Intergalactyc

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.

mat

do not trust me on maintaining a project for more than a month

GitHub Repository

minecraft minecraft-saves parser minecraft-anvil