Search in sources :

Example 1 with SinkReply

use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.

the class ModuleCrafter method tick.

@Override
public void tick() {
    enabledUpdateEntity();
    if (_lostItems.isEmpty()) {
        return;
    }
    // if(true) return;
    DelayedGeneric<Pair<ItemIdentifierStack, IAdditionalTargetInformation>> lostItem = _lostItems.poll();
    int rerequested = 0;
    while (lostItem != null && rerequested < 100) {
        Pair<ItemIdentifierStack, IAdditionalTargetInformation> pair = lostItem.get();
        if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
            SinkReply reply = LogisticsManager.canSink(getRouter(), null, true, pair.getValue1().getItem(), null, true, true);
            if (reply == null || reply.maxNumberOfItems < 1) {
                _lostItems.add(new DelayedGeneric<>(pair, 9000 + (int) (Math.random() * 2000)));
                lostItem = _lostItems.poll();
                continue;
            }
        }
        int received = RequestTree.requestPartial(pair.getValue1(), (CoreRoutedPipe) _service, pair.getValue2());
        rerequested++;
        if (received < pair.getValue1().getStackSize()) {
            pair.getValue1().setStackSize(pair.getValue1().getStackSize() - received);
            _lostItems.add(new DelayedGeneric<>(pair, 4500 + (int) (Math.random() * 1000)));
        }
        lostItem = _lostItems.poll();
    }
}
Also used : SinkReply(logisticspipes.utils.SinkReply) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Pair(logisticspipes.utils.tuples.Pair) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation)

Example 2 with SinkReply

use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.

the class ModuleCrafter method cacheAreAllOrderesToBuffer.

public void cacheAreAllOrderesToBuffer() {
    boolean result = true;
    for (LogisticsItemOrder order : _service.getItemOrderManager()) {
        if (order.getDestination() instanceof IItemSpaceControl) {
            SinkReply reply = LogisticsManager.canSink(order.getDestination().getRouter(), null, true, order.getResource().getItem(), null, true, false);
            if (reply != null && reply.bufferMode == BufferMode.NONE && reply.maxNumberOfItems >= 1) {
                result = false;
                break;
            }
        } else {
            // No Space control
            result = false;
            break;
        }
    }
    cachedAreAllOrderesToBuffer = result;
}
Also used : IItemSpaceControl(logisticspipes.interfaces.routing.IItemSpaceControl) SinkReply(logisticspipes.utils.SinkReply) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder)

Example 3 with SinkReply

use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.

the class ChassiTransportLayer method stillWantItem.

@Override
public boolean stillWantItem(IRoutedItem item) {
    LogisticsModule module = _chassiPipe.getLogisticsModule();
    if (module == null) {
        _chassiPipe.notifyOfItemArival(item.getInfo());
        return false;
    }
    if (!_chassiPipe.isEnabled()) {
        _chassiPipe.notifyOfItemArival(item.getInfo());
        return false;
    }
    SinkReply reply = module.sinksItem(item.getItemIdentifierStack().getItem(), -1, 0, true, false);
    if (reply == null || reply.maxNumberOfItems < 0) {
        _chassiPipe.notifyOfItemArival(item.getInfo());
        return false;
    }
    if (reply.maxNumberOfItems > 0 && item.getItemIdentifierStack().getStackSize() > reply.maxNumberOfItems) {
        ForgeDirection o = _chassiPipe.getPointedOrientation();
        if (o == null || o == ForgeDirection.UNKNOWN) {
            o = ForgeDirection.UP;
        }
        item.split(reply.maxNumberOfItems, o);
    }
    return true;
}
Also used : SinkReply(logisticspipes.utils.SinkReply) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) ForgeDirection(net.minecraftforge.common.util.ForgeDirection)

Example 4 with SinkReply

use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.

the class ChassiModule method sinksItem.

