play sound on fall damage

This commit is contained in:
Alexander Medvedev
2025-01-27 21:55:32 +01:00
parent b5bac2926d
commit deda78231a
6 changed files with 32 additions and 9 deletions

View File

@@ -32,7 +32,7 @@ debug = true
[workspace.dependencies]
log = "0.4"
tokio = { version = "1.42", features = [
tokio = { version = "1.43", features = [
"macros",
"net",
"rt-multi-thread",
@@ -50,7 +50,7 @@ rayon = "1.10.0"
parking_lot = { version = "0.12.3", features = ["send_guard"] }
crossbeam = "0.8.4"
uuid = { version = "1.11.0", features = ["serde", "v3", "v4"] }
uuid = { version = "1.12.1", features = ["serde", "v3", "v4"] }
derive_more = { version = "1.0.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

View File

@@ -8,7 +8,7 @@ pumpkin-protocol = { path = "../pumpkin-protocol" }
pumpkin-nbt = { path = "../pumpkin-nbt" }
pumpkin-util = { path = "../pumpkin-util" }
indexmap = { version = "2.7.0", features = ["serde"] }
indexmap = { version = "2.7.1", features = ["serde"] }
serde.workspace = true
serde_json.workspace = true

View File

@@ -27,10 +27,10 @@ num-traits = "0.2"
# Compression
flate2 = "1.0"
lz4 = "1.28.0"
lz4 = "1.28.1"
file-guard = "0.2.0"
indexmap = "2.7.0"
indexmap = "2.7.1"
enum_dispatch = "0.3.13"

View File

@@ -68,7 +68,7 @@ sha2 = "0.10.8"
base64 = "0.22.1"
# icon loading
png = "0.17.15"
png = "0.17.16"
# logging
simple_logger = { version = "5.0.0", features = ["threads"] }
@@ -78,10 +78,10 @@ time = "0.3.37"
chrono = { version = "0.4.39", features = ["serde"]}
# commands
async-trait = "0.1.83"
async-trait = "0.1.85"
# plugins
libloading = "0.8.5"
libloading = "0.8.6"
[build-dependencies]
git-version = "0.3.9"
# This makes it so the entire project doesn't recompile on each build on linux.

View File

@@ -2,6 +2,7 @@ use std::sync::atomic::AtomicI32;
use async_trait::async_trait;
use crossbeam::atomic::AtomicCell;
use pumpkin_data::sound::Sound;
use pumpkin_nbt::tag::NbtTag;
use pumpkin_protocol::client::play::{CDamageEvent, CEntityStatus, CSetEntityMetadata, Metadata};
use pumpkin_util::math::vector3::Vector3;
@@ -135,6 +136,10 @@ impl LivingEntity {
return;
}
self.entity
.play_sound(Self::get_fall_sound(fall_distance as i32))
.await;
// TODO: Play block fall sound
self.damage(damage, 10).await; // Fall
} else if y_diff < 0.0 {
self.fall_distance.store(0.0);
@@ -144,6 +149,14 @@ impl LivingEntity {
}
}
fn get_fall_sound(distance: i32) -> Sound {
if distance > 4 {
Sound::EntityGenericBigFall
} else {
Sound::EntityGenericSmallFall
}
}
/// Kills the Entity
///
/// This is similar to `kill` but Spawn Particles, Animation and plays death sound

View File

@@ -3,7 +3,10 @@ use std::sync::{atomic::AtomicBool, Arc};
use async_trait::async_trait;
use crossbeam::atomic::AtomicCell;
use pumpkin_data::entity::{EntityPose, EntityType};
use pumpkin_data::{
entity::{EntityPose, EntityType},
sound::{Sound, SoundCategory},
};
use pumpkin_nbt::{compound::NbtCompound, tag::NbtTag};
use pumpkin_protocol::{
client::play::{
@@ -296,6 +299,13 @@ impl Entity {
self.world.broadcast_packet_all(&packet).await;
}
/// Plays sound at this entity's position with the entity's sound category
pub async fn play_sound(&self, sound: Sound) {
self.world
.play_sound(sound, SoundCategory::Neutral, &self.pos.load())
.await;
}
pub async fn set_pose(&self, pose: EntityPose) {
self.pose.store(pose);
let pose = pose as i32;