mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-08 02:42:58 +00:00
De-spaghettify the hierarchy for chest inventories
This commit is contained in:
@ -23,12 +23,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory;
|
||||
|
||||
use pocketmine\inventory\BaseInventory;
|
||||
use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\Sound;
|
||||
|
||||
class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
class DoubleChestInventory extends AnimatedBlockInventory implements InventoryHolder{
|
||||
/** @var ChestInventory */
|
||||
private $left;
|
||||
/** @var ChestInventory */
|
||||
@ -37,20 +36,13 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
public function __construct(ChestInventory $left, ChestInventory $right){
|
||||
$this->left = $left;
|
||||
$this->right = $right;
|
||||
BaseInventory::__construct($this->left->getSize() + $this->right->getSize());
|
||||
parent::__construct($this->left->getHolder(), $this->left->getSize() + $this->right->getSize());
|
||||
}
|
||||
|
||||
public function getInventory(){
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Position
|
||||
*/
|
||||
public function getHolder(){
|
||||
return $this->left->getHolder();
|
||||
}
|
||||
|
||||
public function getItem(int $index) : Item{
|
||||
return $index < $this->left->getSize() ? $this->left->getItem($index) : $this->right->getItem($index - $this->left->getSize());
|
||||
}
|
||||
@ -72,6 +64,10 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getOpenSound() : Sound{ return $this->left->getOpenSound(); }
|
||||
|
||||
protected function getCloseSound() : Sound{ return $this->left->getCloseSound(); }
|
||||
|
||||
protected function animateBlock(bool $isOpen) : void{
|
||||
$this->left->animateBlock($isOpen);
|
||||
$this->right->animateBlock($isOpen);
|
||||
|
Reference in New Issue
Block a user