Rename CombinedInventory -> CombinedInventoryProxy

This commit is contained in:
Dylan K. Taylor 2024-12-08 16:28:00 +00:00
parent 9949e3815f
commit 0fe786af4d
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 20 additions and 19 deletions

View File

@ -23,7 +23,7 @@ declare(strict_types=1);
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 @@ class Chest extends Spawnable implements ContainerTile, Nameable{
$this->containerTraitBlockDestroyedHook();
}
public function getInventory() : Inventory|CombinedInventory{
public function getInventory() : Inventory|CombinedInventoryProxy{
if($this->isPaired() && $this->doubleInventory === null){
$this->checkPairing();
}
@ -139,9 +139,9 @@ class Chest extends Spawnable implements ContainerTile, Nameable{
$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]);
}
}
}

View File

@ -35,7 +35,7 @@ use function spl_object_id;
* 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;

View File

@ -23,12 +23,13 @@ declare(strict_types=1);
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 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
}
public function testGetItem() : void{
$inventory = new CombinedInventory($this->createInventories());
$inventory = new CombinedInventoryProxy($this->createInventories());
$this->verifyReadItems([
$inventory->getItem(0),
@ -84,7 +85,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
}
public function testGetContents() : void{
$inventory = new CombinedInventory($this->createInventories());
$inventory = new CombinedInventoryProxy($this->createInventories());
$this->verifyReadItems($inventory->getContents(includeEmpty: true));
@ -123,7 +124,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
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 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
*/
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 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
}
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 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
}
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 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
public function testListenersOnBackingSlotUpdate() : void{
$backing = $this->createInventories();
$inventory = new CombinedInventory($backing);
$inventory = new CombinedInventoryProxy($backing);
$slotChangeDetected = null;
$numChanges = 0;
@ -231,7 +232,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
*/
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 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
*/
public function testListenersOnSingleBackingContentUpdate() : void{
$backing = new SimpleInventory(2);
$inventory = new CombinedInventory([$backing]);
$inventory = new CombinedInventoryProxy([$backing]);
$numChanges = 0;
$inventory->getListeners()->add(new CallbackInventoryListener(