Commit Graph

31 Commits

Author SHA1 Message Date
8633804f15 InventoryManager: disentangle slot tracking from slot syncing 2023-01-06 20:26:19 +00:00
1e9d83f014 BaseInventory: validate given array in setContents() (#5391) 2022-11-07 13:09:05 +00:00
6866c86d39 BaseInventory: fix CS 2022-09-02 19:36:45 +01:00
a735a69870 BaseInventory: improve type info available to setContents() and internalSetContents() 2022-09-02 19:36:08 +01:00
38d6284671 Use PHP-CS-Fixer to enforce file header presence 2022-06-04 17:34:49 +01:00
bf71eb448a Reduce chaos in inventory classes 2022-03-22 17:19:55 +00:00
2c29d272ad BaseInventory: move setMaxStackSize() to a more sensible place 2022-03-22 17:11:48 +00:00
e986a0a4f2 Replace disallowed operators in src/inventory/ 2022-01-20 19:20:32 +00:00
ed4978c31b Added VanillaItems::AIR()
we don't usually add VanillaItems entries for blocks since they already exist in VanillaBlocks, but air has a special use case specifically as an itemstack, so we make an exception for this case.
2021-12-07 00:41:07 +00:00
a5833327f0 Inventory: added getAddableItemQuantity()
this mostly reuses the code from canAddItem().
2021-10-11 21:46:27 +01:00
00984c1b9f BaseInventory: Move contents of InventoryHelpersTrait back inline
I moved these to a trait in anticipation of having multiple full Inventory implementations. That's no longer necessary because of the abstraction of SimpleInventory.
2021-08-04 20:57:20 +01:00
0910054c41 NetworkSession: Fixed InventoryManager nullability disaster
fixes #4277
fixes #4275
fixes #3139
2021-06-26 17:44:42 +01:00
f909557529 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.
2021-05-09 20:51:16 +01:00
b8645f5c15 Clean up EnderChestInventory implementation
now, EnderChestInventory is just a temporary window, much like anvil/enchanting windows. It provides a gateway to the player's PlayerEnderInventory.

This removes one of the remaining obstacles to disallowing null World in Position constructor.
2021-05-02 14:26:27 +01:00
9b8f32c584 Extract inventory helper methods from BaseInventory to a trait
this allows easier alternate implementations of Inventory that don't extend BaseInventory (e.g. double chest, or delegate inventory).
2021-05-02 13:38:49 +01:00
c61f66d973 Removed ext-ds dependency 2021-02-11 15:40:37 +00:00
eca0e88471 BaseInventory: fixed passing NULL slots to InventoryListener->onContentChange()
as per the documentation, InventoryListener->onContentChange() does not expect to receive NULL in the given array.
2020-12-05 01:11:30 +00:00
73a8c90bee Merge remote-tracking branch 'origin/stable'
# Conflicts:
#	resources/vanilla
#	src/world/Explosion.php
#	tests/phpunit/item/ItemTest.php
#	tests/phpunit/world/format/io/region/RegionLoaderTest.php
#	tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMainLoggerTest.php
#	tests/plugins/TesterPlugin/src/pmmp/TesterPlugin/tests/AsyncTaskMemoryLeakTest.php
2020-11-01 14:21:47 +00:00
4437756987 Inventory: reduce API duplication by using a Set for viewers 2020-05-14 14:13:28 +01:00
6e6fffa461 Inventory: added removeAllListeners()
this isn't strictly necessary because it could be done by removeListeners(...getListeners()), but I think developers will appreciate not needing so much boilerplate code.
2020-05-03 21:44:45 +01:00
4fbf4dcdc6 Rename InventoryChangeListener -> InventoryListener 2020-04-24 23:44:38 +01:00
12e4e92894 Inventory: Pass old item(s) to inventory change listeners, closes #3323 (#3337) 2020-03-09 13:52:15 +00:00
78394a336c Merge branch 'stable' 2020-02-25 20:45:39 +00:00
7c2741e4f5 Inventory: eliminate remaining $send parameters 2020-02-23 21:59:51 +00:00
b108fb61bf Inventory: drop $send params from setItem() and clear() 2020-02-12 13:34:35 +00:00
1c06438cbb Inventory: remove final usage of $send parameter of setItem() and clear() 2020-02-12 13:33:23 +00:00
fb1126797a Merge branch 'stable' 2020-02-07 18:13:55 +00:00
67bcc1c0fb phpdoc armageddon for master, pass 1 2020-01-22 11:55:03 +00:00
a9c09e4517 Merge branch 'next-minor' 2019-12-12 13:52:14 +00:00
d3d7709ead Merge branch 'next-minor' 2019-12-03 11:55:45 +00:00
5499ac620c Removed pocketmine subdirectory, map PSR-4 style 2019-07-30 19:14:57 +01:00