Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to get full list of stacks for an item/fluid type. #2804

Merged
merged 1 commit into from
Jan 2, 2021

Conversation

uecasm
Copy link
Contributor

@uecasm uecasm commented Jan 2, 2021

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 calling getStacks() 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 using get(uuid) to try a faster lookup later on, and (b) this way seemed more efficient since it doesn't require creating a new collection.

@raoulvdberge raoulvdberge merged commit a11a5e3 into refinedmods:mc1.16 Jan 2, 2021
@uecasm uecasm deleted the get-stacks-list branch January 2, 2021 10:43
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants