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), )
def send_reset_world(self): data = [ self.protocol.buff_type.pack_varint(0), b'', self.protocol.buff_type.pack_nbt( TagRoot({ '': TagCompound({ "MOTION_BLOCKING": TagLongArray(PackedArray.empty_height()) }) })), self.protocol.buff_type.pack_varint(1024), ] for i in range(1024): data.append(self.protocol.buff_type.pack_varint(127)) data.append(self.protocol.buff_type.pack_varint(0)) data.append(b'') data.append(self.protocol.buff_type.pack_varint(0)) data.append(b'') for x in range(-8, 8): for y in range(-8, 8): self.protocol.send_packet( "chunk_data", self.protocol.buff_type.pack("ii", x, y), *data)
def send_chunk(self, x, z): emptyHeight = TagRoot({"": TagCompound({ "MOTION_BLOCKING": TagLongArray(PackedArray.empty_height()) })}) try: cdpacket = ChunkDataPacket(self.protocol.buff_type, x, z, False, emptyHeight, [None]*16, [1]*256, []) self.protocol.send_packet(cdpacket.type_, *cdpacket.datas) except ValueError: pass
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
def unpackLightArray(buf) -> PackedArray: length = buf.unpack_varint() assert(length == 2048) return PackedArray.from_light_bytes(buf.read(length))
def from_buff(cls, buff): return cls( PackedArray.from_bytes(bytes=buff.read( buff.unpack('i') * (cls.width // 8)), sector_width=cls.width))
def from_buff(cls, buff): length = buff.unpack('i') data = buff.read(length * (cls.width // 8)) return cls(PackedArray.from_bytes(data, length, cls.width, cls.width))