22declare(strict_types=1);
24namespace pocketmine\block\inventory;
30trait AnimatedBlockInventoryTrait{
31 use BlockInventoryTrait;
33 public function getViewerCount() : int{
34 return count($this->getViewers());
41 abstract public function getViewers() : array;
43 abstract protected function getOpenSound() : Sound;
45 abstract protected function getCloseSound() : Sound;
47 public function onOpen(Player $who) : void{
50 if($this->holder->isValid() && $this->getViewerCount() === 1){
52 $this->animateBlock(true);
53 $this->holder->getWorld()->addSound($this->holder->add(0.5, 0.5, 0.5), $this->getOpenSound());
57 abstract protected function animateBlock(
bool $isOpen) : void;
59 public function onClose(Player $who) : void{
60 if($this->holder->isValid() && $this->getViewerCount() === 1){
62 $this->animateBlock(
false);
63 $this->holder->getWorld()->addSound($this->holder->add(0.5, 0.5, 0.5), $this->getCloseSound());
65 parent::onClose($who);