mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-08-27 13:38:58 +00:00
Item: added count parameter to pop()
this allows popping an arbitrary number of items from the stack, instead of just 1.
This commit is contained in:
parent
ad15ab5b42
commit
e3d2fa10a5
@ -597,19 +597,21 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Pops an item from the stack and returns it, decreasing the stack count of this item stack by one.
|
* 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.
|
* @param int $count
|
||||||
|
*
|
||||||
|
* @return Item
|
||||||
|
* @throws \InvalidArgumentException if trying to pop more items than are on the stack
|
||||||
*/
|
*/
|
||||||
public function pop() : Item{
|
public function pop(int $count = 1) : Item{
|
||||||
if($this->isNull()){
|
if($count > $this->count){
|
||||||
throw new \InvalidStateException("Cannot pop an item from a null stack");
|
throw new \InvalidArgumentException("Cannot pop $count items from a stack of $this->count");
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = clone $this;
|
$item = clone $this;
|
||||||
$item->setCount(1);
|
$item->count = $count;
|
||||||
|
|
||||||
$this->count--;
|
$this->count -= $count;
|
||||||
|
|
||||||
return $item;
|
return $item;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user