Sound no longer extends Vector3

This commit is contained in:
Dylan K. Taylor 2018-12-16 14:26:42 +00:00
parent 3c520aa786
commit 20aaa8373a
23 changed files with 48 additions and 61 deletions

View File

@ -141,7 +141,7 @@ abstract class Door extends Transparent{
} }
$this->level->setBlock($this, $this); $this->level->setBlock($this, $this);
$this->level->addSound(new DoorSound($this)); $this->level->addSound($this, new DoorSound());
return true; return true;
} }

View File

@ -85,7 +85,7 @@ class FenceGate extends Transparent{
} }
$this->getLevel()->setBlock($this, $this); $this->getLevel()->setBlock($this, $this);
$this->level->addSound(new DoorSound($this)); $this->level->addSound($this, new DoorSound());
return true; return true;
} }

View File

@ -476,7 +476,7 @@ abstract class Liquid extends Transparent{
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){
$this->level->setBlock($this, $ev->getNewState()); $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; return true;
} }

View File

@ -89,7 +89,7 @@ class Trapdoor extends Transparent{
public function onActivate(Item $item, Player $player = null) : bool{ public function onActivate(Item $item, Player $player = null) : bool{
$this->open = !$this->open; $this->open = !$this->open;
$this->level->setBlock($this, $this); $this->level->setBlock($this, $this);
$this->level->addSound(new DoorSound($this)); $this->level->addSound($this, new DoorSound());
return true; return true;
} }

View File

@ -60,9 +60,9 @@ class EnderPearl extends Throwable{
//TODO: spawn endermites at origin //TODO: spawn endermites at origin
$this->level->broadcastLevelEvent($owner, LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT); $this->level->broadcastLevelEvent($owner, LevelEventPacket::EVENT_PARTICLE_ENDERMAN_TELEPORT);
$this->level->addSound(new EndermanTeleportSound($owner)); $this->level->addSound($owner, new EndermanTeleportSound());
$owner->teleport($event->getRayTraceResult()->getHitVector()); $owner->teleport($target = $event->getRayTraceResult()->getHitVector());
$this->level->addSound(new EndermanTeleportSound($owner)); $this->level->addSound($target, new EndermanTeleportSound());
$owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_FALL, 5)); $owner->attack(new EntityDamageEvent($owner, EntityDamageEvent::CAUSE_FALL, 5));
} }

View File

@ -77,9 +77,9 @@ class ChorusFruit extends Food{
} }
//Sounds are broadcasted at both source and destination //Sounds are broadcasted at both source and destination
$level->addSound(new EndermanTeleportSound($consumer->asVector3())); $level->addSound($consumer->asVector3(), new EndermanTeleportSound());
$consumer->teleport(new Vector3($x + 0.5, $y + 1, $z + 0.5)); $consumer->teleport($target = new Vector3($x + 0.5, $y + 1, $z + 0.5));
$level->addSound(new EndermanTeleportSound($consumer->asVector3())); $level->addSound($target, new EndermanTeleportSound());
break; break;
} }

View File

@ -450,15 +450,15 @@ class Level implements ChunkManager, Metadatable{
$this->closed = true; $this->closed = true;
} }
public function addSound(Sound $sound, array $players = null){ public function addSound(Vector3 $pos, Sound $sound, array $players = null){
$pk = $sound->encode(); $pk = $sound->encode($pos);
if(!is_array($pk)){ if(!is_array($pk)){
$pk = [$pk]; $pk = [$pk];
} }
if(!empty($pk)){ if(!empty($pk)){
if($players === null){ if($players === null){
foreach($pk as $e){ foreach($pk as $e){
$this->broadcastPacketToViewers($sound, $e); $this->broadcastPacketToViewers($pos, $e);
} }
}else{ }else{
$this->server->broadcastPackets($players, $pk); $this->server->broadcastPackets($players, $pk);

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class AnvilBreakSound extends GenericSound{ class AnvilBreakSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_ANVIL_BREAK, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_BREAK, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class AnvilFallSound extends GenericSound{ class AnvilFallSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_ANVIL_FALL, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_FALL, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class AnvilUseSound extends GenericSound{ class AnvilUseSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_ANVIL_USE, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_ANVIL_USE, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class BlazeShootSound extends GenericSound{ class BlazeShootSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_BLAZE_SHOOT, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_BLAZE_SHOOT, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class ClickSound extends GenericSound{ class ClickSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_CLICK, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_CLICK, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class DoorBumpSound extends GenericSound{ class DoorBumpSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_DOOR_BUMP, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR_BUMP, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class DoorCrashSound extends GenericSound{ class DoorCrashSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_DOOR_CRASH, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR_CRASH, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class DoorSound extends GenericSound{ class DoorSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_DOOR, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_DOOR, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class EndermanTeleportSound extends GenericSound{ class EndermanTeleportSound extends GenericSound{
public function __construct(Vector3 $pos){ public function __construct(){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_ENDERMAN_TELEPORT); parent::__construct(LevelEventPacket::EVENT_SOUND_ENDERMAN_TELEPORT);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class FizzSound extends GenericSound{ class FizzSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_FIZZ, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_FIZZ, $pitch);
} }
} }

View File

@ -33,8 +33,7 @@ class GenericSound extends Sound{
/** @var float */ /** @var float */
protected $pitch = 0; protected $pitch = 0;
public function __construct(Vector3 $pos, int $id, float $pitch = 0){ public function __construct(int $id, float $pitch = 0){
parent::__construct($pos->x, $pos->y, $pos->z);
$this->id = $id; $this->id = $id;
$this->pitch = $pitch * 1000; $this->pitch = $pitch * 1000;
} }
@ -47,10 +46,10 @@ class GenericSound extends Sound{
$this->pitch = $pitch * 1000; $this->pitch = $pitch * 1000;
} }
public function encode(){ public function encode(Vector3 $pos){
$pk = new LevelEventPacket; $pk = new LevelEventPacket;
$pk->evid = $this->id; $pk->evid = $this->id;
$pk->position = $this->asVector3(); $pk->position = $pos;
$pk->data = (int) $this->pitch; $pk->data = (int) $this->pitch;
return $pk; return $pk;

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class GhastShootSound extends GenericSound{ class GhastShootSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_GHAST_SHOOT, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_GHAST_SHOOT, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class GhastSound extends GenericSound{ class GhastSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_GHAST, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_GHAST, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class LaunchSound extends GenericSound{ class LaunchSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_SHOOT, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_SHOOT, $pitch);
} }
} }

View File

@ -23,11 +23,10 @@ declare(strict_types=1);
namespace pocketmine\level\sound; namespace pocketmine\level\sound;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket; use pocketmine\network\mcpe\protocol\LevelEventPacket;
class PopSound extends GenericSound{ class PopSound extends GenericSound{
public function __construct(Vector3 $pos, float $pitch = 0){ public function __construct(float $pitch = 0){
parent::__construct($pos, LevelEventPacket::EVENT_SOUND_POP, $pitch); parent::__construct(LevelEventPacket::EVENT_SOUND_POP, $pitch);
} }
} }

View File

@ -26,11 +26,13 @@ namespace pocketmine\level\sound;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\DataPacket; use pocketmine\network\mcpe\protocol\DataPacket;
abstract class Sound extends Vector3{ abstract class Sound{
/** /**
* @param Vector3 $pos
*
* @return DataPacket|DataPacket[] * @return DataPacket|DataPacket[]
*/ */
abstract public function encode(); abstract public function encode(Vector3 $pos);
} }