Clean up EnderChestInventory implementation

now, EnderChestInventory is just a temporary window, much like anvil/enchanting windows. It provides a gateway to the player's PlayerEnderInventory.

This removes one of the remaining obstacles to disallowing null World in Position constructor.
This commit is contained in:
Dylan K. Taylor
2021-05-02 14:26:27 +01:00
parent 129ca7fee0
commit b8645f5c15
6 changed files with 117 additions and 25 deletions

View File

@ -117,13 +117,7 @@ abstract class BaseInventory implements Inventory{
$this->viewers[$id] = $viewer;
}
foreach($this->listeners as $listener){
$listener->onContentChange($this, $oldContents);
}
foreach($this->getViewers() as $viewer){
$viewer->getNetworkSession()->getInvManager()->syncContents($this);
}
$this->onContentChange($oldContents);
}
public function setItem(int $index, Item $item) : void{
@ -179,6 +173,20 @@ abstract class BaseInventory implements Inventory{
}
}
/**
* @param Item[] $itemsBefore
* @phpstan-param array<int, Item> $itemsBefore
*/
protected function onContentChange(array $itemsBefore) : void{
foreach($this->listeners as $listener){
$listener->onContentChange($this, $itemsBefore);
}
foreach($this->getViewers() as $viewer){
$viewer->getNetworkSession()->getInvManager()->syncContents($this);
}
}
public function slotExists(int $slot) : bool{
return $slot >= 0 and $slot < $this->slots->getSize();
}

View File

@ -0,0 +1,38 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\inventory;
use pocketmine\entity\Human;
final class PlayerEnderInventory extends BaseInventory{
private Human $holder;
public function __construct(Human $holder, int $size = 27){
$this->holder = $holder;
parent::__construct($size);
}
public function getHolder() : Human{ return $this->holder; }
}