You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
use valence::bevy_ecs;
|
|
use valence::{
|
|
entity::player::PlayerEntityBundle,
|
|
prelude::{event::StartDigging, *},
|
|
};
|
|
|
|
use crate::{GameState, CONFIG};
|
|
|
|
#[derive(Component, Debug)]
|
|
pub struct Alive(pub bool);
|
|
|
|
pub fn init_clients(
|
|
mut clients: Query<(Entity, &UniqueId, &mut GameMode), Added<Client>>,
|
|
instances: Query<Entity, With<Instance>>,
|
|
mut commands: Commands,
|
|
) {
|
|
for (entity, uuid, mut game_mode) in &mut clients {
|
|
*game_mode = GameMode::Spectator;
|
|
|
|
commands.entity(entity).insert((
|
|
Alive(false),
|
|
PlayerEntityBundle {
|
|
location: Location(instances.single()),
|
|
position: Position::new([0.0, CONFIG.spawn_y as f64 + 10.0, 0.0]),
|
|
uuid: *uuid,
|
|
..Default::default()
|
|
},
|
|
));
|
|
}
|
|
}
|
|
pub fn break_block(mut instances: Query<&mut Instance>, mut events: EventReader<StartDigging>) {
|
|
let mut instance = instances.single_mut();
|
|
|
|
for event in events.iter() {
|
|
instance.set_block(event.position, BlockState::AIR);
|
|
}
|
|
}
|
|
|
|
pub fn death(
|
|
mut clients: Query<(&mut Client, &mut Position, &mut GameMode, &mut Alive)>,
|
|
state: Res<State<GameState>>,
|
|
) {
|
|
for (mut client, mut pos, mut gamemode, mut alive) in &mut clients {
|
|
if pos.0.y <= 0.0 && state.0 == GameState::Started {
|
|
*gamemode = GameMode::Spectator;
|
|
pos.set([0.0, (CONFIG.spawn_y + 10).into(), 0.0]);
|
|
alive.0 = false;
|
|
|
|
client.send_message("You died!".italic().bold().color(Color::GRAY));
|
|
}
|
|
}
|
|
}
|