mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Added API method Item->pop()
This commit is contained in:
@ -643,6 +643,25 @@ class Item implements ItemIds, \JsonSerializable{
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops an item from the stack and returns it, decreasing the stack count of this item stack by one.
|
||||
* @return Item
|
||||
*
|
||||
* @throws \InvalidStateException if the count is less than or equal to zero, or if the stack is air.
|
||||
*/
|
||||
public function pop() : Item{
|
||||
if($this->isNull()){
|
||||
throw new \InvalidStateException("Cannot pop an item from a null stack");
|
||||
}
|
||||
|
||||
$item = clone $this;
|
||||
$item->setCount(1);
|
||||
|
||||
$this->count--;
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public function isNull() : bool{
|
||||
return $this->count <= 0 or $this->id === Item::AIR;
|
||||
}
|
||||
|
Reference in New Issue
Block a user