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;
}
Aggregations