Chest block now has responsibility for configuring double chest inventories

it already needs to locate the correct pair anyway to know the left/right for DoubleChestInventoryWindow, so we might as well use this logic for initializing the DoubleChestInventory itself too. The old logic in tile/Chest didn't work correctly.
This commit is contained in:
Dylan K. Taylor
2024-11-24 22:47:35 +00:00
parent 9c5df90e9b
commit 1d2b52732e
11 changed files with 31 additions and 69 deletions

View File

@ -115,15 +115,14 @@ class Chest extends Spawnable implements Container, Nameable{
$this->containerTraitBlockDestroyedHook();
}
public function getInventory() : Inventory|DoubleChestInventory{
if($this->isPaired() && $this->doubleInventory === null){
$this->checkPairing();
}
return $this->doubleInventory instanceof DoubleChestInventory ? $this->doubleInventory : $this->inventory;
public function getInventory() : Inventory{
return $this->inventory;
}
public function getRealInventory() : Inventory{
return $this->inventory;
public function getDoubleInventory() : ?DoubleChestInventory{ return $this->doubleInventory; }
public function setDoubleInventory(?DoubleChestInventory $doubleChestInventory) : void{
$this->doubleInventory = $doubleChestInventory;
}
protected function checkPairing() : void{
@ -134,18 +133,7 @@ class Chest extends Spawnable implements Container, Nameable{
}elseif(($pair = $this->getPair()) instanceof Chest){
if(!$pair->isPaired()){
$pair->createPair($this);
$pair->checkPairing();
}
if($this->doubleInventory === null){
if($pair->doubleInventory !== null){
$this->doubleInventory = $pair->doubleInventory;
}else{
if(($pair->position->x + ($pair->position->z << 15)) > ($this->position->x + ($this->position->z << 15))){ //Order them correctly
$this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($pair->inventory, $this->inventory);
}else{
$this->doubleInventory = $pair->doubleInventory = new DoubleChestInventory($this->inventory, $pair->inventory);
}
}
$this->doubleInventory = $pair->doubleInventory = null;
}
}else{
$this->doubleInventory = null;