Skip to main content

azalea_client/plugins/
tick_end.rs

1//! Clients send a [`ServerboundClientTickEnd`] packet every tick.
2
3use azalea_core::tick::GameTick;
4use azalea_entity::LocalEntity;
5use azalea_physics::PhysicsSystems;
6use azalea_protocol::packets::game::ServerboundClientTickEnd;
7use azalea_world::WorldName;
8use bevy_app::{App, Plugin};
9use bevy_ecs::prelude::*;
10
11use crate::{mining::MiningSystems, packet::game::SendGamePacketEvent};
12
13/// A plugin that makes clients send a [`ServerboundClientTickEnd`] packet every
14/// tick.
15pub struct TickEndPlugin;
16impl Plugin for TickEndPlugin {
17    fn build(&self, app: &mut App) {
18        app.add_systems(
19            GameTick,
20            // this has to happen after every other event that might send
21            // packets
22            game_tick_packet
23                .after(PhysicsSystems)
24                .after(MiningSystems)
25                .after(crate::movement::send_position),
26        );
27    }
28}
29
30pub fn game_tick_packet(
31    query: Query<Entity, (With<LocalEntity>, With<WorldName>)>,
32    mut commands: Commands,
33) {
34    for entity in query.iter() {
35        commands.trigger(SendGamePacketEvent::new(entity, ServerboundClientTickEnd));
36    }
37}