Skip to content

Commit

Permalink
Add API to get full list of stacks for an item/fluid type. (#2804)
Browse files Browse the repository at this point in the history
  • Loading branch information
uecasm authored Jan 2, 2021
1 parent 74ab430 commit a11a5e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ default int getCount(@Nonnull T stack) {
@Nonnull
Collection<StackListEntry<T>> getStacks();

/**
* @return a collection of stacks matching the given type (ignoring NBT)
*/
@Nonnull
Collection<StackListEntry<T>> getStacks(@Nonnull T stack);

/**
* @return a new copy of this list, with the stacks in it copied as well
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FluidStack> {
private final ArrayListMultimap<Fluid, StackListEntry<FluidStack>> stacks = ArrayListMultimap.create();
Expand Down Expand Up @@ -143,6 +141,12 @@ public Collection<StackListEntry<FluidStack>> getStacks() {
return stacks.values();
}

@Override
@Nonnull
public Collection<StackListEntry<FluidStack>> getStacks(@Nonnull FluidStack stack) {
return stacks.get(stack.getFluid());
}

@Override
@Nonnull
public IStackList<FluidStack> copy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> {
private final ArrayListMultimap<Item, StackListEntry<ItemStack>> stacks = ArrayListMultimap.create();
Expand Down Expand Up @@ -141,6 +138,12 @@ public Collection<StackListEntry<ItemStack>> getStacks() {
return stacks.values();
}

@Override
@Nonnull
public Collection<StackListEntry<ItemStack>> getStacks(@Nonnull ItemStack stack) {
return stacks.get(stack.getItem());
}

@Override
@Nonnull
public IStackList<ItemStack> copy() {
Expand Down

0 comments on commit a11a5e3

Please sign in to comment.