holder; } public function onOpen(Player $who) : void{ parent::onOpen($who); if(count($this->getViewers()) === 1 and ($level = $this->getHolder()->getLevel()) instanceof Level){ $this->broadcastBlockEventPacket(true); $level->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_CHEST_OPEN); } } public function onClose(Player $who) : void{ if(count($this->getViewers()) === 1 and ($level = $this->getHolder()->getLevel()) instanceof Level){ $this->broadcastBlockEventPacket(false); $level->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), LevelSoundEventPacket::SOUND_CHEST_CLOSED); } parent::onClose($who); } protected function broadcastBlockEventPacket(bool $isOpen) : void{ $holder = $this->getHolder(); $pk = new BlockEventPacket(); $pk->x = (int) $holder->x; $pk->y = (int) $holder->y; $pk->z = (int) $holder->z; $pk->eventType = 1; //it's always 1 for a chest $pk->eventData = $isOpen ? 1 : 0; $holder->getLevel()->addChunkPacket($holder->getFloorX() >> 4, $holder->getFloorZ() >> 4, $pk); } }