barneygale / quarry

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

Error while unpacking chunk #98

Closed asdf32768 closed 4 years ago

asdf32768 commented 4 years ago

Hi,

I'm coding a minecraft bot and I'm having some difficulties with unpacking the chunk data. I keep recieving this error:

   File "C:\Users\alexk\PycharmProjects\MC bot\plugins\world.py", line 56, in packet_chunk_data
     self.dimension == 0)
  File "C:\Users\alexk\PycharmProjects\MC bot\venv\lib\site-packages\quarry\types\buffer\v1_9.py", line 75, in             
     unpack_chunk_section
    palette = self.unpack_chunk_section_palette(value_width)
  File "C:\Users\alexk\PycharmProjects\MC bot\venv\lib\site-packages\quarry\types\buffer\v1_9.py", line 92, in     
unpack_chunk_section_palette
    return [self.unpack_varint() for _ in xrange(self.unpack_varint())]
  File "C:\Users\alexk\PycharmProjects\MC bot\venv\lib\site-packages\quarry\types\buffer\v1_9.py", line 92, in <listcomp>
    return [self.unpack_varint() for _ in xrange(self.unpack_varint())]
  File "C:\Users\alexk\PycharmProjects\MC bot\venv\lib\site-packages\quarry\types\buffer\v1_7.py", line 224, in unpack_varint
    % (number_min, number, number_max))
ValueError: varint does not fit in range: -2147483648 <= 545457979376 < 2147483648

Here's the code:

def packet_chunk_data(self, buff):
    x, z, full = buff.unpack('ii?')
    bitmask = buff.unpack_varint()
    size = buff.unpack_varint()

    if full:
        chunk = Chunk(x, z)
        chunk.sections = [None] * 16
        chunk = self.chunks[(x, z)] = chunk
    else:
        chunk = self.chunks[(x, z)]

    for idx in range(16):
        if bitmask & (1 << idx):
            section = buff.unpack_chunk_section(
                self.dimension == 0)
        elif self.dimension == 0:
            section = (BlockArray.empty(buff.registry),
                       PackedArray.empty_light(),
                       PackedArray.empty_light())
        else:
            section = (BlockArray.empty(buff.registry),
                       PackedArray.empty_light())

        chunk.sections[idx] = section

    if full:
        chunk.biomes = buff.unpack('I' * 256)

    buff.discard()

Chunk class:

class Chunk(object):
    def __init__(self, x, z):
        self.x = x
        self.y = z

    x = None
    z = None
    size = None
    biomes = []
    sections = {}
    block_entities = {}
    block_actions = {}