From e21e1b97bf9337e9f4747cd1b545b1b3a03e2ce7 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sat, 22 Feb 2025 21:45:26 -0600 Subject: 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 --- azalea-client/src/plugins/respawn.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 azalea-client/src/plugins/respawn.rs (limited to 'azalea-client/src/plugins/respawn.rs') diff --git a/azalea-client/src/plugins/respawn.rs b/azalea-client/src/plugins/respawn.rs new file mode 100644 index 00000000..5797406b --- /dev/null +++ b/azalea-client/src/plugins/respawn.rs @@ -0,0 +1,35 @@ +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::() + .add_systems(Update, perform_respawn.before(handle_outgoing_packets)); + } +} + +pub fn perform_respawn( + mut events: EventReader, + mut send_packets: EventWriter, +) { + for event in events.read() { + send_packets.send(SendPacketEvent::new( + event.entity, + ServerboundClientCommand { + action: s_client_command::Action::PerformRespawn, + }, + )); + } +} -- cgit v1.2.3