@Override
public SinkReply sinksItem(ItemIdentifier item, int bestPriority, int bestCustomPriority, boolean allowDefault, boolean includeInTransit) {
    SinkReply bestresult = null;
    for (LogisticsModule module : modules) {
        if (module != null) {
            SinkReply result = module.sinksItem(item, bestPriority, bestCustomPriority, allowDefault, includeInTransit);
            if (result != null && result.maxNumberOfItems >= 0) {
                bestresult = result;
                bestPriority = result.fixedPriority.ordinal();
                bestCustomPriority = result.customPriority;
            }
        }
    }
    if (bestresult == null) {
        return null;
    }
    //Always deny items when we can't put the item anywhere
    IInventoryUtil invUtil = parentChassis.getSneakyInventory(false, ModulePositionType.SLOT, ((ChassiTargetInformation) bestresult.addInfo).getModuleSlot());
    if (invUtil == null) {
        return null;
    }
    int roomForItem = invUtil.roomForItem(item);
    if (roomForItem < 1) {
        return null;
    }
    if (includeInTransit) {
        int onRoute = parentChassis.countOnRoute(item);
        roomForItem = invUtil.roomForItem(item, onRoute + item.getMaxStackSize());
        roomForItem -= onRoute;
        if (roomForItem < 1) {
            return null;
        }
    }
    if (bestresult.maxNumberOfItems == 0) {
        return new SinkReply(bestresult, roomForItem);
    }
    return new SinkReply(bestresult, Math.min(bestresult.maxNumberOfItems, roomForItem));
}
Also used : SinkReply(logisticspipes.utils.SinkReply) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil)

Example 5 with SinkReply

use of logisticspipes.utils.SinkReply in project LogisticsPipes by RS485.

the class ModuleAdvancedExtractor method checkExtract.

private void checkExtract(IInventoryUtil invUtil) {
    Map<ItemIdentifier, Integer> items = invUtil.getItemsAndCount();
    for (Entry<ItemIdentifier, Integer> item : items.entrySet()) {
        if (!CanExtract(item.getKey().makeNormalStack(item.getValue()))) {
            continue;
        }
        List<Integer> jamList = new LinkedList<>();
        Pair<Integer, SinkReply> reply = _service.hasDestination(item.getKey(), true, jamList);
        if (reply == null) {
            continue;
        }
        int itemsleft = itemsToExtract();
        while (reply != null) {
            int count = Math.min(itemsleft, item.getValue());
            count = Math.min(count, item.getKey().getMaxStackSize());
            if (reply.getValue2().maxNumberOfItems > 0) {
                count = Math.min(count, reply.getValue2().maxNumberOfItems);
            }
            while (!_service.useEnergy(neededEnergy() * count) && count > 0) {
                _service.spawnParticle(Particles.OrangeParticle, 2);
                count--;
            }
            if (count <= 0) {
                break;
            }
            ItemStack stackToSend = invUtil.getMultipleItems(item.getKey(), count);
            if (stackToSend == null || stackToSend.stackSize == 0) {
                break;
            }
            count = stackToSend.stackSize;
            _service.sendStack(stackToSend, reply, itemSendMode());
            itemsleft -= count;
            if (itemsleft <= 0) {
                break;
            }
            jamList.add(reply.getValue1());
            reply = _service.hasDestination(item.getKey(), true, jamList);
        }
        return;
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) SinkReply(logisticspipes.utils.SinkReply) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Aggregations

SinkReply (logisticspipes.utils.SinkReply)36 ChassiTargetInformation (logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation)17 ItemStack (net.minecraft.item.ItemStack)10 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)9 LinkedList (java.util.LinkedList)7 List (java.util.List)6 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)6 ArrayList (java.util.ArrayList)5 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)4 IRouter (logisticspipes.routing.IRouter)4 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)3 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)3 ExitRoute (logisticspipes.routing.ExitRoute)3 LogisticsItemOrder (logisticspipes.routing.order.LogisticsItemOrder)3 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)3 IInventory (net.minecraft.inventory.IInventory)3 BitSet (java.util.BitSet)2 IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)2 IFilter (logisticspipes.interfaces.routing.IFilter)2