def read(self, file_object): action_id = VarInt.read(file_object) self.action_type = PlayerListItemPacket.Action.type_from_id(action_id) action_count = VarInt.read(file_object) self.actions = [] for i in range(action_count): action = self.action_type() action.read(file_object) self.actions.append(action)
def _read(self, file_object): self.name = String.read(file_object) prop_count = VarInt.read(file_object) self.properties = [] for i in range(prop_count): property = PlayerListItemPacket.PlayerProperty() property.read(file_object) self.properties.append(property) self.gamemode = VarInt.read(file_object) self.ping = VarInt.read(file_object) has_display_name = Boolean.read(file_object) if has_display_name: self.display_name = String.read(file_object) else: self.display_name = None
def _send(self, packet_buffer): String.send(self.name, packet_buffer) VarInt.send(len(self.properties), packet_buffer) for property in self.properties: property.send(packet_buffer) VarInt.send(self.gamemode, packet_buffer) VarInt.send(self.ping, packet_buffer) if self.display_name is not None: Boolean.send(True, packet_buffer) String.send(self.display_name, packet_buffer) else: Boolean.send(False, packet_buffer)
def write(self, packet_buffer): UnsignedByte.send(self.x << 4 | self.z & 0xF, packet_buffer) UnsignedByte.send(self.y, packet_buffer) VarInt.send(self.block_state_id, packet_buffer)
def write_fields(self, packet_buffer): VarInt.send(self.action_type.action_id, packet_buffer) VarInt.send(len(self.actions), packet_buffer) for action in self.actions: action.send(packet_buffer)
def _send(self, packet_buffer): VarInt.send(self.ping, packet_buffer)
def _read(self, file_object): self.ping = VarInt.read(file_object)
def _send(self, packet_buffer): VarInt.send(self.gamemode, packet_buffer)
def _read(self, file_object): self.gamemode = VarInt.read(file_object)