use of logisticspipes.interfaces.routing.IProvideItems in project LogisticsPipes by RS485.
the class LogisticsManager method getAmountFor.
@Override
public int getAmountFor(ItemIdentifier itemType, List<ExitRoute> validDestinations) {
// TODO: Replace this entire function wiht a fetch from the pre-built arrays (path incoming later)
List<Map<ItemIdentifier, Integer>> items = new ArrayList<>(ServerRouter.getBiggestSimpleID());
for (int i = 0; i < ServerRouter.getBiggestSimpleID(); i++) {
items.add(new HashMap<>());
}
BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
outer: for (ExitRoute r : validDestinations) {
if (r == null) {
continue;
}
if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
continue;
}
if (!(r.destination.getPipe() instanceof IProvideItems)) {
continue;
}
for (IFilter filter : r.filters) {
if (filter.blockProvider()) {
continue outer;
}
}
IProvideItems provider = (IProvideItems) r.destination.getPipe();
provider.getAllItems(items.get(r.destination.getSimpleID()), r.filters);
used.set(r.destination.getSimpleID(), true);
}
// TODO: Fix this doubly nested list
int amount = 0;
for (Map<ItemIdentifier, Integer> allItems : items) {
for (Entry<ItemIdentifier, Integer> item : allItems.entrySet()) {
if (item.getKey().equals(itemType)) {
amount += item.getValue();
}
}
}
return amount;
}
use of logisticspipes.interfaces.routing.IProvideItems in project LogisticsPipes by RS485.
the class LogisticsManager method getAvailableItems.
/**
* @param validDestinations
* a list of ExitRoute of valid destinations.
* @return HashMap with ItemIdentifier and Integer item count of available
* items.
*/
@Override
public HashMap<ItemIdentifier, Integer> getAvailableItems(List<ExitRoute> validDestinations) {
// TODO: Replace this entire function wiht a fetch from the pre-built arrays (path incoming later)
List<Map<ItemIdentifier, Integer>> items = new ArrayList<>(ServerRouter.getBiggestSimpleID());
for (int i = 0; i < ServerRouter.getBiggestSimpleID(); i++) {
items.add(new HashMap<>());
}
BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
outer: for (ExitRoute r : validDestinations) {
if (r == null) {
continue;
}
if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
continue;
}
if (!(r.destination.getPipe() instanceof IProvideItems)) {
continue;
}
for (IFilter filter : r.filters) {
if (filter.blockProvider()) {
continue outer;
}
}
IProvideItems provider = (IProvideItems) r.destination.getPipe();
provider.getAllItems(items.get(r.destination.getSimpleID()), r.filters);
used.set(r.destination.getSimpleID(), true);
}
// TODO: Fix this doubly nested list
HashMap<ItemIdentifier, Integer> allAvailableItems = new HashMap<>();
for (Map<ItemIdentifier, Integer> allItems : items) {
for (Entry<ItemIdentifier, Integer> item : allItems.entrySet()) {
allAvailableItems.merge(item.getKey(), item.getValue(), Integer::sum);
}
}
return allAvailableItems;
}
use of logisticspipes.interfaces.routing.IProvideItems in project LogisticsPipes by RS485.
the class ModuleProvider method canProvide.
@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
List<ItemIdentifier> possible = new ArrayList<>();
if (tree.getRequestType() instanceof ItemResource) {
possible.add(((ItemResource) tree.getRequestType()).getItem());
} else if (tree.getRequestType() instanceof DictResource) {
possible.addAll(inventoriesWithMode().map(IInventoryUtil::getItemsAndCount).flatMap(inventory -> inventory.keySet().stream()).filter(item -> tree.getRequestType().matches(item, IResource.MatchSettings.NORMAL)).collect(Collectors.toList()));
}
for (ItemIdentifier item : possible) {
int canProvide = getAvailableItemCount(item);
canProvide -= root.getAllPromissesFor((IProvideItems) _service, item);
canProvide = Math.min(canProvide, tree.getMissingAmount());
if (canProvide < 1) {
return;
}
LogisticsPromise promise = new LogisticsPromise(item, canProvide, (IProvideItems) _service, ResourceType.PROVIDER);
tree.addPromise(promise);
}
}
Aggregations