use of logisticspipes.interfaces.IInventoryUtil in project LogisticsPipes by RS485.
the class ModuleProvider method getAllItems.
@Override
public void getAllItems(Map<ItemIdentifier, Integer> items, List<IFilter> filters) {
IInventoryUtil inv = _service.getPointedInventory(_extractionMode, true);
if (inv == null) {
return;
}
Map<ItemIdentifier, Integer> currentInv = inv.getItemsAndCount();
//Skip already added items from this provider, skip filtered items, Reduce what has been reserved, add.
outer: for (Entry<ItemIdentifier, Integer> currItem : currentInv.entrySet()) {
if (items.containsKey(currItem.getKey())) {
// Already provided by the previous module
continue;
}
if (!filterAllowsItem(currItem.getKey())) {
continue;
}
for (IFilter filter : filters) {
if (filter.isBlocked() == filter.isFilteredItem(currItem.getKey().getUndamaged()) || filter.blockProvider()) {
continue outer;
}
}
int remaining = currItem.getValue() - _service.getItemOrderManager().totalItemsCountInOrders(currItem.getKey());
if (remaining < 1) {
continue;
}
items.put(currItem.getKey(), remaining);
}
}
use of logisticspipes.interfaces.IInventoryUtil in project LogisticsPipes by RS485.
the class ModuleQuickSort method tick.
@Override
public void tick() {
if (--currentTick > 0) {
return;
}
if (stalled) {
currentTick = stalledDelay;
} else {
currentTick = normalDelay;
}
//Extract Item
IInventoryUtil invUtil = _service.getPointedInventory(true);
if (invUtil == null) {
return;
}
if (!_service.canUseEnergy(500)) {
stalled = true;
return;
}
if (invUtil instanceof SpecialInventoryHandler) {
Map<ItemIdentifier, Integer> items = invUtil.getItemsAndCount();
if (lastSuceededStack >= items.size()) {
lastSuceededStack = 0;
}
if (lastStackLookedAt >= items.size()) {
lastStackLookedAt = 0;
}
int lookedAt = 0;
for (Entry<ItemIdentifier, Integer> item : items.entrySet()) {
// spool to current place
lookedAt++;
if (lookedAt <= lastStackLookedAt) {
continue;
}
LinkedList<Integer> jamList = new LinkedList<>();
Pair<Integer, SinkReply> reply = _service.hasDestination(item.getKey(), false, jamList);
if (reply == null) {
if (lastStackLookedAt == lastSuceededStack) {
stalled = true;
}
lastStackLookedAt++;
return;
}
if (!_service.useEnergy(500)) {
stalled = true;
lastStackLookedAt++;
return;
}
stalled = false;
//send up to one stack
int maxItemsToSend = item.getKey().getMaxStackSize();
int availableItems = Math.min(maxItemsToSend, item.getValue());
while (reply != null) {
int count = availableItems;
if (reply.getValue2().maxNumberOfItems != 0) {
count = Math.min(count, reply.getValue2().maxNumberOfItems);
}
ItemStack stackToSend = invUtil.getMultipleItems(item.getKey(), count);
if (stackToSend == null || stackToSend.stackSize == 0) {
break;
}
availableItems -= stackToSend.stackSize;
_service.sendStack(stackToSend, reply, ItemSendMode.Fast);
_service.spawnParticle(Particles.OrangeParticle, 8);
if (availableItems <= 0) {
break;
}
jamList.add(reply.getValue1());
reply = _service.hasDestination(item.getKey(), false, jamList);
}
if (availableItems > 0) {
//if we didn't send maxItemsToSend, try next item next time
lastSuceededStack = lastStackLookedAt;
lastStackLookedAt++;
} else {
lastSuceededStack = lastStackLookedAt - 1;
if (lastSuceededStack < 0) {
lastSuceededStack = items.size() - 1;
}
}
return;
}
} else {
if ((!(invUtil instanceof SpecialInventoryHandler) && invUtil.getSizeInventory() == 0) || !_service.canUseEnergy(500)) {
stalled = true;
return;
}
if (lastSuceededStack >= invUtil.getSizeInventory()) {
lastSuceededStack = 0;
}
//incremented at the end of the previous loop.
if (lastStackLookedAt >= invUtil.getSizeInventory()) {
lastStackLookedAt = 0;
}
ItemStack slot = invUtil.getStackInSlot(lastStackLookedAt);
while (slot == null) {
lastStackLookedAt++;
if (lastStackLookedAt >= invUtil.getSizeInventory()) {
lastStackLookedAt = 0;
}
slot = invUtil.getStackInSlot(lastStackLookedAt);
if (lastStackLookedAt == lastSuceededStack) {
stalled = true;
send();
// then we have been around the list without sending, halt for now
return;
}
}
send();
// begin duplicate code
List<Integer> jamList = new LinkedList<>();
Pair<Integer, SinkReply> reply = _service.hasDestination(ItemIdentifier.get(slot), false, jamList);
if (reply == null) {
if (lastStackLookedAt == lastSuceededStack) {
stalled = true;
}
lastStackLookedAt++;
return;
}
if (!_service.useEnergy(500)) {
stalled = true;
lastStackLookedAt++;
return;
}
stalled = false;
//don't directly modify the stack in the inv
int sizePrev;
slot = slot.copy();
sizePrev = slot.stackSize;
boolean partialSend = false;
while (reply != null) {
int count = slot.stackSize;
if (reply.getValue2().maxNumberOfItems > 0) {
count = Math.min(count, reply.getValue2().maxNumberOfItems);
}
ItemStack stackToSend = slot.splitStack(count);
_service.sendStack(stackToSend, reply, ItemSendMode.Fast);
_service.spawnParticle(Particles.OrangeParticle, 8);
if (slot.stackSize == 0) {
break;
}
jamList.add(reply.getValue1());
reply = _service.hasDestination(ItemIdentifier.get(slot), false, jamList);
}
ItemStack returned = null;
int amountToExtract = sizePrev - slot.stackSize;
if (slot.stackSize > 0) {
partialSend = true;
}
returned = invUtil.decrStackSize(lastStackLookedAt, amountToExtract);
if (returned.stackSize != amountToExtract) {
throw new UnsupportedOperationException("Couldn't extract the already sended items from the inventory.");
}
lastSuceededStack = lastStackLookedAt;
// end duplicate code
lastStackLookedAt++;
if (partialSend) {
if (lastStackLookedAt >= invUtil.getSizeInventory()) {
lastStackLookedAt = 0;
}
while (lastStackLookedAt != lastSuceededStack) {
ItemStack tstack = invUtil.getStackInSlot(lastStackLookedAt);
if (tstack != null && !slot.isItemEqual(tstack)) {
break;
}
lastStackLookedAt++;
if (lastStackLookedAt >= invUtil.getSizeInventory()) {
lastStackLookedAt = 0;
}
}
}
}
}
use of logisticspipes.interfaces.IInventoryUtil in project LogisticsPipes by RS485.
the class ModuleItemSink method importFromInventory.
public void importFromInventory() {
if (_service == null) {
return;
}
IInventoryUtil inv = _service.getPointedInventory(false);
if (inv == null) {
return;
}
int count = 0;
for (ItemIdentifier item : inv.getItems()) {
_filterInventory.setInventorySlotContents(count, item.makeStack(1));
count++;
if (count >= _filterInventory.getSizeInventory()) {
break;
}
}
}
use of logisticspipes.interfaces.IInventoryUtil in project LogisticsPipes by RS485.
the class ModuleAdvancedExtractor method tick.
@Override
public void tick() {
if (++currentTick < ticksToAction()) {
return;
}
currentTick = 0;
ForgeDirection extractOrientation = _sneakyDirection;
if (extractOrientation == ForgeDirection.UNKNOWN) {
extractOrientation = _service.inventoryOrientation().getOpposite();
}
IInventoryUtil inventory = _service.getSneakyInventory(extractOrientation, true);
if (inventory == null) {
return;
}
checkExtract(inventory);
}
use of logisticspipes.interfaces.IInventoryUtil in project LogisticsPipes by RS485.
the class ModuleApiaristAnalyser method tick.
@Override
public void tick() {
if (extractMode) {
if (++currentTick < ticksToAction) {
return;
}
currentTick = 0;
IInventoryUtil inv = _service.getUnsidedInventory();
if (inv == null) {
return;
}
for (int i = 0; i < inv.getSizeInventory(); i++) {
ItemStack item = inv.getStackInSlot(i);
if (SimpleServiceLocator.forestryProxy.isBee(item)) {
if (SimpleServiceLocator.forestryProxy.isAnalysedBee(item)) {
Pair<Integer, SinkReply> reply = _service.hasDestination(ItemIdentifier.get(item), true, new ArrayList<>());
if (reply == null) {
continue;
}
if (_service.useEnergy(6)) {
_service.sendStack(inv.decrStackSize(i, 1), reply, ItemSendMode.Normal);
}
}
}
}
}
}
Aggregations