Skip to content

Commit 2baceb1

Browse files
refactor(client): use .map for queries
1 parent 2aa5d68 commit 2baceb1

1 file changed

Lines changed: 22 additions & 23 deletions

File tree

src/lua/client/world/queries.rs

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
macro_rules! get_entities {
33
($client:ident) => {{
44
let ecs = $client.ecs.read();
5-
if let Some(mut query) = ecs.try_query::<(
5+
ecs.try_query::<(
66
&AzaleaPosition,
77
&CustomName,
88
&EntityKindComponent,
@@ -11,7 +11,8 @@ macro_rules! get_entities {
1111
&MinecraftEntityId,
1212
Option<&Owneruuid>,
1313
&Pose,
14-
)>() {
14+
)>()
15+
.map(|mut query| {
1516
query
1617
.iter(&ecs)
1718
.map(
@@ -29,40 +30,38 @@ macro_rules! get_entities {
2930
},
3031
)
3132
.collect::<Vec<_>>()
32-
} else {
33-
Vec::new()
34-
}
33+
})
34+
.unwrap_or_default()
3535
}};
3636
}
3737

3838
#[macro_export]
3939
macro_rules! get_players {
4040
($client:ident) => {{
4141
let ecs = $client.ecs.read();
42-
if let Some(mut query) = ecs.try_query_filtered::<(
42+
ecs.try_query_filtered::<(
4343
&MinecraftEntityId,
4444
&EntityUuid,
4545
&EntityKindComponent,
4646
&AzaleaPosition,
4747
&LookDirection,
4848
&Pose,
4949
), (With<Player>, Without<Dead>)>()
50-
{
51-
query
52-
.iter(&ecs)
53-
.map(|(id, uuid, kind, position, direction, pose)| {
54-
(
55-
id.0,
56-
uuid.to_string(),
57-
kind.to_string(),
58-
Vec3::from(*position),
59-
Direction::from(direction),
60-
*pose as u8,
61-
)
62-
})
63-
.collect::<Vec<_>>()
64-
} else {
65-
Vec::new()
66-
}
50+
.map(|mut query| {
51+
query
52+
.iter(&ecs)
53+
.map(|(id, uuid, kind, position, direction, pose)| {
54+
(
55+
id.0,
56+
uuid.to_string(),
57+
kind.to_string(),
58+
Vec3::from(*position),
59+
Direction::from(direction),
60+
*pose as u8,
61+
)
62+
})
63+
.collect::<Vec<_>>()
64+
})
65+
.unwrap_or_default()
6766
}};
6867
}

0 commit comments

Comments
 (0)