PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
DoubleChestInventory.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block\inventory;
25
32
34 use AnimatedBlockInventoryTrait;
35
36 public function __construct(
37 private ChestInventory $left,
38 private ChestInventory $right
39 ){
40 $this->holder = $this->left->getHolder();
41 parent::__construct();
42 }
43
44 public function getInventory() : self{
45 return $this;
46 }
47
48 public function getSize() : int{
49 return $this->left->getSize() + $this->right->getSize();
50 }
51
52 public function getItem(int $index) : Item{
53 return $index < $this->left->getSize() ? $this->left->getItem($index) : $this->right->getItem($index - $this->left->getSize());
54 }
55
56 protected function internalSetItem(int $index, Item $item) : void{
57 $index < $this->left->getSize() ? $this->left->setItem($index, $item) : $this->right->setItem($index - $this->left->getSize(), $item);
58 }
59
60 public function getContents(bool $includeEmpty = false) : array{
61 $result = $this->left->getContents($includeEmpty);
62 $leftSize = $this->left->getSize();
63
64 foreach($this->right->getContents($includeEmpty) as $i => $item){
65 $result[$i + $leftSize] = $item;
66 }
67
68 return $result;
69 }
70
71 protected function internalSetContents(array $items) : void{
72 $leftSize = $this->left->getSize();
73
74 $leftContents = [];
75 $rightContents = [];
76
77 foreach($items as $i => $item){
78 if($i < $this->left->getSize()){
79 $leftContents[$i] = $item;
80 }else{
81 $rightContents[$i - $leftSize] = $item;
82 }
83 }
84 $this->left->setContents($leftContents);
85 $this->right->setContents($rightContents);
86 }
87
88 protected function getMatchingItemCount(int $slot, Item $test, bool $checkTags) : int{
89 $leftSize = $this->left->getSize();
90 return $slot < $leftSize ?
91 $this->left->getMatchingItemCount($slot, $test, $checkTags) :
92 $this->right->getMatchingItemCount($slot - $leftSize, $test, $checkTags);
93 }
94
95 public function isSlotEmpty(int $index) : bool{
96 $leftSize = $this->left->getSize();
97 return $index < $leftSize ?
98 $this->left->isSlotEmpty($index) :
99 $this->right->isSlotEmpty($index - $leftSize);
100 }
101
102 protected function getOpenSound() : Sound{ return new ChestOpenSound(); }
103
104 protected function getCloseSound() : Sound{ return new ChestCloseSound(); }
105
106 protected function animateBlock(bool $isOpen) : void{
107 $this->left->animateBlock($isOpen);
108 $this->right->animateBlock($isOpen);
109 }
110
111 public function getLeftSide() : ChestInventory{
112 return $this->left;
113 }
114
115 public function getRightSide() : ChestInventory{
116 return $this->right;
117 }
118}
getMatchingItemCount(int $slot, Item $test, bool $checkTags)