Some cleanup to internal sounds handling

This commit is contained in:
Dylan K. Taylor 2019-01-15 21:32:41 +00:00
parent c34a4f45d4
commit f647b1b7a5
15 changed files with 67 additions and 48 deletions

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class AnvilBreakSound extends GenericSound{ class AnvilBreakSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_BREAK, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_ANVIL_BREAK;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class AnvilFallSound extends GenericSound{ class AnvilFallSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_FALL, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_ANVIL_FALL;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class AnvilUseSound extends GenericSound{ class AnvilUseSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_USE, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_ANVIL_USE;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class BlazeShootSound extends GenericSound{ class BlazeShootSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_BLAZE_SHOOT, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_BLAZE_SHOOT;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class ClickSound extends GenericSound{ class ClickSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_CLICK, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_CLICK;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class DoorBumpSound extends GenericSound{ class DoorBumpSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR_BUMP, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_DOOR_BUMP;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class DoorCrashSound extends GenericSound{ class DoorCrashSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR_CRASH, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_DOOR_CRASH;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class DoorSound extends GenericSound{ class DoorSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_DOOR;
} }
} }

View File

@ -25,8 +25,12 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class EndermanTeleportSound extends GenericSound{ class EndermanTeleportSound extends LevelEventSound{
public function __construct(){ public function __construct(){ //don't allow specifying a pitch - TODO: remove pitch from sounds that don't have it
parent::__construct(LevelEventPacket::EVENT_SOUND_ENDERMAN_TELEPORT); parent::__construct();
}
protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_ENDERMAN_TELEPORT;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class FizzSound extends GenericSound{ class FizzSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_FIZZ, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_FIZZ;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class GhastShootSound extends GenericSound{ class GhastShootSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_GHAST_SHOOT, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_GHAST_SHOOT;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class GhastSound extends GenericSound{ class GhastSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_GHAST, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_GHAST;
} }
} }

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class LaunchSound extends GenericSound{ class LaunchSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_SHOOT, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_SHOOT;
} }
} }

View File

@ -26,18 +26,20 @@ namespace pocketmine\level\sound;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class GenericSound extends Sound{ /**
* @internal
*/
abstract class LevelEventSound extends Sound{
/** @var int */
protected $id;
/** @var float */ /** @var float */
protected $pitch = 0; protected $pitch = 0;
public function __construct(int $id, float $pitch = 0){ public function __construct(float $pitch = 0){
$this->id = $id;
$this->pitch = $pitch * 1000; $this->pitch = $pitch * 1000;
} }
abstract protected function getLevelEventId() : int;
public function getPitch() : float{ public function getPitch() : float{
return $this->pitch / 1000; return $this->pitch / 1000;
} }
@ -48,7 +50,7 @@ class GenericSound extends Sound{
public function encode(Vector3 $pos){ public function encode(Vector3 $pos){
$pk = new LevelEventPacket; $pk = new LevelEventPacket;
$pk->evid = $this->id; $pk->evid = $this->getLevelEventId();
$pk->position = $pos; $pk->position = $pos;
$pk->data = (int) $this->pitch; $pk->data = (int) $this->pitch;

View File

@ -25,8 +25,9 @@ namespace pocketmine\level\sound;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class PopSound extends GenericSound{ class PopSound extends LevelEventSound{
public function __construct(float $pitch = 0){
parent::__construct(LevelEventPacket::EVENT_SOUND_POP, $pitch); protected function getLevelEventId() : int{
return LevelEventPacket::EVENT_SOUND_POP;
} }
} }