aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src/plugin/mod.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2026-02-21 23:25:40 -0530
committermat <git@matdoes.dev>2026-02-21 23:25:40 -0530
commitb4e4d2c001dddd530c6e416e841c571c7e127138 (patch)
treeff45d9d1bae16be06a1a71651f7ad2f86182b0f9 /azalea-entity/src/plugin/mod.rs
parent2756eb419af2210eed3d0574e20a620918e4e577 (diff)
downloadazalea-drasl-b4e4d2c001dddd530c6e416e841c571c7e127138.tar.xz
enable threaded ecs and implement some micro-optimizations
Diffstat (limited to 'azalea-entity/src/plugin/mod.rs')
-rw-r--r--azalea-entity/src/plugin/mod.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/azalea-entity/src/plugin/mod.rs b/azalea-entity/src/plugin/mod.rs
index b86c6b7d..7c4f3ed4 100644
--- a/azalea-entity/src/plugin/mod.rs
+++ b/azalea-entity/src/plugin/mod.rs
@@ -254,10 +254,10 @@ pub struct InLoadedChunk;
/// Update the [`InLoadedChunk`] component for all entities in the world.
pub fn update_in_loaded_chunk(
mut commands: bevy_ecs::system::Commands,
- query: Query<(Entity, &WorldName, &Position)>,
+ query: Query<(Entity, &WorldName, &Position, Option<&InLoadedChunk>)>,
worlds: Res<Worlds>,
) {
- for (entity, world_name, position) in &query {
+ for (entity, world_name, position, last_in_loaded_chunk) in &query {
let player_chunk_pos = ChunkPos::from(position);
let Some(world_lock) = worlds.get(world_name) else {
commands.entity(entity).remove::<InLoadedChunk>();
@@ -266,9 +266,13 @@ pub fn update_in_loaded_chunk(
let in_loaded_chunk = world_lock.read().chunks.get(&player_chunk_pos).is_some();
if in_loaded_chunk {
- commands.entity(entity).insert(InLoadedChunk);
+ if last_in_loaded_chunk.is_none() {
+ commands.entity(entity).insert(InLoadedChunk);
+ }
} else {
- commands.entity(entity).remove::<InLoadedChunk>();
+ if last_in_loaded_chunk.is_some() {
+ commands.entity(entity).remove::<InLoadedChunk>();
+ }
}
}
}