def encode(self) -> bytes: return ( Buffer.pack_varint(self.eid) + Buffer.pack("h", self.vel_x) + Buffer.pack("h", self.vel_y) + Buffer.pack("h", self.vel_z) )
def encode(self) -> bytes: out = Buffer.pack_string(self.team_name) + Buffer.pack("b", self.mode) if self.mode == 0: # create team out += (Buffer.pack_chat(Chat(self.data["team_display_name"])) + Buffer.pack("b", self.data["friendly_flags"]) + Buffer.pack_string(self.data["name_tag_visibility"]) + Buffer.pack_string(self.data["collision_rule"]) + Buffer.pack_varint(self.data["team_color"]) + Buffer.pack_chat(Chat(self.data["team_prefix"])) + Buffer.pack_chat(Chat(self.data["team_suffix"])) + Buffer.pack_varint(len(self.data["entities"])) + b"".join( [Buffer.pack_string(e) for e in self.data["entities"]])) elif self.mode == 2: # update team info out += (Buffer.pack_chat(Chat(self.data["team_display_name"])) + Buffer.pack("b", self.data["friendly_flags"]) + Buffer.pack_string(self.data["name_tag_visibility"]) + Buffer.pack_string(self.data["collision_rule"]) + Buffer.pack_varint(self.data["team_color"]) + Buffer.pack_chat(Chat(self.data["team_prefix"])) + Buffer.pack_chat(Chat(self.data["team_suffix"]))) elif self.mode == 3: # add entities to team out += Buffer.pack_varint(len(self.data["entities"])) + b"".join( [Buffer.pack_string(e) for e in self.data["entities"]]) elif self.mode == 4: # remove entities from team out += Buffer.pack_varint(len(self.data["entities"])) + b"".join( [Buffer.pack_string(e) for e in self.data["entities"]]) return out
def encode(self) -> bytes: out = Buffer.pack_varint(self.chunk.x) + Buffer.pack_varint(self.chunk.z) + Buffer.pack("?", True) sky_light_mask = 0 block_light_mask = 0 empty_sky_light_mask = 0 empty_block_light_mask = 0 sky_light_arrays = [] block_light_arrays = [] for y, section in self.chunk.sections.items(): if y >= 0: if section.sky_light is not None: if len(section.sky_light.nonzero()) == 0: empty_sky_light_mask |= 1 << y else: sky_light_mask |= 1 << y data = [] for y in range(16): for z in range(16): for x in range(0, 16, 2): data.append( Buffer.pack("b", section.sky_light[x][y][z] | (section.sky_light[x + 1][y][z] << 4)) ) sky_light_arrays.append(b"".join(data)) if section.block_light is not None: if len(section.block_light.nonzero()) == 0: empty_block_light_mask |= 1 << y else: block_light_mask |= 1 << y data = [] for y in range(16): for z in range(16): for x in range(0, 16, 2): data.append( Buffer.pack( "b", section.block_light[x][y][z] | (section.block_light[x + 1][y][z] << 4) ) ) block_light_arrays.append(b"".join(data)) return ( out + Buffer.pack_varint(sky_light_mask) + Buffer.pack_varint(block_light_mask) + Buffer.pack_varint(empty_sky_light_mask) + Buffer.pack_varint(empty_block_light_mask) + Buffer.pack_varint(len(sky_light_arrays)) + b"".join(sky_light_arrays) + Buffer.pack_varint(len(block_light_arrays)) + b"".join(block_light_arrays) )
def encode(self) -> bytes: return ( Buffer.pack_varint(self.entity_id) + Buffer.pack("f", self.yaw) + Buffer.pack("f", self.pitch) + Buffer.pack("?", self.on_ground) )
def encode(self) -> bytes: return (Buffer.pack_varint(self.window_id) + Buffer.pack("b", len(self.trades)) + b"".join(Buffer.pack_trade(**trade) for trade in self.trades) + Buffer.pack_varint(self.villager_lvl) + Buffer.pack_varint(self.xp) + Buffer.pack("?", self.is_regular) + Buffer.pack("?", self.can_restock))
def encode(self) -> bytes: return ( Buffer.pack("d", self.x) + Buffer.pack("d", self.y) + Buffer.pack("d", self.z) + Buffer.pack("f", self.yaw) + Buffer.pack("f", self.pitch) )
def encode(self) -> bytes: return ( Buffer.pack_varint(self.entity_id) + Buffer.pack("h", self.dx) + Buffer.pack("h", self.dy) + Buffer.pack("h", self.dz) + Buffer.pack("?", self.on_ground) )
def encode(self) -> bytes: return ( Buffer.pack_varint(self.sound_id) + Buffer.pack_varint(self.category) + Buffer.pack_varint(self.eid) + Buffer.pack("f", self.volume) + Buffer.pack("f", self.pitch) )
def encode(self) -> bytes: return (Buffer.pack("i", self.chunk_x) + Buffer.pack("i", self.chunk_z) + Buffer.pack("?", self.trust_edges) + Buffer.pack_varint(self.sky_light_mask) + Buffer.pack_varint(self.block_light_mask) + Buffer.pack_varint(self.empty_sky_light_max) + Buffer.pack_varint(self.empty_block_light_mask) + self.sky_light_array + self.block_light_array)
def encode(self) -> bytes: return (Buffer.pack("i", self.part_id) + Buffer.pack("?", self.long_dist) + Buffer.pack("d", self.x) + Buffer.pack("d", self.y) + Buffer.pack("d", self.z) + Buffer.pack("d", self.off_x) + Buffer.pack("d", self.off_y) + Buffer.pack("d", self.off_z) + Buffer.pack("f", self.part_data) + Buffer.pack("i", self.part_count) + Buffer.pack_particle(self.data))
def encode(self) -> bytes: return ( Buffer.pack("d", self.x) + Buffer.pack("d", self.y) + Buffer.pack("d", self.z) + Buffer.pack("f", self.yaw) + Buffer.pack("f", self.pitch) + self.flags + Buffer.pack_varint(self.tp_id) )
def encode(self) -> bytes: out = (Buffer.pack_varint(self.feet_or_eyes) + Buffer.pack("d", self.tx) + Buffer.pack("d", self.ty) + Buffer.pack("d", self.tz)) if self.is_entity: out += Buffer.pack_varint(self.entity_id) + Buffer.pack_varint( self.entity_feet_or_eyes) return out
def encode(self) -> bytes: return (Buffer.pack("f", self.x) + Buffer.pack("f", self.y) + Buffer.pack("f", self.z) + Buffer.pack("f", self.strength) + Buffer.pack("i", self.record_count) + b"".join([Buffer.pack("b", r) for r in self.records]) + Buffer.pack("f", self.pmx) + Buffer.pack("f", self.pmy) + Buffer.pack("f", self.pmz))
def encode(self) -> bytes: out = Buffer.pack_varint(self.action) if self.action == 0: # set size out += Buffer.pack("d", self.data["diameter"]) elif self.action == 1: # lerp size out += (Buffer.pack("d", self.data["old_diameter"]) + Buffer.pack("d", self.data["new_diameter"]) + Buffer.pack_varint(self.data["speed"])) elif self.action == 2: # set center out += Buffer.pack("d", self.data["x"]) + Buffer.pack( "d", self.data["z"]) elif self.action == 3: # initialize out += (Buffer.pack("d", self.data["x"]) + Buffer.pack("d", self.data["z"]) + Buffer.pack("d", self.data["old_diameter"]) + Buffer.pack("d", self.data["new_diameter"]) + Buffer.pack_varint(self.data["speed"]) + Buffer.pack_varint(self.data["portal_teleport_boundary"]) + Buffer.pack_varint(self.data["warning_blocks"]) + Buffer.pack_varint(self.data["warning_time"])) elif self.action == 4: # set warning time out += Buffer.pack_varint(self.data["warning_time"]) elif self.action == 5: # set warning blocks out += Buffer.pack_varint(self.data["warning_blocks"]) return out
def test_basic(): buf = Buffer() buf.write( Buffer.pack("i", 123) + Buffer.pack("b", 1) + Buffer.pack("?", True) + Buffer.pack("q", 1234567890456)) assert buf.buf == b"\x00\x00\x00{\x01\x01\x00\x00\x01\x1fq\xfb\x06\x18" assert buf.unpack("i") == 123 assert buf.unpack("b") == 1 assert buf.unpack("?") is True assert buf.unpack("q") == 1234567890456
def encode(self) -> bytes: return (Buffer.pack_varint(self.entity_id) + Buffer.pack_uuid(self.object_uuid) + Buffer.pack_varint(self.type_) + Buffer.pack("d" + self.x) + Buffer.pack("d" + self.y) + Buffer.pack("d" + self.z) + Buffer.pack("i" + self.pitch) + Buffer.pack("i" + self.yaw) + Buffer.pack("i", self.head_pitch) + Buffer.pack("h" + self.vloc_x) + Buffer.pack("h" + self.vloc_x) + Buffer.pack("h" + self.vloc_z))
def encode(self) -> bytes: out = (Buffer.pack_varint(self.id) + Buffer.pack_varint(self.start) + Buffer.pack_varint(self.length) + Buffer.pack_varint(len(self.matches))) for m in self.matches: out += Buffer.pack_string(m[0]) if len(m) > 1: out += Buffer.pack("?", True) + Buffer.pack_chat(Chat(m[1])) else: out += Buffer.pack("?", False) return out
def encode(self) -> bytes: return (Buffer.pack("f", self.x) + Buffer.pack("f", self.y) + Buffer.pack("f", self.z) + Buffer.pack("f", self.strength) + Buffer.pack("i", self.record_count) + Buffer.pack_array("b", self.records) + Buffer.pack("f", self.pmx) + Buffer.pack("f", self.pmy) + Buffer.pack("f", self.pmz))
def encode(self) -> bytes: return ( Buffer.pack_position(self.x, self.y, self.z) + Buffer.pack_varint(self.block) + Buffer.pack_varint(self.status) + Buffer.pack("?", self.successful) )
def encode(self) -> bytes: out = Buffer.pack_varint(self.action) if 2 >= self.action >= 0: out += Buffer.pack_chat(Chat(self.data)) elif self.action == 3: out += b"".join([Buffer.pack("i", i) for i in self.data]) return out
def encode(self) -> bytes: out = Buffer.pack_varint(self.entity_id) for prop in self.properties: out += ( Buffer.pack_string(prop["key"]) + Buffer.pack("d", prop["value"]) + Buffer.pack_varint(len(prop["modifiers"])) + b"".join([Buffer.pack_modifier(m) for m in prop["modifiers"]]) )
def encode(self) -> bytes: # Example: # b'\xff\x00\x23\x00\xa7\x00\x31\x00\x00\x00\x34\x00\x37\x00\x00\x00\x31\x00\x2e\x00\x34' \ # b'\x00\x2e\x00\x32\x00\x00\x00\x41\x00\x20\x00\x4d\x00\x69\x00\x6e\x00\x65\x00\x63\x00' \ # b'\x72\x00\x61\x00\x66\x00\x74\x00\x20\x00\x53\x00\x65\x00\x72\x00\x76\x00\x65\x00\x72' \ # b'\x00\x00\x00\x30\x00\x00\x00\x32\x00\x30' out_string = f"§1\x00127\x00{self.motd}\x00{self.players_online}\x00{self.players_max}" return b"\xff" + Buffer.pack( "h", len(out_string)) + out_string.encode("UTF-16BE")
def encode(self) -> bytes: out = (Buffer.pack_varint(self.action) + Buffer.pack("?", self.crafting_book_open) + Buffer.pack("?", self.crafting_book_filter_active) + Buffer.pack("?", self.smelting_book_open) + Buffer.pack("?", self.smelting_book_filter_active) + Buffer.pack("?", self.blast_furnace_book_open) + Buffer.pack("?", self.blast_furnace_book_filter_active) + Buffer.pack("?", self.smoker_book_open) + Buffer.pack("?", self.smoker_book_filter_active) + Buffer.pack_varint(len(self.recipe_ids_1)) + b"".join(Buffer.pack_string(rid) for rid in self.recipe_ids_1)) if self.recipe_ids_2: out += Buffer.pack("?", True) + b"".join( Buffer.pack_string(rid) for rid in self.recipe_ids_2) else: out += Buffer.pack("?", False) return out
def encode(self) -> bytes: return (Buffer.pack("i", self.entity_id) + Buffer.pack("?", self.is_hardcore) + Buffer.pack("B", self.gamemode) + Buffer.pack("b", self.prev_gamemode) + Buffer.pack_varint(len(self.world_names)) + b"".join([Buffer.pack_string(w) for w in self.world_names]) + Buffer.pack_nbt(self.dim_codec) + Buffer.pack_nbt(self.dimension) + Buffer.pack_string(self.world_name) + Buffer.pack("q", self.hashed_seed) + Buffer.pack_varint(self.max_players) + Buffer.pack_varint(self.view_distance) + Buffer.pack("?", self.reduced_debug_info) + Buffer.pack("?", self.enable_respawn_screen) + Buffer.pack("?", self.is_debug) + Buffer.pack("?", self.is_flat))
def encode(self) -> bytes: # See here for data: https://wiki.vg/Protocol#Boss_Bar out = Buffer.pack_uuid(self.uuid) + Buffer.pack_varint(self.action) if self.action == 0: out += ( Buffer.pack_chat(self.data["title"]) + Buffer.pack("f", self.data["health"]) + Buffer.pack_varint(self.data["color"]) + Buffer.pack_varint(self.data["division"]) + Buffer.pack("B", self.data["flags"]) ) elif self.action == 2: out += Buffer.pack("f", self.data["health"]) elif self.action == 3: out += Buffer.pack_chat(self.data["title"]) elif self.action == 4: out += Buffer.pack_varint(self.data["color"]) + Buffer.pack_varint(self.data["division"]) elif self.action == 5: out += Buffer.pack("B", self.data["flags"]) return out
def encode(self) -> bytes: # if self.event == 0: # start combat # return Buffer.pack_varint(self.event) # # if self.event == 1: # end combat # return Buffer.pack_varint(self.event) + Buffer.pack_varint(self.data['duration']) + \ # Buffer.pack('i', self.data['opponent']) if self.event == 2: # entity dead, only one actually used return (Buffer.pack_varint(self.event) + Buffer.pack_varint(self.data["player_id"]) + Buffer.pack("i", self.data["entity_id"]) + Buffer.pack_chat(self.data["message"]))
def encode(self) -> bytes: out = (Buffer.pack_varint(((self.chunk_sect_x & 0x3FFFFF) << 42) | (self.chunk_sect_y & 0xFFFFF) | ( (self.chunk_sect_z & 0x3FFFFF) << 20)) + Buffer.pack("?", self.trust_edges) + Buffer.pack_varint(len(self.blocks))) for block_id, local_x, local_y, local_z in self.blocks: out += Buffer.pack_varint(block_id << 12 | (local_x << 8 | local_z << 4 | local_y)) return out
def encode(self) -> bytes: return (Buffer.pack("d", self.player.x) + Buffer.pack("d", self.player.y) + Buffer.pack("d", self.player.z) + Buffer.pack("f", self.player["Rotation"][0].data) # yaw + Buffer.pack("f", self.player["Rotation"][1].data) # pitch + Buffer.pack("b", self.flags) + Buffer.pack_varint(self.teleport_id))
def encode(self) -> bytes: return (Buffer.pack_string(self.name) + Buffer.pack_varint(self.category) + Buffer.pack("i", self.category) + Buffer.pack("i", self.effect_pos_x) + Buffer.pack("i", self.effect_pos_y) + Buffer.pack("i", self.effect_pos_z) + Buffer.pack("f", self.volume) + Buffer.pack("f", self.pitch))
def encode(self) -> bytes: return (Buffer.pack_nbt(self.dimension) + Buffer.pack_string(self.world_name) + Buffer.pack("l", self.hashed_seed) + Buffer.pack("B", self.gamemode) + Buffer.pack("B", self.prev_gamemode) + Buffer.pack("?", self.is_debug) + Buffer.pack("?", self.is_flat) + Buffer.pack("?", self.copy_metadata))