Add API to get full list of stacks for an item/fluid type. #2804
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds an API method to allow fetching the complete list of stacks matching a given item type.
(The existing APIs only let you get a list of all stacks of all types [which is less efficient], or the first stack matching a given item/fluid name and NBT matching flags [which may be insufficient].)
The motivating case is to allow a more complex NBT comparison for an item by calling the new
getStacks(type)
(which is more efficient than callinggetStacks()
as it doesn't need to process many extraneous items on large storages), perform some custom logic to decide which of these stacks is the one desired (e.g. by evaluating the tags), and then use that stack in further operations (such as extracting it).I considered an alternative implementation that returned only the
ItemStack
/FluidStack
in the list rather than the full entry, but (a) providing the UUID might enable usingget(uuid)
to try a faster lookup later on, and (b) this way seemed more efficient since it doesn't require creating a new collection.