From f647b1b7a5c6b18ddecd0222555ac864579f0522 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 15 Jan 2019 21:32:41 +0000 Subject: [PATCH] Some cleanup to internal sounds handling --- src/pocketmine/level/sound/AnvilBreakSound.php | 7 ++++--- src/pocketmine/level/sound/AnvilFallSound.php | 7 ++++--- src/pocketmine/level/sound/AnvilUseSound.php | 7 ++++--- src/pocketmine/level/sound/BlazeShootSound.php | 7 ++++--- src/pocketmine/level/sound/ClickSound.php | 7 ++++--- src/pocketmine/level/sound/DoorBumpSound.php | 7 ++++--- src/pocketmine/level/sound/DoorCrashSound.php | 7 ++++--- src/pocketmine/level/sound/DoorSound.php | 7 ++++--- .../level/sound/EndermanTeleportSound.php | 10 +++++++--- src/pocketmine/level/sound/FizzSound.php | 7 ++++--- src/pocketmine/level/sound/GhastShootSound.php | 7 ++++--- src/pocketmine/level/sound/GhastSound.php | 7 ++++--- src/pocketmine/level/sound/LaunchSound.php | 7 ++++--- .../{GenericSound.php => LevelEventSound.php} | 14 ++++++++------ src/pocketmine/level/sound/PopSound.php | 7 ++++--- 15 files changed, 67 insertions(+), 48 deletions(-) rename src/pocketmine/level/sound/{GenericSound.php => LevelEventSound.php} (85%) diff --git a/src/pocketmine/level/sound/AnvilBreakSound.php b/src/pocketmine/level/sound/AnvilBreakSound.php index fe8560e75..a7dc6a2a7 100644 --- a/src/pocketmine/level/sound/AnvilBreakSound.php +++ b/src/pocketmine/level/sound/AnvilBreakSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class AnvilBreakSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_BREAK, $pitch); +class AnvilBreakSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_ANVIL_BREAK; } } diff --git a/src/pocketmine/level/sound/AnvilFallSound.php b/src/pocketmine/level/sound/AnvilFallSound.php index 910603afc..82fa3c480 100644 --- a/src/pocketmine/level/sound/AnvilFallSound.php +++ b/src/pocketmine/level/sound/AnvilFallSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class AnvilFallSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_FALL, $pitch); +class AnvilFallSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_ANVIL_FALL; } } diff --git a/src/pocketmine/level/sound/AnvilUseSound.php b/src/pocketmine/level/sound/AnvilUseSound.php index b9902edcc..d3862c2d8 100644 --- a/src/pocketmine/level/sound/AnvilUseSound.php +++ b/src/pocketmine/level/sound/AnvilUseSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class AnvilUseSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_USE, $pitch); +class AnvilUseSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_ANVIL_USE; } } diff --git a/src/pocketmine/level/sound/BlazeShootSound.php b/src/pocketmine/level/sound/BlazeShootSound.php index 7050bb82a..c9d32f4bd 100644 --- a/src/pocketmine/level/sound/BlazeShootSound.php +++ b/src/pocketmine/level/sound/BlazeShootSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class BlazeShootSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_BLAZE_SHOOT, $pitch); +class BlazeShootSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_BLAZE_SHOOT; } } diff --git a/src/pocketmine/level/sound/ClickSound.php b/src/pocketmine/level/sound/ClickSound.php index 24d920b0d..79509bd8e 100644 --- a/src/pocketmine/level/sound/ClickSound.php +++ b/src/pocketmine/level/sound/ClickSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class ClickSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_CLICK, $pitch); +class ClickSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_CLICK; } } diff --git a/src/pocketmine/level/sound/DoorBumpSound.php b/src/pocketmine/level/sound/DoorBumpSound.php index 84f4a18c5..88dac8efa 100644 --- a/src/pocketmine/level/sound/DoorBumpSound.php +++ b/src/pocketmine/level/sound/DoorBumpSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class DoorBumpSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR_BUMP, $pitch); +class DoorBumpSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_DOOR_BUMP; } } diff --git a/src/pocketmine/level/sound/DoorCrashSound.php b/src/pocketmine/level/sound/DoorCrashSound.php index bd8ab139e..6946593ed 100644 --- a/src/pocketmine/level/sound/DoorCrashSound.php +++ b/src/pocketmine/level/sound/DoorCrashSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class DoorCrashSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR_CRASH, $pitch); +class DoorCrashSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_DOOR_CRASH; } } diff --git a/src/pocketmine/level/sound/DoorSound.php b/src/pocketmine/level/sound/DoorSound.php index 623b682d7..ee5a52674 100644 --- a/src/pocketmine/level/sound/DoorSound.php +++ b/src/pocketmine/level/sound/DoorSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class DoorSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR, $pitch); +class DoorSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_DOOR; } } diff --git a/src/pocketmine/level/sound/EndermanTeleportSound.php b/src/pocketmine/level/sound/EndermanTeleportSound.php index 4f3230f33..ab8801657 100644 --- a/src/pocketmine/level/sound/EndermanTeleportSound.php +++ b/src/pocketmine/level/sound/EndermanTeleportSound.php @@ -25,8 +25,12 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class EndermanTeleportSound extends GenericSound{ - public function __construct(){ - parent::__construct(LevelEventPacket::EVENT_SOUND_ENDERMAN_TELEPORT); +class EndermanTeleportSound extends LevelEventSound{ + public function __construct(){ //don't allow specifying a pitch - TODO: remove pitch from sounds that don't have it + parent::__construct(); + } + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_ENDERMAN_TELEPORT; } } diff --git a/src/pocketmine/level/sound/FizzSound.php b/src/pocketmine/level/sound/FizzSound.php index 325cdac70..09fb4b9af 100644 --- a/src/pocketmine/level/sound/FizzSound.php +++ b/src/pocketmine/level/sound/FizzSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class FizzSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_FIZZ, $pitch); +class FizzSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_FIZZ; } } diff --git a/src/pocketmine/level/sound/GhastShootSound.php b/src/pocketmine/level/sound/GhastShootSound.php index 3e4320942..0d2b3fe64 100644 --- a/src/pocketmine/level/sound/GhastShootSound.php +++ b/src/pocketmine/level/sound/GhastShootSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class GhastShootSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_GHAST_SHOOT, $pitch); +class GhastShootSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_GHAST_SHOOT; } } diff --git a/src/pocketmine/level/sound/GhastSound.php b/src/pocketmine/level/sound/GhastSound.php index 568f22158..13cd6509f 100644 --- a/src/pocketmine/level/sound/GhastSound.php +++ b/src/pocketmine/level/sound/GhastSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class GhastSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_GHAST, $pitch); +class GhastSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_GHAST; } } diff --git a/src/pocketmine/level/sound/LaunchSound.php b/src/pocketmine/level/sound/LaunchSound.php index e7f28072f..243c5fc2e 100644 --- a/src/pocketmine/level/sound/LaunchSound.php +++ b/src/pocketmine/level/sound/LaunchSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class LaunchSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_SHOOT, $pitch); +class LaunchSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_SHOOT; } } diff --git a/src/pocketmine/level/sound/GenericSound.php b/src/pocketmine/level/sound/LevelEventSound.php similarity index 85% rename from src/pocketmine/level/sound/GenericSound.php rename to src/pocketmine/level/sound/LevelEventSound.php index be8262636..615c238ef 100644 --- a/src/pocketmine/level/sound/GenericSound.php +++ b/src/pocketmine/level/sound/LevelEventSound.php @@ -26,18 +26,20 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class GenericSound extends Sound{ +/** + * @internal + */ +abstract class LevelEventSound extends Sound{ - /** @var int */ - protected $id; /** @var float */ protected $pitch = 0; - public function __construct(int $id, float $pitch = 0){ - $this->id = $id; + public function __construct(float $pitch = 0){ $this->pitch = $pitch * 1000; } + abstract protected function getLevelEventId() : int; + public function getPitch() : float{ return $this->pitch / 1000; } @@ -48,7 +50,7 @@ class GenericSound extends Sound{ public function encode(Vector3 $pos){ $pk = new LevelEventPacket; - $pk->evid = $this->id; + $pk->evid = $this->getLevelEventId(); $pk->position = $pos; $pk->data = (int) $this->pitch; diff --git a/src/pocketmine/level/sound/PopSound.php b/src/pocketmine/level/sound/PopSound.php index bfc56ee3e..126ca9366 100644 --- a/src/pocketmine/level/sound/PopSound.php +++ b/src/pocketmine/level/sound/PopSound.php @@ -25,8 +25,9 @@ namespace pocketmine\level\sound; use pocketmine\network\mcpe\protocol\LevelEventPacket; -class PopSound extends GenericSound{ - public function __construct(float $pitch = 0){ - parent::__construct(LevelEventPacket::EVENT_SOUND_POP, $pitch); +class PopSound extends LevelEventSound{ + + protected function getLevelEventId() : int{ + return LevelEventPacket::EVENT_SOUND_POP; } }