Cleaned up implementations for EnderChestInventory/DoubleChestInventory

previously, these were forced to extend BaseInventory because of the amount of crap in Inventory's interface.
This meant that these inventories had their own slots storage, which would be _mostly_ unused because these inventories aren't real inventories, but rather just delegates.
This lead to a variety of bugs in the past, such as certain API methods on BaseInventory not working correctly for DoubleChestInventory in particular.

Now, BaseInventory just implements the functional part of the inventory implementation, leaving the storage system up to the implementation.
A SimpleInventory class is provided with a simple SplFixedArray storage backing, which is used by most inventories.
EnderChestInventory and DoubleChestInventory now extend BaseInventory directly, and implement custom methods for dealing with their delegates.
This commit is contained in:
Dylan K. Taylor
2021-05-09 20:50:40 +01:00
parent 1533789f35
commit f909557529
22 changed files with 237 additions and 99 deletions

View File

@ -30,7 +30,7 @@ use pocketmine\item\ItemIds;
class BaseInventoryTest extends TestCase{
public function testAddItemDifferentUserData() : void{
$inv = new class(1) extends BaseInventory{
$inv = new class(1) extends SimpleInventory{
};
$item1 = ItemFactory::getInstance()->get(ItemIds::ARROW, 0, 1);