Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Inventory#all doesn't scan the entire inventory

Open NonSwag opened this issue 1 year ago • 2 comments

Expected behavior

Suggested by the docs of the method, it should look up all slots in the entire inventory

Observed/Actual behavior

It only looks up the storage content

Steps/models to reproduce

Well... it's just an inconsistency... soo...

Plugin and Datapack List

unimportent

Paper version

1.20.6-R0.1-SNAPSHOT

Other

docs: image implementation: image

NonSwag avatar May 11 '24 17:05 NonSwag

I think this is "works as intended" due to the documentation on Inventory#getStorageContents. The javadocs for that method say

In most cases this will represent the entire inventory, but in some cases it may exclude armor or result slots.

and continues

It is these contents which will be used for add / contains / remove methods which look for a specific stack

I think that second part includes the #all method you mention here, as its looking for a specific stack. And it's right, all the other methods only operate on the "storage contents".

Machine-Maker avatar May 13 '24 04:05 Machine-Maker

It looks like previously, Paper has added specific API to cover "all slots". There is a Inventory#removeItemAnySlot method to account for the other Inventory#removeItem only removing from the "storage" contents. I think that is the better solution here, adding an "any slot" variant of all the methods that have "storage-specific" versions.

Machine-Maker avatar May 13 '24 21:05 Machine-Maker