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.
54 lines
1.6 KiB
54 lines
1.6 KiB
use std::{collections::HashMap, sync::Mutex};
|
|
|
|
use once_cell::sync::Lazy;
|
|
use valence::{
|
|
entity::{axolotl::PlayingDead, living::Health, EntityId},
|
|
packet::WritePacket,
|
|
prelude::{event::PlayerMove, *},
|
|
};
|
|
use valence_protocol::{
|
|
item::FoodComponent,
|
|
packet::s2c::play::{DamageTiltS2c, EntityAnimationS2c, EntityDamageS2c, HealthUpdateS2c},
|
|
var_int::VarInt,
|
|
};
|
|
|
|
static PLAYER_HEIGHT_HISTORY: Lazy<Mutex<HashMap<i32, f64>>> =
|
|
Lazy::new(|| Mutex::new(HashMap::new()));
|
|
|
|
pub fn fall_damage(
|
|
mut clients: Query<(&mut Client, &mut EntityId, &mut Health, &GameMode)>,
|
|
mut events: EventReader<PlayerMove>,
|
|
) {
|
|
for event in events.iter() {
|
|
let (mut client, id, mut health, gamemode) = clients.get_mut(event.client).unwrap();
|
|
|
|
if event.on_ground && *gamemode == GameMode::Survival {
|
|
let fall_distance = PLAYER_HEIGHT_HISTORY
|
|
.lock()
|
|
.unwrap()
|
|
.get(&id.get())
|
|
.unwrap_or(&-1.0)
|
|
- event.position.y;
|
|
|
|
if fall_distance > 3.0 {
|
|
health.0 -= (fall_distance - 3.0) as f32;
|
|
}
|
|
|
|
PLAYER_HEIGHT_HISTORY
|
|
.lock()
|
|
.unwrap()
|
|
.insert(id.get(), event.position.y);
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn death(mut healths: Query<(&mut Client, &mut Health), Changed<Health>>) {
|
|
for (mut client, health) in &mut healths {
|
|
dbg!(health.0);
|
|
if health.0 <= 0.0 {
|
|
tracing::debug!("Trying to kill player");
|
|
client.kill(None, "L bozo");
|
|
}
|
|
}
|
|
}
|