diff --git a/src/block/tile/Chest.php b/src/block/tile/Chest.php index 1c21a650fe..6cb523c7de 100644 --- a/src/block/tile/Chest.php +++ b/src/block/tile/Chest.php @@ -23,7 +23,7 @@ namespace pocketmine\block\tile; -use pocketmine\inventory\CombinedInventory; +use pocketmine\inventory\CombinedInventoryProxy; use pocketmine\inventory\Inventory; use pocketmine\inventory\SimpleInventory; use pocketmine\math\Vector3; @@ -46,7 +46,7 @@ class Chest extends Spawnable implements ContainerTile, Nameable{ public const TAG_PAIR_LEAD = "pairlead"; protected Inventory $inventory; - protected ?CombinedInventory $doubleInventory = null; + protected ?CombinedInventoryProxy $doubleInventory = null; private ?int $pairX = null; private ?int $pairZ = null; @@ -113,7 +113,7 @@ protected function onBlockDestroyedHook() : void{ $this->containerTraitBlockDestroyedHook(); } - public function getInventory() : Inventory|CombinedInventory{ + public function getInventory() : Inventory|CombinedInventoryProxy{ if($this->isPaired() && $this->doubleInventory === null){ $this->checkPairing(); } @@ -139,9 +139,9 @@ protected function checkPairing() : void{ $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 CombinedInventory([$pair->inventory, $this->inventory]); + $this->doubleInventory = $pair->doubleInventory = new CombinedInventoryProxy([$pair->inventory, $this->inventory]); }else{ - $this->doubleInventory = $pair->doubleInventory = new CombinedInventory([$this->inventory, $pair->inventory]); + $this->doubleInventory = $pair->doubleInventory = new CombinedInventoryProxy([$this->inventory, $pair->inventory]); } } } diff --git a/src/inventory/CombinedInventory.php b/src/inventory/CombinedInventoryProxy.php similarity index 99% rename from src/inventory/CombinedInventory.php rename to src/inventory/CombinedInventoryProxy.php index aee5170cc1..5b6d1a668d 100644 --- a/src/inventory/CombinedInventory.php +++ b/src/inventory/CombinedInventoryProxy.php @@ -35,7 +35,7 @@ * Allows interacting with several separate inventories via a unified interface * Mainly used for double chests, but could be used for other custom use cases */ -final class CombinedInventory extends BaseInventory{ +final class CombinedInventoryProxy extends BaseInventory{ private readonly int $size; diff --git a/tests/phpunit/inventory/CombinedInventoryTest.php b/tests/phpunit/inventory/CombinedInventoryProxyTest.php similarity index 90% rename from tests/phpunit/inventory/CombinedInventoryTest.php rename to tests/phpunit/inventory/CombinedInventoryProxyTest.php index b62786ffec..5ab7eb3a87 100644 --- a/tests/phpunit/inventory/CombinedInventoryTest.php +++ b/tests/phpunit/inventory/CombinedInventoryProxyTest.php @@ -23,12 +23,13 @@ namespace pocketmine\inventory; +use PHPUnit\Framework\TestCase; use pocketmine\item\Item; use pocketmine\item\ItemTypeIds; use pocketmine\item\VanillaItems; use function array_filter; -final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{ +final class CombinedInventoryProxyTest extends TestCase{ /** * @return Inventory[] @@ -70,7 +71,7 @@ private static function getAltItems() : array{ } public function testGetItem() : void{ - $inventory = new CombinedInventory($this->createInventories()); + $inventory = new CombinedInventoryProxy($this->createInventories()); $this->verifyReadItems([ $inventory->getItem(0), @@ -84,7 +85,7 @@ public function testGetItem() : void{ } public function testGetContents() : void{ - $inventory = new CombinedInventory($this->createInventories()); + $inventory = new CombinedInventoryProxy($this->createInventories()); $this->verifyReadItems($inventory->getContents(includeEmpty: true)); @@ -123,7 +124,7 @@ private function verifyWriteItems(array $backing, array $altItems) : void{ public function testSetItem() : void{ $backing = $this->createInventories(); - $inventory = new CombinedInventory($backing); + $inventory = new CombinedInventoryProxy($backing); $altItems = self::getAltItems(); foreach($altItems as $slot => $item){ @@ -152,25 +153,25 @@ public static function setContentsProvider() : \Generator{ */ public function testSetContents(array $altItems) : void{ $backing = $this->createInventories(); - $inventory = new CombinedInventory($backing); + $inventory = new CombinedInventoryProxy($backing); $inventory->setContents($altItems); $this->verifyWriteItems($backing, $altItems); } public function testGetSize() : void{ - self::assertSame(4, (new CombinedInventory($this->createInventories()))->getSize()); + self::assertSame(4, (new CombinedInventoryProxy($this->createInventories()))->getSize()); } public function testGetMatchingItemCount() : void{ - $inventory = new CombinedInventory($this->createInventories()); + $inventory = new CombinedInventoryProxy($this->createInventories()); //we don't need to test the base functionality, only ensure that the correct delegate is called self::assertSame(1, $inventory->getMatchingItemCount(3, VanillaItems::BONE(), true)); self::assertNotSame(1, $inventory->getMatchingItemCount(3, VanillaItems::PAPER(), true)); } public function testIsSlotEmpty() : void{ - $inventory = new CombinedInventory($this->createInventories()); + $inventory = new CombinedInventoryProxy($this->createInventories()); self::assertTrue($inventory->isSlotEmpty(2)); self::assertFalse($inventory->isSlotEmpty(0)); @@ -179,7 +180,7 @@ public function testIsSlotEmpty() : void{ } public function testListenersOnProxySlotUpdate() : void{ - $inventory = new CombinedInventory($this->createInventories()); + $inventory = new CombinedInventoryProxy($this->createInventories()); $numChanges = 0; $inventory->getListeners()->add(new CallbackInventoryListener( @@ -193,7 +194,7 @@ public function testListenersOnProxySlotUpdate() : void{ } public function testListenersOnProxyContentUpdate() : void{ - $inventory = new CombinedInventory($this->createInventories()); + $inventory = new CombinedInventoryProxy($this->createInventories()); $numChanges = 0; $inventory->getListeners()->add(new CallbackInventoryListener( @@ -208,7 +209,7 @@ public function testListenersOnProxyContentUpdate() : void{ public function testListenersOnBackingSlotUpdate() : void{ $backing = $this->createInventories(); - $inventory = new CombinedInventory($backing); + $inventory = new CombinedInventoryProxy($backing); $slotChangeDetected = null; $numChanges = 0; @@ -231,7 +232,7 @@ public function testListenersOnBackingSlotUpdate() : void{ */ public function testListenersOnBackingContentUpdate() : void{ $backing = $this->createInventories(); - $inventory = new CombinedInventory($backing); + $inventory = new CombinedInventoryProxy($backing); $slotChanges = []; $inventory->getListeners()->add(new CallbackInventoryListener( @@ -253,7 +254,7 @@ public function testListenersOnBackingContentUpdate() : void{ */ public function testListenersOnSingleBackingContentUpdate() : void{ $backing = new SimpleInventory(2); - $inventory = new CombinedInventory([$backing]); + $inventory = new CombinedInventoryProxy([$backing]); $numChanges = 0; $inventory->getListeners()->add(new CallbackInventoryListener(