inventory; } /** * Returns the slot in the inventory which this action modified. */ public function getSlot() : int{ return $this->inventorySlot; } /** * Checks if the item in the inventory at the specified slot is the same as this action's source item. * * @throws TransactionValidationException */ public function validate(Player $source) : void{ if(!$this->inventory->slotExists($this->inventorySlot)){ throw new TransactionValidationException("Slot does not exist"); } if(!$this->inventory->getItem($this->inventorySlot)->equalsExact($this->sourceItem)){ throw new TransactionValidationException("Slot does not contain expected original item"); } if($this->targetItem->getCount() > $this->targetItem->getMaxStackSize()){ throw new TransactionValidationException("Target item exceeds item type max stack size"); } if($this->targetItem->getCount() > $this->inventory->getMaxStackSize()){ throw new TransactionValidationException("Target item exceeds inventory max stack size"); } } /** * Adds this action's target inventory to the transaction's inventory list. */ public function onAddToTransaction(InventoryTransaction $transaction) : void{ $transaction->addInventory($this->inventory); } /** * Sets the item into the target inventory. */ public function execute(Player $source) : void{ $this->inventory->setItem($this->inventorySlot, $this->targetItem); } }