Inheritance: extends Spawnable, implements pocketmine\inventory\InventoryHolder, implements pocketmine\tile\Container, implements pocketmine\tile\Nameable, use trait pocketmine\tile\ContainsItemsInSlotsTrait
 public function __construct(Chest $left, Chest $right)
 {
     $this->left = $left->getRealInventory();
     $this->right = $right->getRealInventory();
     $items = array_merge($this->left->getContents(), $this->right->getContents());
     BaseInventory::__construct($this, InventoryType::get(InventoryType::DOUBLE_CHEST), $items);
 }
Example #2
0
 public function close()
 {
     if ($this->closed === false) {
         foreach ($this->getInventory()->getViewers() as $player) {
             $player->removeWindow($this->getInventory());
         }
         foreach ($this->getInventory()->getViewers() as $player) {
             $player->removeWindow($this->getRealInventory());
         }
         parent::close();
     }
 }
Example #3
0
 public function pairWith(Chest $tile)
 {
     if ($this->isPaired() or $tile->isPaired()) {
         return false;
     }
     $this->createPair($tile);
     $this->spawnToAll();
     $tile->spawnToAll();
     $this->checkPairing();
     return true;
 }
 public function __construct(Chest $left, Chest $right)
 {
     $this->left = $left->getRealInventory();
     $this->right = $right->getRealInventory();
     BaseInventory::__construct($this, InventoryType::get(InventoryType::DOUBLE_CHEST));
 }
Example #5
0
 public function pairWith(Chest $tile)
 {
     if ($this->isPaired() or $tile->isPaired()) {
         return false;
     }
     $this->namedtag->pairx = new Int("pairx", $tile->x);
     $this->namedtag->pairz = new Int("pairz", $tile->z);
     $tile->namedtag->pairx = new Int("pairx", $this->x);
     $tile->namedtag->pairz = new Int("pairz", $this->z);
     $this->spawnToAll();
     $tile->spawnToAll();
     $this->checkPairing();
     return true;
 }
Example #6
0
 public function refillChest(Chest $chest, $refillPair = true)
 {
     $replaceSlots = [];
     $chest->clearAll();
     if (count($replaceSlots) >= $chest->getSize() / 2) {
         array_slice($replaceSlots, $chest->getSize() / 2 - 1);
     }
     foreach ($replaceSlots as $slot) {
         $item = null;
         // TODO: Decide items to put in chest.
         $chest->setItem($slot, $item);
     }
     if ($chest->isPaired() && $refillPair) {
         // Large chests
         $this->refillChest($chest->getPair(), false);
     }
 }
Example #7
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;
 }