use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class PipeItemsInvSysConnector method getExpectedItems.
public Set<ItemIdentifierStack> getExpectedItems() {
// got to be a TreeMap, because a TreeSet doesn't have the ability to retrieve the key.
Set<ItemIdentifierStack> list = new TreeSet<>();
for (Entry<ItemIdentifier, List<ItemRoutingInformation>> entry : itemsOnRoute.entrySet()) {
if (entry.getValue().isEmpty()) {
continue;
}
ItemIdentifierStack currentStack = new ItemIdentifierStack(entry.getKey(), 0);
for (ItemRoutingInformation e : entry.getValue()) {
currentStack.setStackSize(currentStack.getStackSize() + e.getItem().getStackSize());
}
list.add(currentStack);
}
return list;
}
use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.
the class PipeItemsInvSysConnector method checkOneConnectedInv.
private boolean checkOneConnectedInv(@Nonnull IInventoryUtil inv, EnumFacing dir) {
boolean contentchanged = false;
if (!itemsOnRoute.isEmpty()) {
// don't check the inventory if you don't want anything
List<ItemIdentifier> items = new ArrayList<>(itemsOnRoute.keySet());
items.retainAll(inv.getItems());
Map<ItemIdentifier, Integer> amounts = null;
if (!items.isEmpty()) {
amounts = inv.getItemsAndCount();
}
for (ItemIdentifier ident : items) {
if (!amounts.containsKey(ident)) {
continue;
}
int itemAmount = amounts.get(ident);
List<ItemRoutingInformation> needs = itemsOnRoute.get(ident);
for (Iterator<ItemRoutingInformation> iterator = needs.iterator(); iterator.hasNext(); ) {
ItemRoutingInformation need = iterator.next();
if (need.getItem().getStackSize() <= itemAmount) {
if (!useEnergy(6)) {
return contentchanged;
}
ItemStack toSend = inv.getMultipleItems(ident, need.getItem().getStackSize());
if (toSend.isEmpty()) {
return contentchanged;
}
if (toSend.getCount() != need.getItem().getStackSize()) {
if (inv instanceof ITransactor) {
((ITransactor) inv).add(toSend, dir.getOpposite(), true);
} else {
container.getWorld().spawnEntity(ItemIdentifierStack.getFromStack(toSend).makeEntityItem(getWorld(), container.getX(), container.getY(), container.getZ()));
}
new UnsupportedOperationException("The extracted amount didn't match the requested one. (" + inv + ")").printStackTrace();
return contentchanged;
}
sendStack(need, dir);
// finished with this need, we sent part of a stack, lets see if anyone where needs the current item type.
iterator.remove();
contentchanged = true;
if (needs.isEmpty()) {
itemsOnRoute.remove(ident);
}
// Refresh Available Items
amounts = inv.getItemsAndCount();
if (amounts.containsKey(ident)) {
itemAmount = amounts.get(ident);
} else {
break;
}
}
}
}
}
return contentchanged;
}
Aggregations