Exemple #1
0
    def read(self, file_object):
        self.entity_id = VarInt.read(file_object)
        if self._context.protocol_version >= 49:
            self.objectUUID = UUID.read(file_object)
        type_id = Byte.read(file_object)
        self.type = SpawnObjectPacket.EntityType.get_type_by_id(type_id)

        if self._context.protocol_version >= 100:
            self.x = Double.read(file_object)
            self.y = Double.read(file_object)
            self.z = Double.read(file_object)
        else:
            self.x = Integer.read(file_object)
            self.y = Integer.read(file_object)
            self.z = Integer.read(file_object)

        self.pitch = UnsignedByte.read(file_object)
        self.yaw = UnsignedByte.read(file_object)
        self.data = Integer.read(file_object)

        if self._context.protocol_version < 49:
            if self.data > 0:
                self.velocity_x = Short.read(file_object)
                self.velocity_y = Short.read(file_object)
                self.velocity_z = Short.read(file_object)
        else:
            self.velocity_x = Short.read(file_object)
            self.velocity_y = Short.read(file_object)
            self.velocity_z = Short.read(file_object)
    def read(self, file_object):
        if self.context.protocol_version >= 353:
            self.origin = VarInt.read(file_object)
            self.x = Double.read(file_object)
            self.y = Double.read(file_object)
            self.z = Double.read(file_object)
            is_entity = Boolean.read(file_object)
            if is_entity:
                # If the entity given by entity ID cannot be found,
                # this packet should be treated as if is_entity was false.
                self.entity_id = VarInt.read(file_object)
                self.entity_origin = VarInt.read(file_object)
            else:
                self.entity_id = None

        else:  # Protocol version 352
            is_entity = Boolean.read(file_object)
            self.entity_id = VarInt.read(file_object) if is_entity else None
            if not is_entity:
                self.x = Double.read(file_object)
                self.y = Double.read(file_object)
                self.z = Double.read(file_object)
    def write_fields(self, packet_buffer):
        if self.context.protocol_version >= 353:
            VarInt.send(self.origin, packet_buffer)
            Double.send(self.x, packet_buffer)
            Double.send(self.y, packet_buffer)
            Double.send(self.z, packet_buffer)
            if self.entity_id is not None:
                Boolean.send(True, packet_buffer)
                VarInt.send(self.entity_id, packet_buffer)
                VarInt.send(self.entity_origin, packet_buffer)
            else:
                Boolean.send(False, packet_buffer)

        else:  # Protocol version 352
            if self.entity_id is not None:
                Boolean.send(True, packet_buffer)
                VarInt.send(self.entity_id, packet_buffer)
            else:
                Boolean.send(False, packet_buffer)
                Double.send(self.x, packet_buffer)
                Double.send(self.y, packet_buffer)
                Double.send(self.z, packet_buffer)