|
|
|
@ -24,28 +24,47 @@ 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>,
|
|
|
|
|
mut clients: Query<
|
|
|
|
|
(
|
|
|
|
|
&mut Client,
|
|
|
|
|
&OnGround,
|
|
|
|
|
&mut EntityId,
|
|
|
|
|
&mut Health,
|
|
|
|
|
&GameMode,
|
|
|
|
|
&Position,
|
|
|
|
|
),
|
|
|
|
|
Changed<Position>,
|
|
|
|
|
>,
|
|
|
|
|
mut instances: Query<&Instance>,
|
|
|
|
|
) {
|
|
|
|
|
for event in events.iter() {
|
|
|
|
|
let (_client, id, mut health, gamemode) = clients.get_mut(event.client).unwrap();
|
|
|
|
|
let instance = instances.single();
|
|
|
|
|
for (client, on_ground, id, mut health, gamemode, position) in &mut clients {
|
|
|
|
|
let current_block = instance
|
|
|
|
|
.block(BlockPos {
|
|
|
|
|
x: position.0.x.floor() as i32,
|
|
|
|
|
y: position.0.y.floor() as i32 - 1,
|
|
|
|
|
z: position.0.z.floor() as i32,
|
|
|
|
|
})
|
|
|
|
|
.unwrap();
|
|
|
|
|
let mut hashmap = PLAYER_HEIGHT_HISTORY.lock().unwrap();
|
|
|
|
|
if *gamemode == GameMode::Survival {
|
|
|
|
|
// hack that potentially makes water not apply fall damage?
|
|
|
|
|
if current_block.state().to_kind() == BlockKind::Vine
|
|
|
|
|
|| current_block.state().is_liquid()
|
|
|
|
|
{
|
|
|
|
|
hashmap.insert(id.get(), position.0.y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 on_ground.0 {
|
|
|
|
|
let old_position = hashmap.get(&id.get()).unwrap_or(&-1.0);
|
|
|
|
|
|
|
|
|
|
if fall_distance > 3.0 {
|
|
|
|
|
health.0 -= (fall_distance - 3.0) as f32;
|
|
|
|
|
}
|
|
|
|
|
let delta_y = old_position - position.0.y;
|
|
|
|
|
|
|
|
|
|
PLAYER_HEIGHT_HISTORY
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.insert(id.get(), event.position.y);
|
|
|
|
|
if delta_y > 3.0 {
|
|
|
|
|
health.0 -= (delta_y - 3.0) as f32;
|
|
|
|
|
}
|
|
|
|
|
hashmap.insert(id.get(), position.0.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|