Search in sources :

Example 1 with IProvideFluids

use of logisticspipes.interfaces.routing.IProvideFluids in project LogisticsPipes by RS485.

the class LogisticsFluidManager method getAvailableFluid.

@Override
public TreeSet<ItemIdentifierStack> getAvailableFluid(List<ExitRoute> validDestinations) {
    Map<FluidIdentifier, Integer> allAvailableItems = new HashMap<>();
    for (ExitRoute r : validDestinations) {
        if (r == null) {
            continue;
        }
        if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            continue;
        }
        if (!(r.destination.getPipe() instanceof IProvideFluids)) {
            continue;
        }
        IProvideFluids provider = (IProvideFluids) r.destination.getPipe();
        Map<FluidIdentifier, Integer> allItems = provider.getAvailableFluids();
        for (Entry<FluidIdentifier, Integer> liquid : allItems.entrySet()) {
            Integer amount = allAvailableItems.get(liquid.getKey());
            if (amount == null) {
                allAvailableItems.put(liquid.getKey(), liquid.getValue());
            } else {
                long addition = ((long) amount) + liquid.getValue();
                if (addition > Integer.MAX_VALUE) {
                    addition = Integer.MAX_VALUE;
                }
                allAvailableItems.put(liquid.getKey(), (int) addition);
            }
        }
    }
    TreeSet<ItemIdentifierStack> itemIdentifierStackList = allAvailableItems.entrySet().stream().map(item -> new ItemIdentifierStack(item.getKey().getItemIdentifier(), item.getValue())).collect(Collectors.toCollection(TreeSet::new));
    return itemIdentifierStackList;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) PipeRoutingConnectionType(logisticspipes.routing.PipeRoutingConnectionType) IRouter(logisticspipes.routing.IRouter) LogisticsPipes(logisticspipes.LogisticsPipes) IFluidSink(logisticspipes.interfaces.routing.IFluidSink) HashMap(java.util.HashMap) LogisticsFluidContainer(logisticspipes.items.LogisticsFluidContainer) Collectors(java.util.stream.Collectors) ExitRoute(logisticspipes.routing.ExitRoute) TreeSet(java.util.TreeSet) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Map(java.util.Map) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) FluidStack(net.minecraftforge.fluids.FluidStack) IProvideFluids(logisticspipes.interfaces.routing.IProvideFluids) HashMap(java.util.HashMap) IProvideFluids(logisticspipes.interfaces.routing.IProvideFluids) FluidIdentifier(logisticspipes.utils.FluidIdentifier) ExitRoute(logisticspipes.routing.ExitRoute) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Aggregations

HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeSet (java.util.TreeSet)1 Collectors (java.util.stream.Collectors)1 LogisticsPipes (logisticspipes.LogisticsPipes)1 IFluidSink (logisticspipes.interfaces.routing.IFluidSink)1 IProvideFluids (logisticspipes.interfaces.routing.IProvideFluids)1 LogisticsFluidContainer (logisticspipes.items.LogisticsFluidContainer)1 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)1 ExitRoute (logisticspipes.routing.ExitRoute)1 IRouter (logisticspipes.routing.IRouter)1 PipeRoutingConnectionType (logisticspipes.routing.PipeRoutingConnectionType)1 FluidIdentifier (logisticspipes.utils.FluidIdentifier)1 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)1 Pair (logisticspipes.utils.tuples.Pair)1 ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 FluidStack (net.minecraftforge.fluids.FluidStack)1