mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-08-31 23:33:06 +00:00
Inventory: added getAddableItemQuantity()
this mostly reuses the code from canAddItem().
This commit is contained in:
parent
d73ea8efe4
commit
a5833327f0
@ -169,6 +169,10 @@ abstract class BaseInventory implements Inventory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function canAddItem(Item $item) : bool{
|
public function canAddItem(Item $item) : bool{
|
||||||
|
return $this->getAddableItemQuantity($item) === $item->getCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddableItemQuantity(Item $item) : int{
|
||||||
$count = $item->getCount();
|
$count = $item->getCount();
|
||||||
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
||||||
$slot = $this->getItem($i);
|
$slot = $this->getItem($i);
|
||||||
@ -181,11 +185,11 @@ abstract class BaseInventory implements Inventory{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($count <= 0){
|
if($count <= 0){
|
||||||
return true;
|
return $item->getCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return $item->getCount() - $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addItem(Item ...$slots) : array{
|
public function addItem(Item ...$slots) : array{
|
||||||
|
@ -63,6 +63,11 @@ interface Inventory{
|
|||||||
*/
|
*/
|
||||||
public function canAddItem(Item $item) : bool;
|
public function canAddItem(Item $item) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns how many items from the given itemstack can be added to this inventory.
|
||||||
|
*/
|
||||||
|
public function getAddableItemQuantity(Item $item) : int;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the given Item from the inventory.
|
* Removes the given Item from the inventory.
|
||||||
* It will return the Items that couldn't be removed.
|
* It will return the Items that couldn't be removed.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user