Removed InventoryType, added new inventory API methods

This commit is contained in:
Dylan K. Taylor
2017-08-07 11:31:36 +01:00
parent 899e318a88
commit 98e0a2ecba
13 changed files with 115 additions and 264 deletions

View File

@ -34,8 +34,6 @@ use pocketmine\Server;
abstract class BaseInventory implements Inventory{
/** @var InventoryType */
protected $type;
/** @var int */
protected $maxStackSize = Inventory::MAX_STACK;
/** @var int */
@ -53,37 +51,31 @@ abstract class BaseInventory implements Inventory{
/**
* @param InventoryHolder $holder
* @param InventoryType $type
* @param Item[] $items
* @param int $overrideSize
* @param string $overrideTitle
* @param int $size
* @param string $title
*/
public function __construct(InventoryHolder $holder, InventoryType $type, array $items = [], $overrideSize = null, $overrideTitle = null){
public function __construct(InventoryHolder $holder, array $items = [], int $size = null, string $title = null){
$this->holder = $holder;
$this->type = $type;
if($overrideSize !== null){
$this->size = (int) $overrideSize;
}else{
$this->size = $this->type->getDefaultSize();
}
if($overrideTitle !== null){
$this->title = $overrideTitle;
}else{
$this->title = $this->type->getDefaultTitle();
}
$this->name = $this->type->getDefaultTitle();
$this->size = $size ?? $this->getDefaultSize();
$this->title = $title ?? $this->getName();
$this->setContents($items);
}
public function __destruct(){
$this->holder = null;
$this->slots = [];
abstract public function getName() : string;
public function getTitle() : string{
return $this->title;
}
/**
* Returns the Minecraft PE inventory type used to show the inventory window to clients.
* @return int
*/
abstract public function getNetworkType() : int;
public function getSize() : int{
return $this->size;
}
@ -92,18 +84,12 @@ abstract class BaseInventory implements Inventory{
$this->size = $size;
}
abstract public function getDefaultSize() : int;
public function getMaxStackSize() : int{
return $this->maxStackSize;
}
public function getName() : string{
return $this->name;
}
public function getTitle() : string{
return $this->title;
}
public function getItem(int $index) : Item{
assert($index >= 0, "Inventory slot should not be negative");
return isset($this->slots[$index]) ? clone $this->slots[$index] : Item::get(Item::AIR, 0, 0);
@ -456,9 +442,4 @@ abstract class BaseInventory implements Inventory{
$player->dataPacket($pk);
}
}
public function getType() : InventoryType{
return $this->type;
}
}