aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins/tick_counter.rs
diff options
context:
space:
mode:
authorKumpelinus <kumpelinus@jat.de>2025-07-21 22:28:41 +0200
committerGitHub <noreply@github.com>2025-07-21 15:28:41 -0500
commitdf9d776ff8e3945ce7d367e6cecb54957ee0fd7a (patch)
treeaa72f41953fb05e69b660b092d13ecd76e77c1bd /azalea-client/src/plugins/tick_counter.rs
parentebc2e0c067d8b2c901ae02e032159e2c80eac7bc (diff)
downloadazalea-drasl-df9d776ff8e3945ce7d367e6cecb54957ee0fd7a.tar.xz
Add TicksAlive component (#229)
* Add TicksAlive component * Rename TicksAlive to TicksConnected * Move component to plugins/tick_counter.rs and add doc comment
Diffstat (limited to 'azalea-client/src/plugins/tick_counter.rs')
-rw-r--r--azalea-client/src/plugins/tick_counter.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/azalea-client/src/plugins/tick_counter.rs b/azalea-client/src/plugins/tick_counter.rs
new file mode 100644
index 00000000..21515959
--- /dev/null
+++ b/azalea-client/src/plugins/tick_counter.rs
@@ -0,0 +1,37 @@
+use azalea_core::tick::GameTick;
+use azalea_physics::PhysicsSet;
+use azalea_world::InstanceName;
+
+use bevy_app::{App, Plugin};
+use bevy_ecs::prelude::*;
+
+use crate::{mining::MiningSet, movement::send_position, tick_broadcast::send_tick_broadcast};
+
+/// Counts the number of game ticks elapsed on the **local client** since the
+/// `login` packet was received.
+#[derive(Component, Clone, Debug, Default)]
+pub struct TicksConnected(pub u64);
+
+/// Inserts the counter-increment system into the `GameTick` schedule **before**
+/// physics, mining and movement.
+pub struct TickCounterPlugin;
+
+impl Plugin for TickCounterPlugin {
+ fn build(&self, app: &mut App) {
+ app.add_systems(
+ GameTick,
+ increment_counter
+ .before(PhysicsSet)
+ .before(MiningSet)
+ .before(send_position)
+ .before(send_tick_broadcast),
+ );
+ }
+}
+
+/// Increment the [`GameTickCounter`] on every entity that lives in an instance.
+fn increment_counter(mut query: Query<&mut TicksConnected, With<InstanceName>>) {
+ for mut counter in &mut query {
+ counter.0 += 1;
+ }
+}