166 Commits

Author SHA1 Message Date
Dylan K. Taylor
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
Dylan K. Taylor
7ba573db77
Added API method Item::canStackWith() 2021-06-29 19:52:52 +01:00
Dylan T
32d7b1e6af
Start using webmozart/pathutil for joining paths (#4287) 2021-06-29 19:40:43 +01:00
Dylan K. Taylor
9b30c2feda
Extract a DelegateInventory from EnderChestInventory 2021-06-26 21:01:40 +01:00
Dylan K. Taylor
0910054c41
NetworkSession: Fixed InventoryManager nullability disaster
fixes #4277
fixes #4275
fixes #3139
2021-06-26 17:44:42 +01:00
aieuo
a6039ad733
Fixed InventoryHelpersTrait::addItem() cannot add items with a count greater than maxstack (#4283) 2021-06-26 16:48:53 +01:00
Jason
15e5bdb210
BaseInventory::addItem(item1,item2,item3) now has the same behaviour as multiple separate addItem() calls (#4237)
fixes #1412
2021-06-17 21:05:24 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
01794adef1
... 2021-05-05 22:24:23 +01:00
Dylan K. Taylor
652de2632a
Rough OffHand implementation
this doesn't do stuff like taking arrows from offhand yet.
2021-05-05 14:46:51 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
4c783f1037
shut 2021-05-02 13:43:37 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
c61f66d973
Removed ext-ds dependency 2021-02-11 15:40:37 +00:00
Dylan K. Taylor
3e1ac66abf
Merge branch 'stable' 2021-02-02 13:46:29 +00:00
Dylan K. Taylor
c70c0b55df
Separate held item index change listener logic from PlayerInventory 2021-01-12 16:44:25 +00:00
Dylan K. Taylor
01c867b608
Human: make held item sync on inventory content change more consistent
before this change, setContents() wouldn't trigger a held item sync, nor would setItem(heldItemIndex, someItem).
2021-01-10 20:30:39 +00:00
Dylan K. Taylor
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
Dylan K. Taylor
d08c9ee634 Merge remote-tracking branch 'origin/stable'
# Conflicts:
#	resources/vanilla
#	src/pocketmine/VersionInfo.php
2020-11-10 22:44:59 +00:00
Dylan K. Taylor
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
Dylan K. Taylor
d6ed542fcd Merge remote-tracking branch 'origin/stable' into master
# Conflicts:
#	composer.json
#	composer.lock
#	src/CrashDump.php
#	src/pocketmine/Server.php
#	src/pocketmine/level/format/io/region/McRegion.php
#	tests/phpstan/configs/check-explicit-mixed-baseline.neon
#	tests/phpstan/configs/l7-baseline.neon
#	tests/phpstan/configs/l8-baseline.neon
#	tests/travis/setup-php.yml
2020-10-26 16:18:53 +00:00
Dylan K. Taylor
e1d80f05b1 Merge branch 'stable' into master 2020-08-03 20:14:46 +01:00
Dylan K. Taylor
1d18662d9b InventoryAction: replace isValid() with validate() which throws TransactionValidationException 2020-07-04 19:38:34 +01:00
Dylan K. Taylor
cf5e31c619 InventoryTransaction::execute() now throws exceptions instead of returning true/false 2020-07-01 14:08:28 +01:00
Dylan K. Taylor
29612cded3 CraftingTransaction: make CraftingManager injectable
this becomes a bit easier to unit-test.
2020-07-01 13:38:06 +01:00
Dylan K. Taylor
5b0964cec8 Merge commit '2dc3cf816'
# Conflicts:
#	resources/vanilla
2020-06-03 12:52:42 +01:00
Dylan K. Taylor
4437756987 Inventory: reduce API duplication by using a Set for viewers 2020-05-14 14:13:28 +01:00
Dylan K. Taylor
f34753c496 CallbackInventoryListener: fix crash when any of the callbacks isn't provided 2020-05-03 21:48:32 +01:00
Dylan K. Taylor
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
Dylan K. Taylor
adadd5423d move force-close crafting grid hack to InGamePacketHandler
the crafting transaction implementation has no business caring about this
2020-04-29 16:54:23 +01:00
Dylan K. Taylor
6dd31cc3f5 break cycle between block and inventory packages 2020-04-24 23:53:49 +01:00
Dylan K. Taylor
4fbf4dcdc6 Rename InventoryChangeListener -> InventoryListener 2020-04-24 23:44:38 +01:00
Dylan K. Taylor
08ac6a3c43 Convert CreativeInventory to singleton 2020-04-24 00:38:18 +01:00
Dylan K. Taylor
86e051b7bf Merge commit 'a2543ff80d2906bccda1a4e2fdbd9d8e7d147fb3' 2020-04-18 17:33:05 +01:00
DaPigGuy
12e4e92894
Inventory: Pass old item(s) to inventory change listeners, closes #3323 (#3337) 2020-03-09 13:52:15 +00:00
Dylan K. Taylor
78394a336c Merge branch 'stable' 2020-02-25 20:45:39 +00:00
Dylan K. Taylor
7c2741e4f5 Inventory: eliminate remaining $send parameters 2020-02-23 21:59:51 +00:00
Dylan K. Taylor
b108fb61bf Inventory: drop $send params from setItem() and clear() 2020-02-12 13:34:35 +00:00
Dylan K. Taylor
1c06438cbb Inventory: remove final usage of $send parameter of setItem() and clear() 2020-02-12 13:33:23 +00:00
Dylan K. Taylor
4014f9a4f2 InventoryManager: be aware of client-side state when syncing slots
this eliminates feedback loops during client-initiated slot changes, and also makes it possible to have a SlotChangeAction anonymous from its initiator.
2020-02-11 21:12:18 +00:00
Dylan K. Taylor
d2aca6023b add native return types to closures (for phpstan) 2020-02-07 22:05:15 +00:00
Dylan K. Taylor
3a9e6bb612 CallbackInventoryChangeListener: fix use of tab instead of space 2020-02-07 19:28:43 +00:00
Dylan K. Taylor
fb1126797a Merge branch 'stable' 2020-02-07 18:13:55 +00:00
Dylan K. Taylor
85fdb7ec05 CallbackInventoryChangeListener: provide signature information for closures 2020-01-27 18:08:59 +00:00
Dylan K. Taylor
67bcc1c0fb phpdoc armageddon for master, pass 1 2020-01-22 11:55:03 +00:00
Dylan K. Taylor
3ee6887792 populate remaining missing return types, using native returns where possible
this is done separately to stable so that stable changes can be integrated easily using an empty merge.
2020-01-19 10:26:35 +00:00
Dylan K. Taylor
cda1143a79 Merge branch 'stable' 2020-01-09 17:17:42 +00:00
Dylan K. Taylor
0f718ea28b Merge commit '8726604899d1a371567141e0831ed570d3233356' 2019-12-25 14:19:35 +00:00
Dylan K. Taylor
a9c09e4517 Merge branch 'next-minor' 2019-12-12 13:52:14 +00:00
Dylan K. Taylor
d3d7709ead Merge branch 'next-minor' 2019-12-03 11:55:45 +00:00