Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace AlperCore\Nerzox\Drawer;
- use pocketmine\inventory\ContainerInventory;
- use pocketmine\network\mcpe\protocol\BlockEventPacket;
- use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
- use pocketmine\network\mcpe\protocol\types\WindowTypes;
- use pocketmine\Player;
- class DrawerInventory extends ContainerInventory {
- protected $holder;
- public function __construct(DrawerTile $tile){
- parent::__construct($tile);
- }
- public function getNetworkType() : int{
- return WindowTypes::CONTAINER;
- }
- public function getName() : string{
- return "Drawer";
- }
- public function getSize(): int
- {
- return 1;
- }
- public function getDefaultSize() : int{
- return 1;
- }
- public function getHolder(){
- return $this->holder;
- }
- protected function getOpenSound() : int{
- return LevelSoundEventPacket::SOUND_CHEST_OPEN;
- }
- protected function getCloseSound() : int{
- return LevelSoundEventPacket::SOUND_CHEST_CLOSED;
- }
- public function onOpen(Player $who) : void{
- parent::onOpen($who);
- if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){
- $this->broadcastBlockEventPacket(true);
- $this->getHolder()->getLevelNonNull()->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), $this->getOpenSound());
- }
- }
- public function onClose(Player $who) : void{
- if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){
- $this->broadcastBlockEventPacket(false);
- $this->getHolder()->getLevelNonNull()->broadcastLevelSoundEvent($this->getHolder()->add(0.5, 0.5, 0.5), $this->getCloseSound());
- }
- 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->getLevelNonNull()->broadcastPacketToViewers($holder, $pk);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement