aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-12-11 02:24:31 -0600
committermat <github@matdoes.dev>2022-12-11 02:24:31 -0600
commitb60a55e61ed5ee7a37df20802b6d95543657ea40 (patch)
tree0de5fbd490eddb41f04ead69d1042de8e2c027ea
parent37b9f10b3bcc74b48df2c6843a5286a7d41e2414 (diff)
downloadazalea-drasl-b60a55e61ed5ee7a37df20802b6d95543657ea40.tar.xz
rename find_entity to entity_by & add entities_by
-rwxr-xr-xazalea-world/src/entity_storage.rs27
-rw-r--r--azalea-world/src/world.rs11
-rwxr-xr-xazalea/examples/pvp.rs2
3 files changed, 31 insertions, 9 deletions
diff --git a/azalea-world/src/entity_storage.rs b/azalea-world/src/entity_storage.rs
index 71c5413c..2a4c83ff 100755
--- a/azalea-world/src/entity_storage.rs
+++ b/azalea-world/src/entity_storage.rs
@@ -240,18 +240,18 @@ impl PartialEntityStorage {
.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
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
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()))
}
- 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
F: FnMut(&Arc<EntityData>) -> bool,
{
@@ -366,7 +366,22 @@ impl WeakEntityStorage {
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
F: FnMut(&EntityData) -> bool,
{
diff --git a/azalea-world/src/world.rs b/azalea-world/src/world.rs
index 648613b9..ad6037a5 100644
--- a/azalea-world/src/world.rs
+++ b/azalea-world/src/world.rs
@@ -164,11 +164,18 @@ impl WeakWorld {
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
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> {
diff --git a/azalea/examples/pvp.rs b/azalea/examples/pvp.rs
index 76507e64..9d2fdc35 100755
--- a/azalea/examples/pvp.rs
+++ b/azalea/examples/pvp.rs
@@ -50,7 +50,7 @@ async fn swarm_handle(
if let Some(target) = swarm
.worlds
.read()
- .find_entity(|e| e.id == "minecraft:player")
+ .entity_by(|e| e.id == "minecraft:player")
{
for (bot, bot_state) in swarm {
bot.tick_goto_goal(pathfinder::Goals::Reach(target.bounding_box));