mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-29 00:26:56 +00:00
De-spaghettify the hierarchy for chest inventories
This commit is contained in:
parent
d37016f43b
commit
f538440bce
@ -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);
|
||||
|
@ -23,15 +23,16 @@ declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\block\inventory;
|
||||
|
||||
use pocketmine\network\mcpe\protocol\BlockEventPacket;
|
||||
use pocketmine\world\Position;
|
||||
use pocketmine\world\sound\EnderChestCloseSound;
|
||||
use pocketmine\world\sound\EnderChestOpenSound;
|
||||
use pocketmine\world\sound\Sound;
|
||||
|
||||
class EnderChestInventory extends ChestInventory{
|
||||
class EnderChestInventory extends AnimatedBlockInventory{
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct(new Position(0, 0, 0, null));
|
||||
parent::__construct(new Position(0, 0, 0, null), 27);
|
||||
}
|
||||
|
||||
public function setHolderPosition(Position $pos) : void{
|
||||
@ -45,4 +46,11 @@ class EnderChestInventory extends ChestInventory{
|
||||
protected function getCloseSound() : Sound{
|
||||
return new EnderChestCloseSound();
|
||||
}
|
||||
|
||||
protected function animateBlock(bool $isOpen) : void{
|
||||
$holder = $this->getHolder();
|
||||
|
||||
//event ID is always 1 for a chest
|
||||
$holder->getWorld()->broadcastPacketToViewers($holder, BlockEventPacket::create(1, $isOpen ? 1 : 0, $holder->asVector3()));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user