barneygale / quarry

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

Can't unpack chunk sections #65

Closed dedo1911 closed 5 years ago

dedo1911 commented 5 years ago

Hi, I'm playing around and trying to get block names. I've already loaded the LookupRegistry and so on, but at the downstream_chunk_data I keep getting an error during unpack_chunk_section: builtins.ValueError: varint does not fit in range: -2147483648 <= 65766686694 < 2147483648

def packet_downstream_chunk_data(self, buff):
        buff.save()
        blocks = buff.unpack_chunk_section()
        buff.restore()
        self.downstream.send_packet("chunk_data", buff.read())

Also, I think that unpack_chunk_section documentation is outdated (at least for 1.14) as it's only returning blocks as far as I saw. Any help is apreciated.

CappyT commented 5 years ago

Same issue here. Can't seem to unpack a chunk. Are we sure is a varint?

barneygale commented 5 years ago

The 'Chunk Data' packet has more fields that you'll need to unpack first, such as chunk coords, bitmask, heightmap, etc. unpack_chunk_section() only helps with the chunk sections. There's some code here which works for 1.13: https://github.com/barneygale/minebnc/blob/master/plugins/world.py#L73

barneygale commented 5 years ago

If you want to adapt the code above, I think you need an additional buff.unpack_nbt() to load the heightmap as of 1.14.

barneygale commented 5 years ago

Any joy?

dedo1911 commented 5 years ago

I just a bit of time last night to give it a try but still I get errors on unpack_nbt, tonight I'll try again and see If I can get it to work or ask/report something useful here to get that done Thanks for the moment

barneygale commented 5 years ago

This should work for 1.14.4 if you're using the latest (master) version of quarry:

def packet_chunk_data(self, buff):
    x, z, full = buff.unpack('ii?')
    bitmask = buff.unpack_varint()
    heightmap = buff.unpack_nbt()
    sections, biomes = buff.unpack_chunk(bitmask, full)
    block_entities = [buff.unpack_nbt() for _ in range(buff.unpack_varint())]