1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00
azalea/azalea-client/src/plugins/respawn.rs
mat e21e1b97bf
Refactor azalea-client (#205)
* start organizing packet_handling more by moving packet handlers into their own functions

* finish writing all the handler functions for packets

* use macro for generating match statement for packet handler functions

* fix set_entity_data

* update config state to also use handler functions

* organize az-client file structure by moving things into plugins directory

* fix merge issues
2025-02-22 21:45:26 -06:00

35 lines
1 KiB
Rust

use azalea_protocol::packets::game::s_client_command::{self, ServerboundClientCommand};
use bevy_app::{App, Plugin, Update};
use bevy_ecs::prelude::*;
use super::packet::game::handle_outgoing_packets;
use crate::packet::game::SendPacketEvent;
/// Tell the server that we're respawning.
#[derive(Event, Debug, Clone)]
pub struct PerformRespawnEvent {
pub entity: Entity,
}
/// A plugin that makes [`PerformRespawnEvent`] send the packet to respawn.
pub struct RespawnPlugin;
impl Plugin for RespawnPlugin {
fn build(&self, app: &mut App) {
app.add_event::<PerformRespawnEvent>()
.add_systems(Update, perform_respawn.before(handle_outgoing_packets));
}
}
pub fn perform_respawn(
mut events: EventReader<PerformRespawnEvent>,
mut send_packets: EventWriter<SendPacketEvent>,
) {
for event in events.read() {
send_packets.send(SendPacketEvent::new(
event.entity,
ServerboundClientCommand {
action: s_client_command::Action::PerformRespawn,
},
));
}
}