aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins/tick_end.rs
blob: 6df46c78076c69b84e9fc421314fa6c3c5ade674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//! Clients send a [`ServerboundClientTickEnd`] packet every tick.

use azalea_core::tick::GameTick;
use azalea_entity::LocalEntity;
use azalea_physics::PhysicsSystems;
use azalea_protocol::packets::game::ServerboundClientTickEnd;
use azalea_world::WorldName;
use bevy_app::{App, Plugin};
use bevy_ecs::prelude::*;

use crate::{mining::MiningSystems, packet::game::SendGamePacketEvent};

/// A plugin that makes clients send a [`ServerboundClientTickEnd`] packet every
/// tick.
pub struct TickEndPlugin;
impl Plugin for TickEndPlugin {
    fn build(&self, app: &mut App) {
        app.add_systems(
            GameTick,
            // this has to happen after every other event that might send packets
            game_tick_packet
                .after(PhysicsSystems)
                .after(MiningSystems)
                .after(crate::movement::send_position),
        );
    }
}

pub fn game_tick_packet(
    query: Query<Entity, (With<LocalEntity>, With<WorldName>)>,
    mut commands: Commands,
) {
    for entity in query.iter() {
        commands.trigger(SendGamePacketEvent::new(entity, ServerboundClientTickEnd));
    }
}