Merge branch 'stable' into next-minor

This commit is contained in:
Dylan K. Taylor
2022-09-15 12:44:53 +01:00
26 changed files with 171 additions and 190 deletions

View File

@ -76,11 +76,13 @@ abstract class BaseInventory implements Inventory{
/**
* @param Item[] $items
* @phpstan-param array<int, Item> $items
*/
abstract protected function internalSetContents(array $items) : void;
/**
* @param Item[] $items
* @phpstan-param array<int, Item> $items
*/
public function setContents(array $items) : void{
if(count($items) > $this->getSize()){
@ -132,6 +134,7 @@ abstract class BaseInventory implements Inventory{
return $slots;
}
public function first(Item $item, bool $exact = false) : int{
$count = $exact ? $item->getCount() : max(1, $item->getCount());
$checkDamage = $exact || !$item->hasAnyDamageValue();

View File

@ -47,12 +47,20 @@ interface Inventory{
public function setItem(int $index, Item $item) : void;
/**
* Returns an array of all the itemstacks in the inventory, indexed by their slot number.
* Empty slots are not included unless includeEmpty is true.
*
* @return Item[]
* @phpstan-return array<int, Item>
*/
public function getContents(bool $includeEmpty = false) : array;
/**
* Sets the contents of the inventory. Non-numeric offsets or offsets larger than the size of the inventory are
* ignored.
*
* @param Item[] $items
* @phpstan-param array<int, Item> $items
*/
public function setContents(array $items) : void;
@ -85,8 +93,10 @@ interface Inventory{
/**
* Will return all the Items that has the same id and metadata (if not null).
* Won't check amount
* The returned array is indexed by slot number.
*
* @return Item[]
* @phpstan-return array<int, Item>
*/
public function all(Item $item) : array;

View File

@ -58,6 +58,7 @@ class SimpleInventory extends BaseInventory{
/**
* @return Item[]
* @phpstan-return array<int, Item>
*/
public function getContents(bool $includeEmpty = false) : array{
$contents = [];