Search in sources :

Example 26 with SinkReply

use of logisticspipes.utils.SinkReply 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;
                }
            }
        }
    }
}
Also used : IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) LinkedList(java.util.LinkedList) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) SinkReply(logisticspipes.utils.SinkReply) SpecialInventoryHandler(logisticspipes.proxy.specialinventoryhandler.SpecialInventoryHandler) ItemStack(net.minecraft.item.ItemStack)

Example 27 with SinkReply

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

the class ModuleEnchantmentSinkMK2 method registerPosition.

@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
    super.registerPosition(slot, positionInt);
    _sinkReply = new SinkReply(FixedPriority.EnchantmentItemSink, 1, true, false, 1, 0, new ChassiTargetInformation(getPositionInt()));
}
Also used : ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) SinkReply(logisticspipes.utils.SinkReply)

Example 28 with SinkReply

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

the class ModuleItemSink method registerPosition.

@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
    super.registerPosition(slot, positionInt);
    _sinkReply = new SinkReply(FixedPriority.ItemSink, 0, true, false, 1, 0, new ChassiTargetInformation(getPositionInt()));
    _sinkReplyDefault = new SinkReply(FixedPriority.DefaultRoute, 0, true, true, 1, 0, new ChassiTargetInformation(getPositionInt()));
}
Also used : ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) SinkReply(logisticspipes.utils.SinkReply)

Example 29 with SinkReply

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

the class ModuleModBasedItemSink method registerPosition.

@Override
public void registerPosition(ModulePositionType slot, int positionInt) {
    super.registerPosition(slot, positionInt);
    _sinkReply = new SinkReply(FixedPriority.ModBasedItemSink, 0, true, false, 5, 0, new ChassiTargetInformation(getPositionInt()));
}
Also used : ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) SinkReply(logisticspipes.utils.SinkReply)

Example 30 with SinkReply

use of logisticspipes.utils.SinkReply 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);
                    }
                }
            }
        }
    }
}
Also used : SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ItemStack(net.minecraft.item.ItemStack)

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