mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-07 12:18:46 +00:00
BaseInventory: Remove getDefaultSize()
it's possible to want to initialize dynamically-sized inventories which don't have a default size.
This commit is contained in:
parent
60225a378f
commit
9904810f24
@ -33,17 +33,13 @@ class AnvilInventory extends ContainerInventory{
|
||||
protected $holder;
|
||||
|
||||
public function __construct(Position $pos){
|
||||
parent::__construct($pos->asPosition());
|
||||
parent::__construct($pos->asPosition(), 2);
|
||||
}
|
||||
|
||||
public function getNetworkType() : int{
|
||||
return WindowTypes::ANVIL;
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return 2; //1 input, 1 material
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Position
|
||||
|
@ -43,17 +43,13 @@ class ArmorInventory extends BaseInventory{
|
||||
|
||||
public function __construct(Living $holder){
|
||||
$this->holder = $holder;
|
||||
parent::__construct();
|
||||
parent::__construct(4);
|
||||
}
|
||||
|
||||
public function getHolder() : Living{
|
||||
return $this->holder;
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return 4;
|
||||
}
|
||||
|
||||
public function getHelmet() : Item{
|
||||
return $this->getItem(self::SLOT_HEAD);
|
||||
}
|
||||
|
@ -49,11 +49,11 @@ abstract class BaseInventory implements Inventory{
|
||||
protected $slotChangeListener;
|
||||
|
||||
/**
|
||||
* @param Item[] $items
|
||||
* @param int $size
|
||||
* @param Item[] $items
|
||||
*/
|
||||
public function __construct(array $items = [], ?int $size = null){
|
||||
$this->slots = new \SplFixedArray($size ?? $this->getDefaultSize());
|
||||
public function __construct(int $size, array $items = []){
|
||||
$this->slots = new \SplFixedArray($size);
|
||||
|
||||
$this->setContents($items, false);
|
||||
}
|
||||
@ -76,8 +76,6 @@ abstract class BaseInventory implements Inventory{
|
||||
$this->slots->setSize($size);
|
||||
}
|
||||
|
||||
abstract public function getDefaultSize() : int;
|
||||
|
||||
public function getMaxStackSize() : int{
|
||||
return $this->maxStackSize;
|
||||
}
|
||||
|
@ -39,17 +39,13 @@ class ChestInventory extends ContainerInventory{
|
||||
* @param Chest $tile
|
||||
*/
|
||||
public function __construct(Chest $tile){
|
||||
parent::__construct($tile);
|
||||
parent::__construct($tile, 27);
|
||||
}
|
||||
|
||||
public function getNetworkType() : int{
|
||||
return WindowTypes::CONTAINER;
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return 27;
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Chest
|
||||
|
@ -33,9 +33,9 @@ abstract class ContainerInventory extends BaseInventory{
|
||||
/** @var Vector3 */
|
||||
protected $holder;
|
||||
|
||||
public function __construct(Vector3 $holder, array $items = [], ?int $size = null){
|
||||
public function __construct(Vector3 $holder, int $size, array $items = []){
|
||||
$this->holder = $holder;
|
||||
parent::__construct($items, $size);
|
||||
parent::__construct($size, $items);
|
||||
}
|
||||
|
||||
protected function onOpen(Player $who) : void{
|
||||
|
@ -50,17 +50,13 @@ class CraftingGrid extends BaseInventory{
|
||||
public function __construct(Player $holder, int $gridWidth){
|
||||
$this->holder = $holder;
|
||||
$this->gridWidth = $gridWidth;
|
||||
parent::__construct();
|
||||
parent::__construct($this->getGridWidth() ** 2);
|
||||
}
|
||||
|
||||
public function getGridWidth() : int{
|
||||
return $this->gridWidth;
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return $this->getGridWidth() ** 2;
|
||||
}
|
||||
|
||||
public function setSize(int $size) : void{
|
||||
throw new \BadMethodCallException("Cannot change the size of a crafting grid");
|
||||
}
|
||||
|
@ -40,11 +40,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
$this->left = $left->getRealInventory();
|
||||
$this->right = $right->getRealInventory();
|
||||
$items = array_merge($this->left->getContents(true), $this->right->getContents(true));
|
||||
BaseInventory::__construct($items);
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return $this->left->getDefaultSize() + $this->right->getDefaultSize();
|
||||
BaseInventory::__construct($this->left->getSize() + $this->right->getSize(), $items);
|
||||
}
|
||||
|
||||
public function getInventory(){
|
||||
|
@ -33,17 +33,13 @@ class EnchantInventory extends ContainerInventory{
|
||||
protected $holder;
|
||||
|
||||
public function __construct(Position $pos){
|
||||
parent::__construct($pos->asPosition());
|
||||
parent::__construct($pos->asPosition(), 2);
|
||||
}
|
||||
|
||||
public function getNetworkType() : int{
|
||||
return WindowTypes::ENCHANTMENT;
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return 2; //1 input, 1 lapis
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Position
|
||||
|
@ -34,17 +34,13 @@ class EnderChestInventory extends ChestInventory{
|
||||
protected $holder;
|
||||
|
||||
public function __construct(){
|
||||
ContainerInventory::__construct(new Position());
|
||||
ContainerInventory::__construct(new Position(), 27);
|
||||
}
|
||||
|
||||
public function getNetworkType() : int{
|
||||
return WindowTypes::CONTAINER;
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return 27;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the holder's position to that of a tile
|
||||
*
|
||||
|
@ -32,17 +32,13 @@ class FurnaceInventory extends ContainerInventory{
|
||||
protected $holder;
|
||||
|
||||
public function __construct(Furnace $tile){
|
||||
parent::__construct($tile);
|
||||
parent::__construct($tile, 3);
|
||||
}
|
||||
|
||||
public function getNetworkType() : int{
|
||||
return WindowTypes::FURNACE;
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return 3; //1 input, 1 fuel, 1 output
|
||||
}
|
||||
|
||||
/**
|
||||
* This override is here for documentation and code completion purposes only.
|
||||
* @return Furnace
|
||||
|
@ -31,11 +31,7 @@ class PlayerCursorInventory extends BaseInventory{
|
||||
|
||||
public function __construct(Player $holder){
|
||||
$this->holder = $holder;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return 1;
|
||||
parent::__construct(1);
|
||||
}
|
||||
|
||||
public function setSize(int $size) : void{
|
||||
|
@ -45,11 +45,7 @@ class PlayerInventory extends BaseInventory{
|
||||
*/
|
||||
public function __construct(Human $player){
|
||||
$this->holder = $player;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDefaultSize() : int{
|
||||
return 36;
|
||||
parent::__construct(36);
|
||||
}
|
||||
|
||||
public function isHotbarSlot(int $slot) : bool{
|
||||
|
@ -34,13 +34,8 @@ class BaseInventoryTest extends TestCase{
|
||||
}
|
||||
|
||||
public function testAddItemDifferentUserData() : void{
|
||||
$inv = new class extends BaseInventory{
|
||||
public function getDefaultSize() : int{
|
||||
return 1;
|
||||
}
|
||||
public function getName() : string{
|
||||
return "";
|
||||
}
|
||||
$inv = new class(1) extends BaseInventory{
|
||||
|
||||
};
|
||||
$item1 = ItemFactory::get(Item::ARROW, 0, 1);
|
||||
$item2 = ItemFactory::get(Item::ARROW, 0, 1)->setCustomName("TEST");
|
||||
|
Loading…
x
Reference in New Issue
Block a user