Skip to content

Commit 4a32254

Browse files
committed
ctf: implement respawning
1 parent f287303 commit 4a32254

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

examples/ctf.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use valence::inventory::HeldItem;
1010
use valence::prelude::*;
1111
use valence_client::interact_block::InteractBlockEvent;
1212
use valence_client::message::SendMessage;
13+
use valence_client::status::RequestRespawnEvent;
1314
use valence_entity::cow::CowEntityBundle;
1415
use valence_entity::entity::Flags;
1516
use valence_entity::living::Health;
@@ -50,6 +51,7 @@ pub fn main() {
5051
// visualize_triggers,
5152
update_clones,
5253
teleport_oob_clients,
54+
necromancy,
5355
),
5456
)
5557
.run();
@@ -881,3 +883,29 @@ fn teleport_oob_clients(mut clients: Query<(&mut Position, &Team), With<Client>>
881883
}
882884
}
883885
}
886+
887+
/// Handles respawning dead players.
888+
fn necromancy(
889+
mut clients: Query<(
890+
&mut VisibleChunkLayer,
891+
&mut RespawnPosition,
892+
&Team,
893+
&mut Health,
894+
)>,
895+
mut events: EventReader<RequestRespawnEvent>,
896+
layers: Query<Entity, (With<ChunkLayer>, With<EntityLayer>)>,
897+
) {
898+
for event in events.iter() {
899+
if let Ok((mut visible_chunk_layer, mut respawn_pos, team, mut health)) =
900+
clients.get_mut(event.client)
901+
{
902+
respawn_pos.pos = BlockPos::from_pos(team.spawn_pos());
903+
health.0 = 20.0;
904+
905+
let main_layer = layers.single();
906+
907+
// this gets the client to get rid of the respawn screen
908+
visible_chunk_layer.0 = main_layer;
909+
}
910+
}
911+
}

0 commit comments

Comments
 (0)