From 20aaa8373a1b37b2f5e12875411a6ec96819a629 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Sun, 16 Dec 2018 14:26:42 +0000 Subject: [PATCH] Sound no longer extends Vector3 --- src/pocketmine/block/Door.php | 2 +- src/pocketmine/block/FenceGate.php | 2 +- src/pocketmine/block/Liquid.php | 2 +- src/pocketmine/block/Trapdoor.php | 2 +- src/pocketmine/entity/projectile/EnderPearl.php | 6 +++--- src/pocketmine/item/ChorusFruit.php | 6 +++--- src/pocketmine/level/Level.php | 6 +++--- src/pocketmine/level/sound/AnvilBreakSound.php | 5 ++--- src/pocketmine/level/sound/AnvilFallSound.php | 5 ++--- src/pocketmine/level/sound/AnvilUseSound.php | 5 ++--- src/pocketmine/level/sound/BlazeShootSound.php | 5 ++--- src/pocketmine/level/sound/ClickSound.php | 5 ++--- src/pocketmine/level/sound/DoorBumpSound.php | 5 ++--- src/pocketmine/level/sound/DoorCrashSound.php | 5 ++--- src/pocketmine/level/sound/DoorSound.php | 5 ++--- src/pocketmine/level/sound/EndermanTeleportSound.php | 5 ++--- src/pocketmine/level/sound/FizzSound.php | 5 ++--- src/pocketmine/level/sound/GenericSound.php | 7 +++---- src/pocketmine/level/sound/GhastShootSound.php | 5 ++--- src/pocketmine/level/sound/GhastSound.php | 5 ++--- src/pocketmine/level/sound/LaunchSound.php | 5 ++--- src/pocketmine/level/sound/PopSound.php | 5 ++--- src/pocketmine/level/sound/Sound.php | 6 ++++-- 23 files changed, 48 insertions(+), 61 deletions(-) diff --git a/src/pocketmine/block/Door.php b/src/pocketmine/block/Door.php index f1221e1b65..5f7dc498d3 100644 --- a/src/pocketmine/block/Door.php +++ b/src/pocketmine/block/Door.php @@ -141,7 +141,7 @@ abstract class Door extends Transparent{ } $this->level->setBlock($this, $this); - $this->level->addSound(new DoorSound($this)); + $this->level->addSound($this, new DoorSound()); return true; } diff --git a/src/pocketmine/block/FenceGate.php b/src/pocketmine/block/FenceGate.php index fdf1a060e6..d17c9e82e5 100644 --- a/src/pocketmine/block/FenceGate.php +++ b/src/pocketmine/block/FenceGate.php @@ -85,7 +85,7 @@ class FenceGate extends Transparent{ } $this->getLevel()->setBlock($this, $this); - $this->level->addSound(new DoorSound($this)); + $this->level->addSound($this, new DoorSound()); return true; } diff --git a/src/pocketmine/block/Liquid.php b/src/pocketmine/block/Liquid.php index d8c3ea9c49..f5de8b964e 100644 --- a/src/pocketmine/block/Liquid.php +++ b/src/pocketmine/block/Liquid.php @@ -476,7 +476,7 @@ abstract class Liquid extends Transparent{ $ev->call(); if(!$ev->isCancelled()){ $this->level->setBlock($this, $ev->getNewState()); - $this->level->addSound(new FizzSound($this->add(0.5, 0.5, 0.5), 2.6 + (lcg_value() - lcg_value()) * 0.8)); + $this->level->addSound($this->add(0.5, 0.5, 0.5), new FizzSound(2.6 + (lcg_value() - lcg_value()) * 0.8)); } return true; } diff --git a/src/pocketmine/block/Trapdoor.php b/src/pocketmine/block/Trapdoor.php index 9466ebeff1..ac6844d286 100644 --- a/src/pocketmine/block/Trapdoor.php +++ b/src/pocketmine/block/Trapdoor.php @@ -89,7 +89,7 @@ class Trapdoor extends Transparent{ public function onActivate(Item $item, Player $player = null) : bool{ $this->open = !$this->open; $this->level->setBlock($this, $this); - $this->level->addSound(new DoorSound($this)); + $this->level->addSound($this, new DoorSound()); return true; } diff --git a/src/pocketmine/entity/projectile/EnderPearl.php b/src/pocketmine/entity/projectile/EnderPearl.php index 2bbdfab5e8..2191a71eed 100644 --- a/src/pocketmine/entity/projectile/EnderPearl.php +++ b/src/pocketmine/entity/projectile/EnderPearl.php @@ -60,9 +60,9 @@ class EnderPearl extends Throwable{ //TODO: spawn endermites at origin $this->level->broadcastLevelEvent($owner, LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT); - $this->level->addSound(new EndermanTeleportSound($owner)); - $owner->teleport($event->getRayTraceResult()->getHitVector()); - $this->level->addSound(new EndermanTeleportSound($owner)); + $this->level->addSound($owner, new EndermanTeleportSound()); + $owner->teleport($target = $event->getRayTraceResult()->getHitVector()); + $this->level->addSound($target, new EndermanTeleportSound()); $owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_FALL, 5)); } diff --git a/src/pocketmine/item/ChorusFruit.php b/src/pocketmine/item/ChorusFruit.php index 7c9b34ed43..91f7131a9a 100644 --- a/src/pocketmine/item/ChorusFruit.php +++ b/src/pocketmine/item/ChorusFruit.php @@ -77,9 +77,9 @@ class ChorusFruit extends Food{ } //Sounds are broadcasted at both source and destination - $level->addSound(new EndermanTeleportSound($consumer->asVector3())); - $consumer->teleport(new Vector3($x + 0.5, $y + 1, $z + 0.5)); - $level->addSound(new EndermanTeleportSound($consumer->asVector3())); + $level->addSound($consumer->asVector3(), new EndermanTeleportSound()); + $consumer->teleport($target = new Vector3($x + 0.5, $y + 1, $z + 0.5)); + $level->addSound($target, new EndermanTeleportSound()); break; } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 7513497bfb..52743230c3 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -450,15 +450,15 @@ class Level implements ChunkManager, Metadatable{ $this->closed = true; } - public function addSound(Sound $sound, array $players = null){ - $pk = $sound->encode(); + public function addSound(Vector3 $pos, Sound $sound, array $players = null){ + $pk = $sound->encode($pos); if(!is_array($pk)){ $pk = [$pk]; } if(!empty($pk)){ if($players === null){ foreach($pk as $e){ - $this->broadcastPacketToViewers($sound, $e); + $this->broadcastPacketToViewers($pos, $e); } }else{ $this->server->broadcastPackets($players, $pk); diff --git a/src/pocketmine/level/sound/AnvilBreakSound.php b/src/pocketmine/level/sound/AnvilBreakSound.php index c144d8833a..fe8560e752 100644 --- a/src/pocketmine/level/sound/AnvilBreakSound.php +++ b/src/pocketmine/level/sound/AnvilBreakSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class AnvilBreakSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_ANVIL_BREAK, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_BREAK, $pitch); } } diff --git a/src/pocketmine/level/sound/AnvilFallSound.php b/src/pocketmine/level/sound/AnvilFallSound.php index a1bb8ce174..910603afcf 100644 --- a/src/pocketmine/level/sound/AnvilFallSound.php +++ b/src/pocketmine/level/sound/AnvilFallSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class AnvilFallSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_ANVIL_FALL, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_FALL, $pitch); } } diff --git a/src/pocketmine/level/sound/AnvilUseSound.php b/src/pocketmine/level/sound/AnvilUseSound.php index 7036e7113b..b9902edcc2 100644 --- a/src/pocketmine/level/sound/AnvilUseSound.php +++ b/src/pocketmine/level/sound/AnvilUseSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class AnvilUseSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_ANVIL_USE, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_USE, $pitch); } } diff --git a/src/pocketmine/level/sound/BlazeShootSound.php b/src/pocketmine/level/sound/BlazeShootSound.php index 2da36d25bf..7050bb82a9 100644 --- a/src/pocketmine/level/sound/BlazeShootSound.php +++ b/src/pocketmine/level/sound/BlazeShootSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class BlazeShootSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_BLAZE_SHOOT, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_BLAZE_SHOOT, $pitch); } } diff --git a/src/pocketmine/level/sound/ClickSound.php b/src/pocketmine/level/sound/ClickSound.php index 9ca035309a..24d920b0d0 100644 --- a/src/pocketmine/level/sound/ClickSound.php +++ b/src/pocketmine/level/sound/ClickSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class ClickSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_CLICK, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_CLICK, $pitch); } } diff --git a/src/pocketmine/level/sound/DoorBumpSound.php b/src/pocketmine/level/sound/DoorBumpSound.php index 0035b1ef77..84f4a18c56 100644 --- a/src/pocketmine/level/sound/DoorBumpSound.php +++ b/src/pocketmine/level/sound/DoorBumpSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class DoorBumpSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_DOOR_BUMP, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR_BUMP, $pitch); } } diff --git a/src/pocketmine/level/sound/DoorCrashSound.php b/src/pocketmine/level/sound/DoorCrashSound.php index e9e817b4b4..bd8ab139ee 100644 --- a/src/pocketmine/level/sound/DoorCrashSound.php +++ b/src/pocketmine/level/sound/DoorCrashSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class DoorCrashSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_DOOR_CRASH, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR_CRASH, $pitch); } } diff --git a/src/pocketmine/level/sound/DoorSound.php b/src/pocketmine/level/sound/DoorSound.php index 2da8ed9190..623b682d79 100644 --- a/src/pocketmine/level/sound/DoorSound.php +++ b/src/pocketmine/level/sound/DoorSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class DoorSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_DOOR, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR, $pitch); } } diff --git a/src/pocketmine/level/sound/EndermanTeleportSound.php b/src/pocketmine/level/sound/EndermanTeleportSound.php index 587a520e8d..4f3230f331 100644 --- a/src/pocketmine/level/sound/EndermanTeleportSound.php +++ b/src/pocketmine/level/sound/EndermanTeleportSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class EndermanTeleportSound extends GenericSound{ - public function __construct(Vector3 $pos){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_ENDERMAN_TELEPORT); + public function __construct(){ + parent::__construct(LevelEventPacket::EVENT_SOUND_ENDERMAN_TELEPORT); } } diff --git a/src/pocketmine/level/sound/FizzSound.php b/src/pocketmine/level/sound/FizzSound.php index 944f9b7462..325cdac707 100644 --- a/src/pocketmine/level/sound/FizzSound.php +++ b/src/pocketmine/level/sound/FizzSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class FizzSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_FIZZ, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_FIZZ, $pitch); } } diff --git a/src/pocketmine/level/sound/GenericSound.php b/src/pocketmine/level/sound/GenericSound.php index 1aba871a3d..be8262636a 100644 --- a/src/pocketmine/level/sound/GenericSound.php +++ b/src/pocketmine/level/sound/GenericSound.php @@ -33,8 +33,7 @@ class GenericSound extends Sound{ /** @var float */ protected $pitch = 0; - public function __construct(Vector3 $pos, int $id, float $pitch = 0){ - parent::__construct($pos->x, $pos->y, $pos->z); + public function __construct(int $id, float $pitch = 0){ $this->id = $id; $this->pitch = $pitch * 1000; } @@ -47,10 +46,10 @@ class GenericSound extends Sound{ $this->pitch = $pitch * 1000; } - public function encode(){ + public function encode(Vector3 $pos){ $pk = new LevelEventPacket; $pk->evid = $this->id; - $pk->position = $this->asVector3(); + $pk->position = $pos; $pk->data = (int) $this->pitch; return $pk; diff --git a/src/pocketmine/level/sound/GhastShootSound.php b/src/pocketmine/level/sound/GhastShootSound.php index 09000042ee..3e4320942b 100644 --- a/src/pocketmine/level/sound/GhastShootSound.php +++ b/src/pocketmine/level/sound/GhastShootSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class GhastShootSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_GHAST_SHOOT, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_GHAST_SHOOT, $pitch); } } diff --git a/src/pocketmine/level/sound/GhastSound.php b/src/pocketmine/level/sound/GhastSound.php index cef339b382..568f221586 100644 --- a/src/pocketmine/level/sound/GhastSound.php +++ b/src/pocketmine/level/sound/GhastSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class GhastSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_GHAST, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_GHAST, $pitch); } } diff --git a/src/pocketmine/level/sound/LaunchSound.php b/src/pocketmine/level/sound/LaunchSound.php index 2ad2e3bfdd..e7f28072f2 100644 --- a/src/pocketmine/level/sound/LaunchSound.php +++ b/src/pocketmine/level/sound/LaunchSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class LaunchSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_SHOOT, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_SHOOT, $pitch); } } diff --git a/src/pocketmine/level/sound/PopSound.php b/src/pocketmine/level/sound/PopSound.php index adb768ac65..bfc56ee3eb 100644 --- a/src/pocketmine/level/sound/PopSound.php +++ b/src/pocketmine/level/sound/PopSound.php @@ -23,11 +23,10 @@ declare(strict_types=1); namespace pocketmine\level\sound; -use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\LevelEventPacket; class PopSound extends GenericSound{ - public function __construct(Vector3 $pos, float $pitch = 0){ - parent::__construct($pos, LevelEventPacket::EVENT_SOUND_POP, $pitch); + public function __construct(float $pitch = 0){ + parent::__construct(LevelEventPacket::EVENT_SOUND_POP, $pitch); } } diff --git a/src/pocketmine/level/sound/Sound.php b/src/pocketmine/level/sound/Sound.php index 641739e899..0c488d14bb 100644 --- a/src/pocketmine/level/sound/Sound.php +++ b/src/pocketmine/level/sound/Sound.php @@ -26,11 +26,13 @@ namespace pocketmine\level\sound; use pocketmine\math\Vector3; use pocketmine\network\mcpe\protocol\DataPacket; -abstract class Sound extends Vector3{ +abstract class Sound{ /** + * @param Vector3 $pos + * * @return DataPacket|DataPacket[] */ - abstract public function encode(); + abstract public function encode(Vector3 $pos); }