Beispiel #1
0
    def unpack_chunk_section(self, overworld=True):
        """
        Unpacks a chunk section. Returns a sequence of length 4096 (16x16x16).
        """

        non_air, value_width = self.unpack('HB')
        palette = self.unpack_chunk_section_palette(value_width)
        array = self.unpack_chunk_section_array(value_width)
        return BlockArray.from_bytes(bytes=array,
                                     palette=palette,
                                     registry=self.registry,
                                     non_air=non_air,
                                     value_width=value_width), None, None
Beispiel #2
0
def test_wikivg_example():
    # Example from https://wiki.vg/Chunk_Format#Example
    data = bitstring.BitArray(length=13 * 4096)
    data[
        0:
        64] = '0b0000000000100000100001100011000101001000010000011000100001000001'
    data[
        64:
        128] = '0b0000000100000001100010100111001001100000111101101000110010000111'
    data = data.bytes

    blocks = BlockArray.from_bytes(data, 5, OpaqueRegistry(13), [])
    assert blocks[:24] == [
        1, 2, 2, 3, 4, 4, 5, 6, 6, 4, 8, 0, 7, 4, 3, 13, 15, 16, 9, 14, 10, 12,
        0, 2
    ]
Beispiel #3
0
def test_wikivg_example():
    # Example from https://wiki.vg/Chunk_Format#Example
    data = bitstring.BitArray(length=13*4096)
    data[0:64]   = '0b0000000100000000000110001000000011000000000001100000000000100000'
    data[64:128] = '0b0000001000000000110100000000011010000000000001001100000000100000'
    data = data.bytes

    blocks = BlockArray.from_bytes(data, [], BitShiftRegistry(13), 10)
    assert blocks[0] == (2, 0)  # grass
    assert blocks[1] == (3, 0)  # dirt
    assert blocks[2] == (3, 0)  # dirt
    assert blocks[3] == (3, 1)  # coarse dirt
    assert blocks[4] == (1, 0)  # stone
    assert blocks[5] == (1, 0)  # stone
    assert blocks[6] == (1, 3)  # diorite
    assert blocks[7] == (13, 0) # gravel
    assert blocks[8] == (13, 0) # gravel
    assert blocks[9] == (1, 0)  # stone
Beispiel #4
0
    def unpack_chunk_section(self, overworld=True):
        """
        Unpacks a chunk section. Returns a 3-tuple of
        ``(blocks, block_lights, sky_lights)``, where *sky_lights* is ``None``
        when *overworld* is ``False``. The returned values are sequences of
        length 4096 (16x16x16).
        """

        value_width = self.unpack('B')
        palette = self.unpack_chunk_section_palette(value_width)
        array = self.unpack_chunk_section_array(value_width)
        blocks = BlockArray.from_bytes(bytes=array,
                                       palette=palette,
                                       registry=self.registry,
                                       non_air=None,
                                       value_width=value_width)
        block_lights = PackedArray.from_light_bytes(self.read(2048))
        if overworld:
            sky_lights = PackedArray.from_light_bytes(self.read(2048))
        else:
            sky_lights = None

        return blocks, block_lights, sky_lights