mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-23 00:55:57 +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{
|
||||
return $this->getAddableItemQuantity($item) === $item->getCount();
|
||||
}
|
||||
|
||||
public function getAddableItemQuantity(Item $item) : int{
|
||||
$count = $item->getCount();
|
||||
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
||||
$slot = $this->getItem($i);
|
||||
@ -181,11 +185,11 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
|
||||
if($count <= 0){
|
||||
return true;
|
||||
return $item->getCount();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return $item->getCount() - $count;
|
||||
}
|
||||
|
||||
public function addItem(Item ...$slots) : array{
|
||||
|
@ -63,6 +63,11 @@ interface Inventory{
|
||||
*/
|
||||
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.
|
||||
* It will return the Items that couldn't be removed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user