diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index f121d2bd2..96355daf7 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 32ff6a2dd..a657be6a4 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 000000000..8c2fde1cb --- /dev/null +++ b/src/world/sound/EntityAttackNoDamageSound.php @@ -0,0 +1,43 @@ +<?php + +/* + * + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * @author PocketMine Team + * @link http://www.pocketmine.net/ + * + * +*/ + +declare(strict_types=1); + +namespace pocketmine\world\sound; + +use pocketmine\math\Vector3; +use pocketmine\network\mcpe\protocol\ClientboundPacket; +use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; + +/** + * Played when a player attacks a mob, but fails to deal damage (e.g. cancelled or attack cooldown). + */ +class EntityAttackNoDamageSound implements Sound{ + + public function encode(?Vector3 $pos){ + return LevelSoundEventPacket::create( + LevelSoundEventPacket::SOUND_ATTACK_NODAMAGE, + $pos, + -1, + "minecraft:player" + ); + } +} diff --git a/src/world/sound/EntityAttackSound.php b/src/world/sound/EntityAttackSound.php new file mode 100644 index 000000000..b1ffd4a56 --- /dev/null +++ b/src/world/sound/EntityAttackSound.php @@ -0,0 +1,43 @@ +<?php + +/* + * + * ____ _ _ __ __ _ __ __ ____ + * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ + * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | + * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ + * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * @author PocketMine Team + * @link http://www.pocketmine.net/ + * + * +*/ + +declare(strict_types=1); + +namespace pocketmine\world\sound; + +use pocketmine\math\Vector3; +use pocketmine\network\mcpe\protocol\ClientboundPacket; +use pocketmine\network\mcpe\protocol\LevelSoundEventPacket; + +/** + * Played when a player attacks a mob, dealing damage. + */ +class EntityAttackSound implements Sound{ + + public function encode(?Vector3 $pos){ + return LevelSoundEventPacket::create( + LevelSoundEventPacket::SOUND_ATTACK_STRONG, //TODO: seems like ATTACK is dysfunctional + $pos, + -1, + "minecraft:player" + ); + } +}