mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-11 12:27:51 +00:00
Rename CombinedInventory -> CombinedInventoryProxy
This commit is contained in:
parent
9949e3815f
commit
0fe786af4d
@ -23,7 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\block\tile;
|
namespace pocketmine\block\tile;
|
||||||
|
|
||||||
use pocketmine\inventory\CombinedInventory;
|
use pocketmine\inventory\CombinedInventoryProxy;
|
||||||
use pocketmine\inventory\Inventory;
|
use pocketmine\inventory\Inventory;
|
||||||
use pocketmine\inventory\SimpleInventory;
|
use pocketmine\inventory\SimpleInventory;
|
||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
@ -46,7 +46,7 @@ class Chest extends Spawnable implements ContainerTile, Nameable{
|
|||||||
public const TAG_PAIR_LEAD = "pairlead";
|
public const TAG_PAIR_LEAD = "pairlead";
|
||||||
|
|
||||||
protected Inventory $inventory;
|
protected Inventory $inventory;
|
||||||
protected ?CombinedInventory $doubleInventory = null;
|
protected ?CombinedInventoryProxy $doubleInventory = null;
|
||||||
|
|
||||||
private ?int $pairX = null;
|
private ?int $pairX = null;
|
||||||
private ?int $pairZ = null;
|
private ?int $pairZ = null;
|
||||||
@ -113,7 +113,7 @@ class Chest extends Spawnable implements ContainerTile, Nameable{
|
|||||||
$this->containerTraitBlockDestroyedHook();
|
$this->containerTraitBlockDestroyedHook();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInventory() : Inventory|CombinedInventory{
|
public function getInventory() : Inventory|CombinedInventoryProxy{
|
||||||
if($this->isPaired() && $this->doubleInventory === null){
|
if($this->isPaired() && $this->doubleInventory === null){
|
||||||
$this->checkPairing();
|
$this->checkPairing();
|
||||||
}
|
}
|
||||||
@ -139,9 +139,9 @@ class Chest extends Spawnable implements ContainerTile, Nameable{
|
|||||||
$this->doubleInventory = $pair->doubleInventory;
|
$this->doubleInventory = $pair->doubleInventory;
|
||||||
}else{
|
}else{
|
||||||
if(($pair->position->x + ($pair->position->z << 15)) > ($this->position->x + ($this->position->z << 15))){ //Order them correctly
|
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{
|
}else{
|
||||||
$this->doubleInventory = $pair->doubleInventory = new CombinedInventory([$this->inventory, $pair->inventory]);
|
$this->doubleInventory = $pair->doubleInventory = new CombinedInventoryProxy([$this->inventory, $pair->inventory]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ use function spl_object_id;
|
|||||||
* Allows interacting with several separate inventories via a unified interface
|
* Allows interacting with several separate inventories via a unified interface
|
||||||
* Mainly used for double chests, but could be used for other custom use cases
|
* 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;
|
private readonly int $size;
|
||||||
|
|
@ -23,12 +23,13 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\inventory;
|
namespace pocketmine\inventory;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
use pocketmine\item\Item;
|
use pocketmine\item\Item;
|
||||||
use pocketmine\item\ItemTypeIds;
|
use pocketmine\item\ItemTypeIds;
|
||||||
use pocketmine\item\VanillaItems;
|
use pocketmine\item\VanillaItems;
|
||||||
use function array_filter;
|
use function array_filter;
|
||||||
|
|
||||||
final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
final class CombinedInventoryProxyTest extends TestCase{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Inventory[]
|
* @return Inventory[]
|
||||||
@ -70,7 +71,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testGetItem() : void{
|
public function testGetItem() : void{
|
||||||
$inventory = new CombinedInventory($this->createInventories());
|
$inventory = new CombinedInventoryProxy($this->createInventories());
|
||||||
|
|
||||||
$this->verifyReadItems([
|
$this->verifyReadItems([
|
||||||
$inventory->getItem(0),
|
$inventory->getItem(0),
|
||||||
@ -84,7 +85,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testGetContents() : void{
|
public function testGetContents() : void{
|
||||||
$inventory = new CombinedInventory($this->createInventories());
|
$inventory = new CombinedInventoryProxy($this->createInventories());
|
||||||
|
|
||||||
$this->verifyReadItems($inventory->getContents(includeEmpty: true));
|
$this->verifyReadItems($inventory->getContents(includeEmpty: true));
|
||||||
|
|
||||||
@ -123,7 +124,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
|||||||
|
|
||||||
public function testSetItem() : void{
|
public function testSetItem() : void{
|
||||||
$backing = $this->createInventories();
|
$backing = $this->createInventories();
|
||||||
$inventory = new CombinedInventory($backing);
|
$inventory = new CombinedInventoryProxy($backing);
|
||||||
|
|
||||||
$altItems = self::getAltItems();
|
$altItems = self::getAltItems();
|
||||||
foreach($altItems as $slot => $item){
|
foreach($altItems as $slot => $item){
|
||||||
@ -152,25 +153,25 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
|||||||
*/
|
*/
|
||||||
public function testSetContents(array $altItems) : void{
|
public function testSetContents(array $altItems) : void{
|
||||||
$backing = $this->createInventories();
|
$backing = $this->createInventories();
|
||||||
$inventory = new CombinedInventory($backing);
|
$inventory = new CombinedInventoryProxy($backing);
|
||||||
$inventory->setContents($altItems);
|
$inventory->setContents($altItems);
|
||||||
|
|
||||||
$this->verifyWriteItems($backing, $altItems);
|
$this->verifyWriteItems($backing, $altItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetSize() : void{
|
public function testGetSize() : void{
|
||||||
self::assertSame(4, (new CombinedInventory($this->createInventories()))->getSize());
|
self::assertSame(4, (new CombinedInventoryProxy($this->createInventories()))->getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetMatchingItemCount() : void{
|
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
|
//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::assertSame(1, $inventory->getMatchingItemCount(3, VanillaItems::BONE(), true));
|
||||||
self::assertNotSame(1, $inventory->getMatchingItemCount(3, VanillaItems::PAPER(), true));
|
self::assertNotSame(1, $inventory->getMatchingItemCount(3, VanillaItems::PAPER(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsSlotEmpty() : void{
|
public function testIsSlotEmpty() : void{
|
||||||
$inventory = new CombinedInventory($this->createInventories());
|
$inventory = new CombinedInventoryProxy($this->createInventories());
|
||||||
|
|
||||||
self::assertTrue($inventory->isSlotEmpty(2));
|
self::assertTrue($inventory->isSlotEmpty(2));
|
||||||
self::assertFalse($inventory->isSlotEmpty(0));
|
self::assertFalse($inventory->isSlotEmpty(0));
|
||||||
@ -179,7 +180,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testListenersOnProxySlotUpdate() : void{
|
public function testListenersOnProxySlotUpdate() : void{
|
||||||
$inventory = new CombinedInventory($this->createInventories());
|
$inventory = new CombinedInventoryProxy($this->createInventories());
|
||||||
|
|
||||||
$numChanges = 0;
|
$numChanges = 0;
|
||||||
$inventory->getListeners()->add(new CallbackInventoryListener(
|
$inventory->getListeners()->add(new CallbackInventoryListener(
|
||||||
@ -193,7 +194,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testListenersOnProxyContentUpdate() : void{
|
public function testListenersOnProxyContentUpdate() : void{
|
||||||
$inventory = new CombinedInventory($this->createInventories());
|
$inventory = new CombinedInventoryProxy($this->createInventories());
|
||||||
|
|
||||||
$numChanges = 0;
|
$numChanges = 0;
|
||||||
$inventory->getListeners()->add(new CallbackInventoryListener(
|
$inventory->getListeners()->add(new CallbackInventoryListener(
|
||||||
@ -208,7 +209,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
|||||||
|
|
||||||
public function testListenersOnBackingSlotUpdate() : void{
|
public function testListenersOnBackingSlotUpdate() : void{
|
||||||
$backing = $this->createInventories();
|
$backing = $this->createInventories();
|
||||||
$inventory = new CombinedInventory($backing);
|
$inventory = new CombinedInventoryProxy($backing);
|
||||||
|
|
||||||
$slotChangeDetected = null;
|
$slotChangeDetected = null;
|
||||||
$numChanges = 0;
|
$numChanges = 0;
|
||||||
@ -231,7 +232,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
|||||||
*/
|
*/
|
||||||
public function testListenersOnBackingContentUpdate() : void{
|
public function testListenersOnBackingContentUpdate() : void{
|
||||||
$backing = $this->createInventories();
|
$backing = $this->createInventories();
|
||||||
$inventory = new CombinedInventory($backing);
|
$inventory = new CombinedInventoryProxy($backing);
|
||||||
|
|
||||||
$slotChanges = [];
|
$slotChanges = [];
|
||||||
$inventory->getListeners()->add(new CallbackInventoryListener(
|
$inventory->getListeners()->add(new CallbackInventoryListener(
|
||||||
@ -253,7 +254,7 @@ final class CombinedInventoryTest extends \PHPUnit\Framework\TestCase{
|
|||||||
*/
|
*/
|
||||||
public function testListenersOnSingleBackingContentUpdate() : void{
|
public function testListenersOnSingleBackingContentUpdate() : void{
|
||||||
$backing = new SimpleInventory(2);
|
$backing = new SimpleInventory(2);
|
||||||
$inventory = new CombinedInventory([$backing]);
|
$inventory = new CombinedInventoryProxy([$backing]);
|
||||||
|
|
||||||
$numChanges = 0;
|
$numChanges = 0;
|
||||||
$inventory->getListeners()->add(new CallbackInventoryListener(
|
$inventory->getListeners()->add(new CallbackInventoryListener(
|
Loading…
x
Reference in New Issue
Block a user