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;
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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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;
}
}