use of logisticspipes.routing.LogisticsPromise 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) {
IInventoryUtil inv = _service.getPointedInventory(_extractionMode, true);
if (inv != null) {
Map<ItemIdentifier, Integer> currentInv = inv.getItemsAndCount();
possible.addAll(currentInv.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);
}
}
use of logisticspipes.routing.LogisticsPromise in project LogisticsPipes by RS485.
the class PipeLogisticsChassi method registerExtras.
@Override
public void registerExtras(IPromise promise) {
if (!(promise instanceof LogisticsPromise)) {
throw new UnsupportedOperationException("Extra has to be an item for a chassis pipe");
}
ItemIdentifierStack stack = new ItemIdentifierStack(((LogisticsPromise) promise).item, ((LogisticsPromise) promise).numberOfItems);
_extras.add(new LogisticsItemOrder(new DictResource(stack, null), null, ResourceType.EXTRA, null));
}
use of logisticspipes.routing.LogisticsPromise in project LogisticsPipes by RS485.
the class PipeItemsProviderLogistics method canProvide.
@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
if (!isEnabled()) {
return;
}
if (tree.getRequestType() instanceof ItemResource) {
ItemIdentifier item = ((ItemResource) tree.getRequestType()).getItem();
for (IFilter filter : filters) {
if (filter.isBlocked() == filter.isFilteredItem(item.getUndamaged()) || filter.blockProvider()) {
return;
}
}
// Check the transaction and see if we have helped already
int canProvide = getAvailableItemCount(item);
canProvide -= root.getAllPromissesFor(this, item);
if (canProvide < 1) {
return;
}
LogisticsPromise promise = new LogisticsPromise(item, Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
tree.addPromise(promise);
} else if (tree.getRequestType() instanceof DictResource) {
DictResource dict = (DictResource) tree.getRequestType();
HashMap<ItemIdentifier, Integer> available = new HashMap<>();
getAllItems(available, filters);
for (Entry<ItemIdentifier, Integer> item : available.entrySet()) {
if (!dict.matches(item.getKey(), IResource.MatchSettings.NORMAL)) {
continue;
}
int canProvide = getAvailableItemCount(item.getKey());
canProvide -= root.getAllPromissesFor(this, item.getKey());
if (canProvide < 1) {
continue;
}
LogisticsPromise promise = new LogisticsPromise(item.getKey(), Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
tree.addPromise(promise);
if (tree.getMissingAmount() <= 0) {
break;
}
}
}
}
Aggregations