Use covariant types for InventoryHolder and Container implementors

This commit is contained in:
Dylan K. Taylor 2022-06-05 18:49:48 +01:00
parent 38cf9fc6e6
commit f2dc9187f0
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
11 changed files with 17 additions and 67 deletions

View File

@ -41,7 +41,7 @@ class DoubleChestInventory extends BaseInventory implements BlockInventory, Inve
parent::__construct(); parent::__construct();
} }
public function getInventory(){ public function getInventory() : self{
return $this; return $this;
} }

View File

@ -56,17 +56,11 @@ class Barrel extends Spawnable implements Container, Nameable{
} }
} }
/** public function getInventory() : BarrelInventory{
* @return BarrelInventory
*/
public function getInventory(){
return $this->inventory; return $this->inventory;
} }
/** public function getRealInventory() : BarrelInventory{
* @return BarrelInventory
*/
public function getRealInventory(){
return $this->inventory; return $this->inventory;
} }

View File

@ -112,17 +112,11 @@ class BrewingStand extends Spawnable implements Container, Nameable{
} }
} }
/** public function getInventory() : BrewingStandInventory{
* @return BrewingStandInventory
*/
public function getInventory(){
return $this->inventory; return $this->inventory;
} }
/** public function getRealInventory() : BrewingStandInventory{
* @return BrewingStandInventory
*/
public function getRealInventory(){
return $this->inventory; return $this->inventory;
} }

View File

@ -114,20 +114,14 @@ class Chest extends Spawnable implements Container, Nameable{
$this->containerTraitBlockDestroyedHook(); $this->containerTraitBlockDestroyedHook();
} }
/** public function getInventory() : ChestInventory|DoubleChestInventory{
* @return ChestInventory|DoubleChestInventory
*/
public function getInventory(){
if($this->isPaired() && $this->doubleInventory === null){ if($this->isPaired() && $this->doubleInventory === null){
$this->checkPairing(); $this->checkPairing();
} }
return $this->doubleInventory instanceof DoubleChestInventory ? $this->doubleInventory : $this->inventory; return $this->doubleInventory instanceof DoubleChestInventory ? $this->doubleInventory : $this->inventory;
} }
/** public function getRealInventory() : ChestInventory{
* @return ChestInventory
*/
public function getRealInventory(){
return $this->inventory; return $this->inventory;
} }

View File

@ -30,10 +30,7 @@ interface Container extends InventoryHolder{
public const TAG_ITEMS = "Items"; public const TAG_ITEMS = "Items";
public const TAG_LOCK = "Lock"; public const TAG_LOCK = "Lock";
/** public function getRealInventory() : Inventory;
* @return Inventory
*/
public function getRealInventory();
/** /**
* Returns whether this container can be opened by an item with the given custom name. * Returns whether this container can be opened by an item with the given custom name.

View File

@ -38,10 +38,7 @@ trait ContainerTrait{
/** @var string|null */ /** @var string|null */
private $lock = null; private $lock = null;
/** abstract public function getRealInventory() : Inventory;
* @return Inventory
*/
abstract public function getRealInventory();
protected function loadItems(CompoundTag $tag) : void{ protected function loadItems(CompoundTag $tag) : void{
if(($inventoryTag = $tag->getTag(Container::TAG_ITEMS)) instanceof ListTag && $inventoryTag->getTagType() === NBT::TAG_Compound){ if(($inventoryTag = $tag->getTag(Container::TAG_ITEMS)) instanceof ListTag && $inventoryTag->getTagType() === NBT::TAG_Compound){

View File

@ -104,17 +104,11 @@ abstract class Furnace extends Spawnable implements Container, Nameable{
} }
} }
/** public function getInventory() : FurnaceInventory{
* @return FurnaceInventory
*/
public function getInventory(){
return $this->inventory; return $this->inventory;
} }
/** public function getRealInventory() : FurnaceInventory{
* @return FurnaceInventory
*/
public function getRealInventory(){
return $this->getInventory(); return $this->getInventory();
} }

View File

@ -69,17 +69,11 @@ class Hopper extends Spawnable implements Container, Nameable{
return "Hopper"; return "Hopper";
} }
/** public function getInventory() : HopperInventory{
* @return HopperInventory
*/
public function getInventory(){
return $this->inventory; return $this->inventory;
} }
/** public function getRealInventory() : HopperInventory{
* @return HopperInventory
*/
public function getRealInventory(){
return $this->inventory; return $this->inventory;
} }
} }

View File

@ -93,17 +93,11 @@ class ShulkerBox extends Spawnable implements Container, Nameable{
$this->facing = $facing; $this->facing = $facing;
} }
/** public function getInventory() : ShulkerBoxInventory{
* @return ShulkerBoxInventory
*/
public function getInventory(){
return $this->inventory; return $this->inventory;
} }
/** public function getRealInventory() : ShulkerBoxInventory{
* @return ShulkerBoxInventory
*/
public function getRealInventory(){
return $this->inventory; return $this->inventory;
} }

View File

@ -189,10 +189,7 @@ class Human extends Living implements ProjectileSource, InventoryHolder{
return min(100, 7 * $this->xpManager->getXpLevel()); return min(100, 7 * $this->xpManager->getXpLevel());
} }
/** public function getInventory() : PlayerInventory{
* @return PlayerInventory
*/
public function getInventory(){
return $this->inventory; return $this->inventory;
} }

View File

@ -25,10 +25,5 @@ namespace pocketmine\inventory;
interface InventoryHolder{ interface InventoryHolder{
/** public function getInventory() : Inventory;
* Get the object related inventory
*
* @return Inventory
*/
public function getInventory();
} }