pub struct EntityFinder<'w, 's, F = ()>where
F: QueryFilter + 'static,{ /* private fields */ }
Expand description
This system parameter can be used as a shorthand for quickly finding an entity, (or several) close to a given position.
This system parameter allows for additional filtering of entities based off
of ECS marker components, such as With<>
, Without<>
, or Added<>
, etc.
All functions used by this system parameter instance will respect the
applied filter.
use azalea::chat::SendChatEvent;
use azalea::nearest_entity::EntityFinder;
use azalea_entity::metadata::{Player, AbstractMonster};
use azalea_entity::LocalEntity;
use bevy_ecs::system::Query;
use bevy_ecs::prelude::{Entity, EventWriter};
use bevy_ecs::query::With;
/// All bots near aggressive mobs will scream in chat.
pub fn bots_near_aggressive_mobs(
bots: Query<Entity, (With<LocalEntity>, With<Player>)>,
entity_finder: EntityFinder<With<AbstractMonster>>,
mut chat_events: EventWriter<SendChatEvent>,
) {
for bot_id in bots.iter() {
let Some(nearest) = entity_finder.nearest_to_entity(bot_id, 16.0) else {
continue;
};
chat_events.send(SendChatEvent {
entity: bot_id,
content: String::from("Ahhh!"),
});
}
}
Implementations§
Source§impl<'w, 's, 'a, F> EntityFinder<'w, 's, F>where
F: QueryFilter + 'static,
impl<'w, 's, 'a, F> EntityFinder<'w, 's, F>where
F: QueryFilter + 'static,
Sourcepub fn nearest_to_position(
&'a self,
position: &Position,
instance_name: &InstanceName,
max_distance: f64,
) -> Option<Entity>
pub fn nearest_to_position( &'a self, position: &Position, instance_name: &InstanceName, max_distance: f64, ) -> Option<Entity>
Gets the nearest entity to the given position and world instance name.
This method will return None
if there are no entities within range. If
multiple entities are within range, only the closest one is returned.
Sourcepub fn nearest_to_entity(
&'a self,
entity: Entity,
max_distance: f64,
) -> Option<Entity>
pub fn nearest_to_entity( &'a self, entity: Entity, max_distance: f64, ) -> Option<Entity>
Gets the nearest entity to the given entity. This method will return
None
if there are no entities within range. If multiple entities are
within range, only the closest one is returned.
Sourcepub fn nearby_entities_to_position(
&'a self,
position: &'a Position,
instance_name: &'a InstanceName,
max_distance: f64,
) -> impl Iterator<Item = (Entity, f64)> + 'a
pub fn nearby_entities_to_position( &'a self, position: &'a Position, instance_name: &'a InstanceName, max_distance: f64, ) -> impl Iterator<Item = (Entity, f64)> + 'a
This function get an iterator over all nearby entities to the given position within the given maximum distance. The entities in this iterator are not returned in any specific order.
This function returns the Entity ID of nearby entities and their distance away.
Sourcepub fn nearby_entities_to_entity(
&'a self,
entity: Entity,
max_distance: f64,
) -> impl Iterator<Item = (Entity, f64)> + 'a
pub fn nearby_entities_to_entity( &'a self, entity: Entity, max_distance: f64, ) -> impl Iterator<Item = (Entity, f64)> + 'a
This function get an iterator over all nearby entities to the given entity within the given maximum distance. The entities in this iterator are not returned in any specific order.
This function returns the Entity ID of nearby entities and their distance away.
Trait Implementations§
Source§impl<F> SystemParam for EntityFinder<'_, '_, F>where
F: QueryFilter + 'static,
impl<F> SystemParam for EntityFinder<'_, '_, F>where
F: QueryFilter + 'static,
Source§type Item<'w, 's> = EntityFinder<'w, 's, F>
type Item<'w, 's> = EntityFinder<'w, 's, F>
Self
, instantiated with new lifetimes. Read moreSource§fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State
World
] access used by this [SystemParam
]
and creates a new instance of this param’s State
.Source§fn new_archetype(
state: &mut Self::State,
archetype: &Archetype,
system_meta: &mut SystemMeta,
)
fn new_archetype( state: &mut Self::State, archetype: &Archetype, system_meta: &mut SystemMeta, )
Archetype
], registers the components accessed by this [SystemParam
] (if applicable).Source§fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
SystemParam
]’s state.
This is used to apply Commands
during apply_deferred
.Source§unsafe fn get_param<'w, 's>(
state: &'s mut Self::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'w>,
change_tick: Tick,
) -> Self::Item<'w, 's>
unsafe fn get_param<'w, 's>( state: &'s mut Self::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> Self::Item<'w, 's>
SystemParamFunction
. Read moreimpl<'w, 's, F> ReadOnlySystemParam for EntityFinder<'w, 's, F>where
F: QueryFilter + 'static,
Query<'w, 's, (&'static Position, &'static InstanceName), With<MinecraftEntityId>>: ReadOnlySystemParam,
Query<'w, 's, (Entity, &'static InstanceName, &'static Position), (With<MinecraftEntityId>, F)>: ReadOnlySystemParam,
Auto Trait Implementations§
impl<'w, 's, F> Freeze for EntityFinder<'w, 's, F>
impl<'w, 's, F = ()> !RefUnwindSafe for EntityFinder<'w, 's, F>
impl<'w, 's, F> Send for EntityFinder<'w, 's, F>
impl<'w, 's, F> Sync for EntityFinder<'w, 's, F>
impl<'w, 's, F> Unpin for EntityFinder<'w, 's, F>
impl<'w, 's, F = ()> !UnwindSafe for EntityFinder<'w, 's, F>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any
.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any
.