mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 00:33:59 +00:00
Inventory: Added includeEmpty parameter to getContents()
This commit is contained in:
parent
2fb580db26
commit
1de7c5b114
@ -93,10 +93,20 @@ abstract class BaseInventory implements Inventory{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $includeEmpty
|
||||
*
|
||||
* @return Item[]
|
||||
*/
|
||||
public function getContents() : array{
|
||||
return array_filter($this->slots->toArray(), function(Item $item = null){ return $item !== null; });
|
||||
public function getContents(bool $includeEmpty = false) : array{
|
||||
$contents = [];
|
||||
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
||||
$item = $this->getItem($i);
|
||||
if($includeEmpty or !$item->isNull()){
|
||||
$contents[$i] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,15 +71,6 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
return $index < $this->left->getSize() ? $this->left->clear($index, $send) : $this->right->clear($index - $this->right->getSize(), $send);
|
||||
}
|
||||
|
||||
public function getContents() : array{
|
||||
$contents = [];
|
||||
for($i = 0, $size = $this->getSize(); $i < $size; ++$i){
|
||||
$contents[$i] = $this->getItem($i);
|
||||
}
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item[] $items
|
||||
* @param bool $send
|
||||
|
@ -108,9 +108,11 @@ interface Inventory{
|
||||
public function removeItem(Item ...$slots) : array;
|
||||
|
||||
/**
|
||||
* @param bool $includeEmpty
|
||||
*
|
||||
* @return Item[]
|
||||
*/
|
||||
public function getContents() : array;
|
||||
public function getContents(bool $includeEmpty = false) : array;
|
||||
|
||||
/**
|
||||
* @param Item[] $items
|
||||
|
Loading…
x
Reference in New Issue
Block a user