Skip to content

Commit

Permalink
Rename CombinedInventory -> CombinedInventoryProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Dec 8, 2024
1 parent 9949e38 commit 0fe786a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/block/tile/Chest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -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),
Expand All @@ -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));

Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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));
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit 0fe786a

Please sign in to comment.