diff options
| author | mat <git@matdoes.dev> | 2023-05-12 23:20:23 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-05-12 23:20:23 -0500 |
| commit | e977391b0413aaa62ea725a53e4a78c287844f4c (patch) | |
| tree | 8ca64948b685610b81ae7f3f95153acf8a25c003 /azalea-client/src | |
| parent | 741a1f65d669c83710e8c33082b120c189b28f1d (diff) | |
| download | azalea-drasl-e977391b0413aaa62ea725a53e4a78c287844f4c.tar.xz | |
auto respawn
Diffstat (limited to 'azalea-client/src')
| -rw-r--r-- | azalea-client/src/client.rs | 2 | ||||
| -rw-r--r-- | azalea-client/src/lib.rs | 1 | ||||
| -rw-r--r-- | azalea-client/src/respawn.rs | 38 |
3 files changed, 41 insertions, 0 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index 7a4285e6..f2e91dfa 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -11,6 +11,7 @@ use crate::{ movement::{LastSentLookDirection, PlayerMovePlugin}, packet_handling::{self, PacketHandlerPlugin, PacketReceiver}, player::retroactively_add_game_profile_component, + respawn::RespawnPlugin, task_pool::TaskPoolPlugin, Account, PlayerInfo, }; @@ -717,6 +718,7 @@ impl PluginGroup for DefaultPlugins { .add(DisconnectPlugin) .add(PlayerMovePlugin) .add(InteractPlugin) + .add(RespawnPlugin) .add(TickBroadcastPlugin) } } diff --git a/azalea-client/src/lib.rs b/azalea-client/src/lib.rs index c198ced3..2c08033b 100644 --- a/azalea-client/src/lib.rs +++ b/azalea-client/src/lib.rs @@ -25,6 +25,7 @@ mod movement; pub mod packet_handling; pub mod ping; mod player; +pub mod respawn; pub mod task_pool; pub use account::{Account, AccountOpts}; 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(), + ); + } + } +} |
