aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/respawn.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-client/src/respawn.rs')
-rw-r--r--azalea-client/src/respawn.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/azalea-client/src/respawn.rs b/azalea-client/src/respawn.rs
new file mode 100644
index 00000000..4e42157c
--- /dev/null
+++ b/azalea-client/src/respawn.rs
@@ -0,0 +1,38 @@
+use azalea_protocol::packets::game::serverbound_client_command_packet::{
+ self, ServerboundClientCommandPacket,
+};
+use bevy_app::{App, Plugin};
+use bevy_ecs::prelude::*;
+
+use crate::LocalPlayer;
+
+/// Tell the server that we're respawning.
+#[derive(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_system(perform_respawn);
+ }
+}
+
+pub fn perform_respawn(
+ mut events: EventReader<PerformRespawnEvent>,
+ mut query: Query<&mut LocalPlayer>,
+) {
+ for event in events.iter() {
+ if let Ok(local_player) = query.get_mut(event.entity) {
+ local_player.write_packet(
+ ServerboundClientCommandPacket {
+ action: serverbound_client_command_packet::Action::PerformRespawn,
+ }
+ .get(),
+ );
+ }
+ }
+}