From d3dcb8a4e3482c78aac1f58a9118fb4ccb8e5986 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 4 May 2020 11:50:42 +0100 Subject: [PATCH] moving entity attack sounds to server-side --- .../mcpe/handler/InGamePacketHandler.php | 3 ++ src/player/Player.php | 5 +++ src/world/sound/EntityAttackNoDamageSound.php | 43 +++++++++++++++++++ src/world/sound/EntityAttackSound.php | 43 +++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 src/world/sound/EntityAttackNoDamageSound.php create mode 100644 src/world/sound/EntityAttackSound.php diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index f121d2bd2a..96355daf75 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -757,6 +757,9 @@ class InGamePacketHandler extends PacketHandler{ public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{ //TODO: we want to block out this packet completely, but we don't yet know the full scope of sounds that the client sends us from here switch($packet->sound){ + case LevelSoundEventPacket::SOUND_ATTACK: + case LevelSoundEventPacket::SOUND_ATTACK_NODAMAGE: + case LevelSoundEventPacket::SOUND_ATTACK_STRONG: //TODO: reassess this, seems like the regular attack is never used ?? case LevelSoundEventPacket::SOUND_HIT: //block punch, maybe entity attack too? case LevelSoundEventPacket::SOUND_LAND: case LevelSoundEventPacket::SOUND_FALL: diff --git a/src/player/Player.php b/src/player/Player.php index 32ff6a2ddf..a657be6a43 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -104,6 +104,8 @@ use pocketmine\world\format\Chunk; use pocketmine\world\particle\BlockPunchParticle; use pocketmine\world\Position; use pocketmine\world\sound\BlockPunchSound; +use pocketmine\world\sound\EntityAttackNoDamageSound; +use pocketmine\world\sound\EntityAttackSound; use pocketmine\world\World; use function abs; use function assert; @@ -1686,10 +1688,13 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, $entity->attack($ev); + $soundPos = $entity->getPosition()->add(0, $entity->width / 2, 0); if($ev->isCancelled()){ + $this->getWorld()->addSound($soundPos, new EntityAttackNoDamageSound()); return false; } $this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers()); + $this->getWorld()->addSound($soundPos, new EntityAttackSound()); if($ev->getModifier(EntityDamageEvent::MODIFIER_CRITICAL) > 0 and $entity instanceof Living){ $entity->broadcastAnimation(new CriticalHitAnimation($entity)); diff --git a/src/world/sound/EntityAttackNoDamageSound.php b/src/world/sound/EntityAttackNoDamageSound.php new file mode 100644 index 0000000000..8c2fde1cbb --- /dev/null +++ b/src/world/sound/EntityAttackNoDamageSound.php @@ -0,0 +1,43 @@ +