pub fn send_entity_to_player(lazy: &LazyUpdate, player: Entity, entity: Entity) {
    lazy.exec(move |world| {
        // Attempt to get the `PacketCreator` for the entity.
        // If it doesn't exist, skip sending.
        let packet_creators = world.read_component::<PacketCreatorComponent>();
        let packet_creator = match packet_creators.get(entity) {
            Some(packet_creator) => packet_creator,
            None => return,
        };

        let create_packet = packet_creator.0;
        let packet = create_packet(world, entity);

        if let Some(network) = world.read_component::<NetworkComponent>().get(player) {
            send_packet_boxed_to_player(network, packet);

            // If the entity has metadata, send it.
            let metas = world.read_component::<Metadata>();
            if let Some(meta) = metas.get(entity) {
                let packet = PacketEntityMetadata {
                    entity_id: entity.id() as i32,
                    metadata: meta.to_full_raw_metadata(),
                };
                send_packet_to_player(network, packet);
            }
        }

        // Insert last known position
        let positions = world.read_component::<PositionComponent>();
        let mut last_positions = world.write_component::<LastKnownPositionComponent>();
        if let Some(last_positions) = last_positions.get_mut(player) {
            if let Some(pos) = positions.get(entity) {
                last_positions.0.insert(entity, pos.current);
            }
        }

        // Trigger event
        let event = EntitySendEvent { entity, player };
        world.fetch_mut::<EventChannel<_>>().single_write(event);
    });
}
/// Lazily sends an entity to a player.
Lazily sends an entity to a player.
Lazily sends an entity to a player .
pub fn send_entity_to_player(lazy: &LazyUpdate, player: Entity, entity: Entity) {
    lazy.exec(move |world| {
        // Attempt to get the `PacketCreator` for the entity.
        // If it doesn't exist, skip sending.
        let packet_creators = world.read_component::<PacketCreatorComponent>();
        let packet_creator = match packet_creators.get(entity) {
            Some(packet_creator) => packet_creator,
            None => return,
        };
        let create_packet = packet_creator.0;
        let packet = create_packet(world, entity);
        if let Some(network) = world.read_component::<NetworkComponent>().get(player) {
            send_packet_boxed_to_player(network, packet);
            // If the entity has metadata, send it.
            let metas = world.read_component::<Metadata>();
            if let Some(meta) = metas.get(entity) {
                let packet = PacketEntityMetadata {
                    entity_id: entity.id() as i32,
                    metadata: meta.to_full_raw_metadata(),
                };
                send_packet_to_player(network, packet);
            }
        }
        // Insert last known position
        let positions = world.read_component::<PositionComponent>();
        let mut last_positions = world.write_component::<LastKnownPositionComponent>();
        if let Some(last_positions) = last_positions.get_mut(player) {
            if let Some(pos) = positions.get(entity) {
                last_positions.0.insert(entity, pos.current);
            }
        }
        // Trigger event
        let event = EntitySendEvent { entity, player };
        world.fetch_mut::<EventChannel<_>>().single_write(event);
    });
}
pub fn send_entity_to_player ( lazy : & LazyUpdate , player : Entity , entity : Entity ) { lazy . exec ( move | world | { // Attempt to get the `PacketCreator` for the entity. // If it doesn't exist, skip sending. let packet_creators = world . read_component :: < PacketCreatorComponent > ( ) ; let packet_creator = match packet_creators . get ( entity ) { Some ( packet_creator ) => packet_creator , None => return , } ; let create_packet = packet_creator . 0 ; let packet = create_packet ( world , entity ) ; if let Some ( network ) = world . read_component :: < NetworkComponent > ( ) . get ( player ) { send_packet_boxed_to_player ( network , packet ) ; // If the entity has metadata, send it. let metas = world . read_component :: < Metadata > ( ) ; if let Some ( meta ) = metas . get ( entity ) { let packet = PacketEntityMetadata { entity_id : entity . id ( ) as i32 , metadata : meta . to_full_raw_metadata ( ) , } ; send_packet_to_player ( network , packet ) ; } } // Insert last known position let positions = world . read_component :: < PositionComponent > ( ) ; let mut last_positions = world . write_component :: < LastKnownPositionComponent > ( ) ; if let Some ( last_positions ) = last_positions . get_mut ( player ) { if let Some ( pos ) = positions . get ( entity ) { last_positions . 0 . insert ( entity , pos . current ) ; } } // Trigger event let event = EntitySendEvent { entity , player } ; world . fetch_mut :: < EventChannel < _ > > ( ) . single_write ( event ) ; } ) ; }
Lazily sends an entity to a player.
Lazily sends an entity to a player .
lazy
&LazyUpdate
player
Entity
entity
Entity
lazy
&LazyUpdate
player
Entity
entity
Entity