twoolie / NBT

Python Parser/Writer for the NBT file format, and it's container the RegionFile.
MIT License
361 stars 74 forks source link

KeyError: Tag Level does not exist when using Minecraft 1.18.1 worlds. #159

Open ads103 opened 2 years ago

ads103 commented 2 years ago

I tried to use the block_finder example on a Mincraft 1.18.1 world. Upon doing so, this exception was thrown:

>python3 nbtTry.py . 1 1 10 water
Preparing to scan chunk from -9:-9 to chunk 11:11 for a water
Traceback (most recent call last):
  File "nbtTry.py", line 84, in <module>
    sys.exit(main(world_folder, chunkx, chunkz, chunkrange, block))
  File "nbtTry.py", line 33, in main
    chunk = world.get_chunk(chunkx, chunkz)
  File "C:\Users\ads103\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\nbt\world.py", line 183, in get_chunk
    return self.chunkclass(self.get_nbt(x, z))
  File "C:\Users\ads103\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\nbt\chunk.py", line 280, in __init__
    Chunk.__init__(self, nbt)
  File "C:\Users\ads103\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\nbt\chunk.py", line 103, in __init__
    self.chunk_data = nbt['Level']
  File "C:\Users\ads103\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\nbt\nbt.py", line 543, in __getitem__
    raise KeyError("Tag %s does not exist" % key)
KeyError: 'Tag Level does not exist'
alex4200 commented 2 years ago

They made some changes to the tags in 1.18. For an overview please see: https://minecraft.fandom.com/wiki/Chunk_format

LeBogoo commented 2 years ago

Same issue here. Unfortunately i'm way to incompetent to fix this myself. Are there any updates coming soon? I'd love to use this library since it looks pretty solid.

macfreek commented 2 years ago

The NBT library is pretty solid when it comes to parsing the region files and NBT data, but less so when it comes to interpreting it (the functionality in chunk.py). You may even argue that the library would be better with the chunk part removed. That's not done for compatibility reasons.

My recommendation is to use replace (in the above code) world.get_chunk(chunkx, chunkz) with world.get_nbt(chunkx, chunkz) and use that in any way you want. See the example files for some inspiration.