Skip to content

Commit

Permalink
ctf: implement respawning
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Jul 27, 2023
1 parent f287303 commit 4a32254
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions examples/ctf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use valence::inventory::HeldItem;
use valence::prelude::*;
use valence_client::interact_block::InteractBlockEvent;
use valence_client::message::SendMessage;
use valence_client::status::RequestRespawnEvent;
use valence_entity::cow::CowEntityBundle;
use valence_entity::entity::Flags;
use valence_entity::living::Health;
Expand Down Expand Up @@ -50,6 +51,7 @@ pub fn main() {
// visualize_triggers,
update_clones,
teleport_oob_clients,
necromancy,
),
)
.run();
Expand Down Expand Up @@ -881,3 +883,29 @@ fn teleport_oob_clients(mut clients: Query<(&mut Position, &Team), With<Client>>
}
}
}

/// Handles respawning dead players.
fn necromancy(
mut clients: Query<(
&mut VisibleChunkLayer,
&mut RespawnPosition,
&Team,
&mut Health,
)>,
mut events: EventReader<RequestRespawnEvent>,
layers: Query<Entity, (With<ChunkLayer>, With<EntityLayer>)>,
) {
for event in events.iter() {
if let Ok((mut visible_chunk_layer, mut respawn_pos, team, mut health)) =
clients.get_mut(event.client)
{
respawn_pos.pos = BlockPos::from_pos(team.spawn_pos());
health.0 = 20.0;

let main_layer = layers.single();

// this gets the client to get rid of the respawn screen
visible_chunk_layer.0 = main_layer;
}
}
}

0 comments on commit 4a32254

Please sign in to comment.