pocketmine\tile\Chest::getInventory PHP Method

getInventory() public method

public getInventory ( ) : ChestInventory | DoubleChestInventory
return pocketmine\inventory\ChestInventory | pocketmine\inventory\DoubleChestInventory
    public function getInventory()
    {
        if ($this->isPaired() and $this->doubleInventory === null) {
            $this->checkPairing();
        }
        return $this->doubleInventory instanceof DoubleChestInventory ? $this->doubleInventory : $this->inventory;
    }

Usage Example

Example #1
0
 public function onActivate(Item $item, Player $player = null)
 {
     if ($player instanceof Player) {
         $top = $this->getSide(1);
         if ($top->isTransparent !== true) {
             return true;
         }
         $t = $this->getLevel()->getTile($this);
         $chest = null;
         if ($t instanceof TileChest) {
             $chest = $t;
         } else {
             $nbt = new Compound(false, [new Enum("Items", []), new String("id", Tile::CHEST), new Int("x", $this->x), new Int("y", $this->y), new Int("z", $this->z)]);
             $nbt->Items->setTagType(NBT::TAG_Compound);
             $chest = new TileChest($this->getLevel()->getChunkAt($this->x >> 4, $this->z >> 4), $nbt);
         }
         if (($player->gamemode & 0x1) === 0x1) {
             return true;
         }
         $player->addWindow($chest->getInventory());
     }
     return true;
 }