First look: Split up Inventory & InventoryWindow

this unblocks a variety of changes, such as positionless tiles, enhanced APIs on Blocks for inventories, and also eliminates a bunch of cyclic references within the core code.

linked to #5033
This commit is contained in:
Dylan K. Taylor
2024-11-24 21:40:47 +00:00
parent 473bbe64e0
commit 45a4282e8b
74 changed files with 827 additions and 933 deletions

View File

@ -23,8 +23,9 @@ declare(strict_types=1);
namespace pocketmine\block\tile;
use pocketmine\block\inventory\ChestInventory;
use pocketmine\block\inventory\DoubleChestInventory;
use pocketmine\inventory\Inventory;
use pocketmine\inventory\SimpleInventory;
use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\IntTag;
@ -44,7 +45,7 @@ class Chest extends Spawnable implements Container, Nameable{
public const TAG_PAIRZ = "pairz";
public const TAG_PAIR_LEAD = "pairlead";
protected ChestInventory $inventory;
protected Inventory $inventory;
protected ?DoubleChestInventory $doubleInventory = null;
private ?int $pairX = null;
@ -52,7 +53,7 @@ class Chest extends Spawnable implements Container, Nameable{
public function __construct(World $world, Vector3 $pos){
parent::__construct($world, $pos);
$this->inventory = new ChestInventory($this->position);
$this->inventory = new SimpleInventory(27);
}
public function readSaveData(CompoundTag $nbt) : void{
@ -114,14 +115,14 @@ class Chest extends Spawnable implements Container, Nameable{
$this->containerTraitBlockDestroyedHook();
}
public function getInventory() : ChestInventory|DoubleChestInventory{
public function getInventory() : Inventory|DoubleChestInventory{
if($this->isPaired() && $this->doubleInventory === null){
$this->checkPairing();
}
return $this->doubleInventory instanceof DoubleChestInventory ? $this->doubleInventory : $this->inventory;
}
public function getRealInventory() : ChestInventory{
public function getRealInventory() : Inventory{
return $this->inventory;
}