33 private bool $backingInventoryChanging =
false;
35 public function __construct(
38 parent::__construct();
39 $weakThis = \WeakReference::create($this);
41 static function(
Inventory $unused,
int $slot,
Item $oldItem) use ($weakThis) :
void{
42 if(($strongThis = $weakThis->get()) !==
null){
43 $strongThis->backingInventoryChanging =
true;
45 $strongThis->onSlotChange($slot, $oldItem);
47 $strongThis->backingInventoryChanging =
false;
51 static function(
Inventory $unused, array $oldContents) use ($weakThis) :
void{
52 if(($strongThis = $weakThis->get()) !==
null){
53 $strongThis->backingInventoryChanging =
true;
55 $strongThis->onContentChange($oldContents);
57 $strongThis->backingInventoryChanging =
false;
64 public function __destruct(){
65 $this->backingInventory->getListeners()->remove($this->inventoryListener);
69 return $this->backingInventory->
getSize();
73 return $this->backingInventory->getItem($index);
76 protected function internalSetItem(
int $index,
Item $item) : void{
77 $this->backingInventory->setItem($index, $item);
80 public function getContents(
bool $includeEmpty =
false) : array{
81 return $this->backingInventory->getContents($includeEmpty);
85 $this->backingInventory->setContents($items);
89 return $this->backingInventory->isSlotEmpty($index);
92 protected function onSlotChange(
int $index,
Item $before) : void{
93 if($this->backingInventoryChanging){
94 parent::onSlotChange($index, $before);
99 if($this->backingInventoryChanging){
100 parent::onContentChange($itemsBefore);