From 2964a4be35a8b9ad69e6517f5b6782566332dd93 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 1 May 2020 12:23:00 +0100 Subject: [PATCH] making BlockPunchSound server-controlled --- .../mcpe/handler/InGamePacketHandler.php | 1 + src/player/Player.php | 2 + src/world/sound/BlockPunchSound.php | 49 +++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/world/sound/BlockPunchSound.php diff --git a/src/network/mcpe/handler/InGamePacketHandler.php b/src/network/mcpe/handler/InGamePacketHandler.php index 312a7fda9..0a4aa3722 100644 --- a/src/network/mcpe/handler/InGamePacketHandler.php +++ b/src/network/mcpe/handler/InGamePacketHandler.php @@ -756,6 +756,7 @@ 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_HIT: //block punch, maybe entity attack too? case LevelSoundEventPacket::SOUND_LAND: case LevelSoundEventPacket::SOUND_FALL: case LevelSoundEventPacket::SOUND_FALL_SMALL: diff --git a/src/player/Player.php b/src/player/Player.php index 0730fb164..8cf2648fb 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -100,6 +100,7 @@ use pocketmine\world\ChunkLoader; use pocketmine\world\format\Chunk; use pocketmine\world\particle\PunchBlockParticle; use pocketmine\world\Position; +use pocketmine\world\sound\BlockPunchSound; use pocketmine\world\World; use function abs; use function assert; @@ -1583,6 +1584,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, public function continueBreakBlock(Vector3 $pos, int $face) : void{ $block = $this->getWorld()->getBlock($pos); $this->getWorld()->addParticle($pos, new PunchBlockParticle($block, $face)); + $this->getWorld()->addSound($pos, new BlockPunchSound($block)); $this->broadcastEntityEvent(ActorEventPacket::ARM_SWING, null, $this->getViewers()); //TODO: destroy-progress level event diff --git a/src/world/sound/BlockPunchSound.php b/src/world/sound/BlockPunchSound.php new file mode 100644 index 000000000..75b23e02c --- /dev/null +++ b/src/world/sound/BlockPunchSound.php @@ -0,0 +1,49 @@ +block = $block; + } + + public function encode(?Vector3 $pos){ + return LevelSoundEventPacket::create( + LevelSoundEventPacket::SOUND_HIT, + $pos, + $this->block->getRuntimeId() + ); + } +}