pocketmine\network\protocol\ContainerOpenPacket::encode PHP Method

encode() public method

public encode ( )
    public function encode()
    {
        $this->reset();
        $this->putByte($this->windowid);
        $this->putByte($this->type);
        $this->putShort($this->slots);
        $this->putInt($this->x);
        $this->putInt($this->y);
        $this->putInt($this->z);
        $this->putLong($this->entityId);
    }

Usage Example

Example #1
0
 public static function openChest(Block $chest, Player $player)
 {
     if ($chest->getId() === Item::CHEST) {
         if ($player->gamemode === Player::CREATIVE) {
             $player->sendMessage("[HG] You are in creative Mode");
             return;
         }
         if (!$player->isOp()) {
             $pk = new ContainerOpenPacket();
             $pk->windowid = $player->getWindowId($player->getInventory());
             $pk->type = InventoryType::CHEST;
             $pk->slots = $player->getInventory()->getSize();
             $pk->x = $chest->x;
             $pk->y = $chest->y;
             $pk->z = $chest->z;
             $pk->encode();
             $player->directDataPacket($pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
             if ($player->getInventory() != null) {
                 $player->getInventory()->sendContents($player);
             }
             $player->sendTip("chest open!");
         }
     }
 }
ContainerOpenPacket