22declare(strict_types=1);
24namespace pocketmine\inventory\transaction;
44 private \SplFixedArray $changedSlots;
46 public function __construct(
49 parent::__construct();
50 $this->changedSlots = new \SplFixedArray($this->actualInventory->getSize());
53 public function getActualInventory() :
Inventory{
54 return $this->actualInventory;
58 for($i = 0, $size = $this->
getSize(); $i < $size; ++$i){
59 if(!isset($items[$i])){
67 protected function internalSetItem(
int $index,
Item $item) : void{
68 if(!$item->equalsExact($this->actualInventory->getItem($index))){
69 $this->changedSlots[$index] = $item->isNull() ? VanillaItems::AIR() : clone $item;
74 return $this->actualInventory->getSize();
78 return $this->changedSlots[$index] !== null ? clone $this->changedSlots[$index] : $this->actualInventory->getItem($index);
81 public function getContents(
bool $includeEmpty =
false) : array{
82 $contents = $this->actualInventory->getContents($includeEmpty);
83 foreach($this->changedSlots as $index => $item){
85 if($includeEmpty || !$item->isNull()){
86 $contents[$index] = clone $item;
88 unset($contents[$index]);
100 foreach($this->changedSlots as $index => $newItem){
101 if($newItem !==
null){
102 $oldItem = $this->actualInventory->getItem($index);
103 if(!$newItem->equalsExact($oldItem)){
104 $result[] =
new SlotChangeAction($this->actualInventory, $index, $oldItem, $newItem);
setItem(int $index, Item $item)
getContents(bool $includeEmpty=false)
internalSetContents(array $items)