Beispiel #1
0
 def send_air_chunk(self, x, z):
     sections = []
     if x == 0 and z == 0:
         sections = [(BlockArray.empty(self.registry), None)
                     for _ in range(16)]
         sections[9][0][0] = {"name": "minecraft:bedrock"}
     sections_data = self.buff_type.pack_chunk(sections)
     motion_world = PackedArray.empty_height()
     motion_blocking = TagLongArray(PackedArray.empty_height())
     world_surface = TagLongArray(PackedArray.empty_height())
     heightmap = TagRoot({
         "":
         TagCompound({
             "MOTION_BLOCKING": motion_blocking,
             "WORLD_SURFACE": world_surface
         })
     })
     biomes = [27 for _ in range(1024)]
     block_entities = []
     self.send_packet(
         "chunk_data",
         self.buff_type.pack("ii?", x, z, True),
         self.buff_type.pack_chunk_bitmask(sections),
         self.buff_type.pack_nbt(heightmap),  # added in 1.14
         self.buff_type.pack_varint(0),
         b"",
         # b"".join(self.buff_type.pack_varint(biome) for biome in biomes),
         # self.buff_type.pack_array("I", biomes),
         self.buff_type.pack_varint(len(sections_data)),
         sections_data,
         self.buff_type.pack_varint(len(block_entities)),
         b""
         # b"".join(self.buff_type.pack_nbt(entity) for entity in block_entities),
     )
Beispiel #2
0
def test_chunk_internals():
    blocks = BlockArray.empty(OpaqueRegistry(13))
    storage = blocks.storage

    # Accumulate blocks
    added = []
    for i in range(300):
        blocks[i] = i
        added.append(i)

        assert blocks[:i + 1] == added

        if i < 256:
            assert len(blocks.palette) == i + 1
            if i < 16:
                assert storage.value_width == 4
            elif i < 32:
                assert storage.value_width == 5
            elif i < 64:
                assert storage.value_width == 6
            elif i < 128:
                assert storage.value_width == 7
            else:
                assert storage.value_width == 8
        else:
            assert blocks.palette == []
            assert storage.value_width == 13

    # Zero the first 100 blocks
    for i in range(100):
        blocks[i] = 0
    blocks.repack()
    assert len(blocks.palette) == 201
    assert storage.value_width == 8

    # Zero blocks 100-199
    for i in range(100, 200):
        blocks[i] = 0
    blocks.repack()
    assert len(blocks.palette) == 101
    assert storage.value_width == 7

    # Zero blocks 205 - 300
    for i in range(205, 300):
        blocks[i] = 0
    blocks.repack()
    assert len(blocks.palette) == 6
    assert storage.value_width == 4

    # Check value
    for i in range(4096):
        if 200 <= i < 205:
            assert blocks[i] == i
        else:
            assert blocks[i] == 0
Beispiel #3
0
    def packet_downstream_chunk_data(self, buff):
        x, z, contiguous = buff.unpack('ii?')
        bitmask = buff.unpack_varint()
        size = buff.unpack_varint()

        if contiguous:
            chunk = self.chunks[x, z] = {
                'sections': [None] * 16,
                'block_entities': {},
                'block_actions': {}}
        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),
                           LightArray.empty(),
                           LightArray.empty())
            else:
                section = (BlockArray.empty(buff.registry),
                           LightArray.empty())

            chunk['sections'][idx] = section

        if contiguous:
            chunk['biomes'] = buff.unpack('I' * 256)

        for _ in range(buff.unpack_varint()):
            block_entity = buff.unpack_nbt()
            block_entity_obj = block_entity.to_obj()[""]
            chunk['block_entities'][
                block_entity_obj['x'],
                block_entity_obj['y'],
                block_entity_obj['z']] = block_entity