mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
rename find_entity to entity_by & add entities_by
This commit is contained in:
parent
37b9f10b3b
commit
b60a55e61e
3 changed files with 31 additions and 9 deletions
|
@ -240,18 +240,18 @@ impl PartialEntityStorage {
|
||||||
.update_entity_chunk(entity_id, old_chunk, new_chunk);
|
.update_entity_chunk(entity_id, old_chunk, new_chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_entity<F>(&self, mut f: F) -> Option<Arc<EntityData>>
|
pub fn entity_by<F>(&self, mut f: F) -> Option<Arc<EntityData>>
|
||||||
where
|
where
|
||||||
F: FnMut(&Arc<EntityData>) -> bool,
|
F: FnMut(&Arc<EntityData>) -> bool,
|
||||||
{
|
{
|
||||||
self.shared.read().find_entity(|e| f(e))
|
self.shared.read().entity_by(|e| f(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_entity_in_chunk<F>(&self, chunk: &ChunkPos, mut f: F) -> Option<Arc<EntityData>>
|
pub fn entity_by_in_chunk<F>(&self, chunk: &ChunkPos, mut f: F) -> Option<Arc<EntityData>>
|
||||||
where
|
where
|
||||||
F: FnMut(&EntityData) -> bool,
|
F: FnMut(&EntityData) -> bool,
|
||||||
{
|
{
|
||||||
self.shared.read().find_entity_in_chunk(chunk, |e| f(e))
|
self.shared.read().entity_by_in_chunk(chunk, |e| f(e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ impl WeakEntityStorage {
|
||||||
.and_then(|id| self.data_by_id.get(id).and_then(|e| e.upgrade()))
|
.and_then(|id| self.data_by_id.get(id).and_then(|e| e.upgrade()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_entity<F>(&self, mut f: F) -> Option<Arc<EntityData>>
|
pub fn entity_by<F>(&self, mut f: F) -> Option<Arc<EntityData>>
|
||||||
where
|
where
|
||||||
F: FnMut(&Arc<EntityData>) -> bool,
|
F: FnMut(&Arc<EntityData>) -> bool,
|
||||||
{
|
{
|
||||||
|
@ -366,7 +366,22 @@ impl WeakEntityStorage {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_entity_in_chunk<F>(&self, chunk: &ChunkPos, mut f: F) -> Option<Arc<EntityData>>
|
pub fn entities_by<F>(&self, mut f: F) -> Vec<Arc<EntityData>>
|
||||||
|
where
|
||||||
|
F: FnMut(&Arc<EntityData>) -> bool,
|
||||||
|
{
|
||||||
|
let mut entities = Vec::new();
|
||||||
|
for entity in self.entities() {
|
||||||
|
if let Some(entity) = entity.upgrade() {
|
||||||
|
if f(&entity) {
|
||||||
|
entities.push(entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entities
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn entity_by_in_chunk<F>(&self, chunk: &ChunkPos, mut f: F) -> Option<Arc<EntityData>>
|
||||||
where
|
where
|
||||||
F: FnMut(&EntityData) -> bool,
|
F: FnMut(&EntityData) -> bool,
|
||||||
{
|
{
|
||||||
|
|
|
@ -164,11 +164,18 @@ impl WeakWorld {
|
||||||
self.entity_storage.read().get_by_uuid(uuid)
|
self.entity_storage.read().get_by_uuid(uuid)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_entity<F>(&self, mut f: F) -> Option<Arc<EntityData>>
|
pub fn entity_by<F>(&self, mut f: F) -> Option<Arc<EntityData>>
|
||||||
where
|
where
|
||||||
F: FnMut(&EntityData) -> bool,
|
F: FnMut(&EntityData) -> bool,
|
||||||
{
|
{
|
||||||
self.entity_storage.read().find_entity(|entity| f(entity))
|
self.entity_storage.read().entity_by(|e| f(e))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn entities_by<F>(&self, mut f: F) -> Vec<Arc<EntityData>>
|
||||||
|
where
|
||||||
|
F: FnMut(&EntityData) -> bool,
|
||||||
|
{
|
||||||
|
self.entity_storage.read().entities_by(|e| f(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_entity_pos(&self, entity_id: u32, new_pos: Vec3) -> Result<(), MoveEntityError> {
|
pub fn set_entity_pos(&self, entity_id: u32, new_pos: Vec3) -> Result<(), MoveEntityError> {
|
||||||
|
|
|
@ -50,7 +50,7 @@ async fn swarm_handle(
|
||||||
if let Some(target) = swarm
|
if let Some(target) = swarm
|
||||||
.worlds
|
.worlds
|
||||||
.read()
|
.read()
|
||||||
.find_entity(|e| e.id == "minecraft:player")
|
.entity_by(|e| e.id == "minecraft:player")
|
||||||
{
|
{
|
||||||
for (bot, bot_state) in swarm {
|
for (bot, bot_state) in swarm {
|
||||||
bot.tick_goto_goal(pathfinder::Goals::Reach(target.bounding_box));
|
bot.tick_goto_goal(pathfinder::Goals::Reach(target.bounding_box));
|
||||||
|
|
Loading…
Add table
Reference in a new issue