/// Returns a `Spawn Mob` packet with the given entity type ID.
Returns a `Spawn Mob` packet with the given entity type ID.
Returns a ` Spawn Mob ` packet with the given entity type ID .
pub fn create_mob_packet(world: &World, entity: Entity, type_id: i32) -> Box<dyn Packet> {
    let entity_id = entity.id() as i32;
    let entity_uuid = world
        .read_component::<NamedComponent>()
        .get(entity)
        .map(|named| named.uuid)
        .unwrap_or_else(Uuid::new_v4);
    let positions = world.read_component::<PositionComponent>();
    let position = positions.get(entity).copied().unwrap_or_default();
    let velocities = world.read_component::<VelocityComponent>();
    let velocity = velocities.get(entity).copied().unwrap_or_default();
    let (velocity_x, velocity_y, velocity_z) = protocol_velocity(velocity.0);
    let metadatas = world.read_component::<Metadata>();
    let metadata = metadatas.get(entity).unwrap_or(&EMPTY_METADATA);
    let packet = SpawnMob {
        entity_id,
        entity_uuid,
        ty: type_id,
        x: position.current.x,
        y: position.current.y,
        z: position.current.z,
        yaw: degrees_to_stops(position.current.yaw),
        pitch: degrees_to_stops(position.current.pitch),
        head_pitch: degrees_to_stops(position.current.pitch), // FIXME: is this correct?
        velocity_x,
        velocity_y,
        velocity_z,
        meta: metadata.to_full_raw_metadata(),
    };
    Box::new(packet)
}
pub fn create_mob_packet ( world : & World , entity : Entity , type_id : i32 ) -> Box < dyn Packet > { let entity_id = entity . id ( ) as i32 ; let entity_uuid = world . read_component :: < NamedComponent > ( ) . get ( entity ) . map ( | named | named . uuid ) . unwrap_or_else ( Uuid :: new_v4 ) ; let positions = world . read_component :: < PositionComponent > ( ) ; let position = positions . get ( entity ) . copied ( ) . unwrap_or_default ( ) ; let velocities = world . read_component :: < VelocityComponent > ( ) ; let velocity = velocities . get ( entity ) . copied ( ) . unwrap_or_default ( ) ; let ( velocity_x , velocity_y , velocity_z ) = protocol_velocity ( velocity . 0 ) ; let metadatas = world . read_component :: < Metadata > ( ) ; let metadata = metadatas . get ( entity ) . unwrap_or ( & EMPTY_METADATA ) ; let packet = SpawnMob { entity_id , entity_uuid , ty : type_id , x : position . current . x , y : position . current . y , z : position . current . z , yaw : degrees_to_stops ( position . current . yaw ) , pitch : degrees_to_stops ( position . current . pitch ) , head_pitch : degrees_to_stops ( position . current . pitch ) , // FIXME: is this correct? velocity_x , velocity_y , velocity_z , meta : metadata . to_full_raw_metadata ( ) , } ; Box :: new ( packet ) }
Returns a `Spawn Mob` packet with the given entity type ID.
Returns a ` Spawn Mob ` packet with the given entity type ID .
world
&World
entity
Entity
type_id
i32