barneygale / quarry

Python library that implements the Minecraft network protocol and data types
Other
532 stars 74 forks source link

BufferUnderrun when reading map #84

Closed jonajames closed 4 years ago

jonajames commented 4 years ago

I wrote a script that reads an mca file and print its content block-by-block When importing a large map my application crashes like so:

Traceback (most recent call last):
  File "...", line 23, in mcaIterator
    try: chunk = region_file.load_chunk(chunk_x,chunk_z)
  File "/usr/lib/python3.8/site-packages/quarry/types/nbt.py", line 332, in load_chunk
    chunk = buff.read(buff.unpack('IB')[0])
  File "/usr/lib/python3.8/site-packages/quarry/types/buffer/v1_7.py", line 75, in read
    raise BufferUnderrun()
quarry.types.buffer.BufferUnderrun

This is my code:

# Iterate over all mca files
def mcaIterator(mca_path,mca_filename):
    registry = OpaqueRegistry(None)
    with RegionFile(mca_path+mca_filename) as region_file:
        for chunk_x in range(0,32):
            for chunk_z in range(0,32):
                    try: chunk = region_file.load_chunk(chunk_x,chunk_z)

Am I doing something wrong? Does it have something to do with the parameter of OpaqueRegistry?

barneygale commented 4 years ago

If you use an OpaqueRegistry I think you need to pass a max_bits value rather than None. In recent versions of minecraft this is 14, in older versions its 13 IIRC.

jonajames commented 4 years ago

Thanks for the reply. The registry is actually never used (if I understand the thing correctly) because I do not encode blocks, I just use the string ids. I also noticed that converting a nonsense file gives the same result, so maybe the chunk was just corrupted?

I'm closing this btw...

barneygale commented 4 years ago

It's a fair point that you shouldn't need to know max_bits when working with on-disk data, because on-disk the world always uses a palette.

I'm considering reworking chunk support for 1.16 so I'll keep this in mind.