From a11a5e306ef4d10337ea1ae69a67cd09467cfe4d Mon Sep 17 00:00:00 2001 From: Gavin Lambert Date: Sat, 2 Jan 2021 23:36:23 +1300 Subject: [PATCH] Add API to get full list of stacks for an item/fluid type. (#2804) --- .../refinedstorage/api/util/IStackList.java | 6 ++++++ .../refinedstorage/apiimpl/util/FluidStackList.java | 12 ++++++++---- .../refinedstorage/apiimpl/util/ItemStackList.java | 11 +++++++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/refinedmods/refinedstorage/api/util/IStackList.java b/src/main/java/com/refinedmods/refinedstorage/api/util/IStackList.java index 4ed5bb2af3..db0e9aa9f4 100644 --- a/src/main/java/com/refinedmods/refinedstorage/api/util/IStackList.java +++ b/src/main/java/com/refinedmods/refinedstorage/api/util/IStackList.java @@ -118,6 +118,12 @@ default int getCount(@Nonnull T stack) { @Nonnull Collection> getStacks(); + /** + * @return a collection of stacks matching the given type (ignoring NBT) + */ + @Nonnull + Collection> getStacks(@Nonnull T stack); + /** * @return a new copy of this list, with the stacks in it copied as well */ diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/util/FluidStackList.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/util/FluidStackList.java index 3157fbe582..cdea3db262 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/util/FluidStackList.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/util/FluidStackList.java @@ -6,14 +6,12 @@ import com.refinedmods.refinedstorage.api.util.StackListResult; import com.refinedmods.refinedstorage.apiimpl.API; import net.minecraft.fluid.Fluid; +import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; public class FluidStackList implements IStackList { private final ArrayListMultimap> stacks = ArrayListMultimap.create(); @@ -143,6 +141,12 @@ public Collection> getStacks() { return stacks.values(); } + @Override + @Nonnull + public Collection> getStacks(@Nonnull FluidStack stack) { + return stacks.get(stack.getFluid()); + } + @Override @Nonnull public IStackList copy() { diff --git a/src/main/java/com/refinedmods/refinedstorage/apiimpl/util/ItemStackList.java b/src/main/java/com/refinedmods/refinedstorage/apiimpl/util/ItemStackList.java index 385fabdb39..bb3aa4ea52 100644 --- a/src/main/java/com/refinedmods/refinedstorage/apiimpl/util/ItemStackList.java +++ b/src/main/java/com/refinedmods/refinedstorage/apiimpl/util/ItemStackList.java @@ -11,10 +11,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; public class ItemStackList implements IStackList { private final ArrayListMultimap> stacks = ArrayListMultimap.create(); @@ -141,6 +138,12 @@ public Collection> getStacks() { return stacks.values(); } + @Override + @Nonnull + public Collection> getStacks(@Nonnull ItemStack stack) { + return stacks.get(stack.getItem()); + } + @Override @Nonnull public IStackList copy() {