Search in sources :

Example 6 with SinkReply

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

the class ModuleOreDictItemSink method registerPosition.

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

Example 7 with SinkReply

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

the class ModulePassiveSupplier method registerPosition.

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

Example 8 with SinkReply

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

the class ModuleCrafter method enabledUpdateEntity.

public void enabledUpdateEntity() {
    if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
        if (_service.isNthTick(6)) {
            cacheAreAllOrderesToBuffer();
        }
        if (_service.getItemOrderManager().isFirstOrderWatched()) {
            TileEntity tile = lastAccessedCrafter.get();
            if (tile != null) {
                _service.getItemOrderManager().setMachineProgress(SimpleServiceLocator.machineProgressProvider.getProgressForTile(tile));
            } else {
                _service.getItemOrderManager().setMachineProgress((byte) 0);
            }
        }
    } else {
        cachedAreAllOrderesToBuffer = false;
    }
    if (!_service.isNthTick(6)) {
        return;
    }
    waitingForCraft = false;
    if ((!_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
        if (getUpgradeManager().getCrafterCleanup() > 0) {
            List<AdjacentTileEntity> crafters = locateCrafters();
            ItemStack extracted = null;
            for (AdjacentTileEntity adjacentCrafter : crafters) {
                extracted = extractFiltered(adjacentCrafter, _cleanupInventory, cleanupModeIsExclude, getUpgradeManager().getCrafterCleanup() * 3);
                if (extracted != null && extracted.stackSize > 0) {
                    break;
                }
            }
            if (extracted != null && extracted.stackSize > 0) {
                _service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(extracted), ForgeDirection.UP);
                _service.getCacheHolder().trigger(CacheTypes.Inventory);
            }
        }
        return;
    }
    waitingForCraft = true;
    List<AdjacentTileEntity> adjacentCrafters = locateCrafters();
    if (adjacentCrafters.size() < 1) {
        if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
            _service.getItemOrderManager().sendFailed();
        }
        return;
    }
    List<ItemIdentifierStack> wanteditem = getCraftedItems();
    if (wanteditem == null || wanteditem.isEmpty()) {
        return;
    }
    _service.spawnParticle(Particles.VioletParticle, 2);
    int itemsleft = itemsToExtract();
    int stacksleft = stacksToExtract();
    while (itemsleft > 0 && stacksleft > 0 && (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
        // fetch but not remove.
        LogisticsItemOrder nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
        int maxtosend = Math.min(itemsleft, nextOrder.getResource().stack.getStackSize());
        maxtosend = Math.min(nextOrder.getResource().getItem().getMaxStackSize(), maxtosend);
        // retrieve the new crafted items
        ItemStack extracted = null;
        AdjacentTileEntity adjacent = null;
        for (AdjacentTileEntity adjacentCrafter : adjacentCrafters) {
            adjacent = adjacentCrafter;
            extracted = extract(adjacent, nextOrder.getResource(), maxtosend);
            if (extracted != null && extracted.stackSize > 0) {
                break;
            }
        }
        if (extracted == null || extracted.stackSize == 0) {
            _service.getItemOrderManager().deferSend();
            break;
        }
        _service.getCacheHolder().trigger(CacheTypes.Inventory);
        lastAccessedCrafter = new WeakReference<>(adjacent.tileEntity);
        // send the new crafted items to the destination
        ItemIdentifier extractedID = ItemIdentifier.get(extracted);
        while (extracted.stackSize > 0) {
            if (!doesExtractionMatch(nextOrder, extractedID)) {
                LogisticsItemOrder startOrder = nextOrder;
                if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                    do {
                        _service.getItemOrderManager().deferSend();
                        nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
                    } while (!doesExtractionMatch(nextOrder, extractedID) && startOrder != nextOrder);
                }
                if (startOrder == nextOrder) {
                    int numtosend = Math.min(extracted.stackSize, extractedID.getMaxStackSize());
                    if (numtosend == 0) {
                        break;
                    }
                    stacksleft -= 1;
                    itemsleft -= numtosend;
                    ItemStack stackToSend = extracted.splitStack(numtosend);
                    //Route the unhandled item
                    _service.sendStack(stackToSend, -1, ItemSendMode.Normal, null);
                    continue;
                }
            }
            int numtosend = Math.min(extracted.stackSize, extractedID.getMaxStackSize());
            numtosend = Math.min(numtosend, nextOrder.getResource().stack.getStackSize());
            if (numtosend == 0) {
                break;
            }
            stacksleft -= 1;
            itemsleft -= numtosend;
            ItemStack stackToSend = extracted.splitStack(numtosend);
            if (nextOrder.getDestination() != null) {
                SinkReply reply = LogisticsManager.canSink(nextOrder.getDestination().getRouter(), null, true, ItemIdentifier.get(stackToSend), null, true, false);
                boolean defersend = false;
                if (reply == null || reply.bufferMode != BufferMode.NONE || reply.maxNumberOfItems < 1) {
                    defersend = true;
                }
                IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
                item.setDestination(nextOrder.getDestination().getRouter().getSimpleID());
                item.setTransportMode(TransportMode.Active);
                item.setAdditionalTargetInformation(nextOrder.getInformation());
                _service.queueRoutedItem(item, adjacent.direction);
                _service.getItemOrderManager().sendSuccessfull(stackToSend.stackSize, defersend, item);
            } else {
                _service.sendStack(stackToSend, -1, ItemSendMode.Normal, nextOrder.getInformation());
                _service.getItemOrderManager().sendSuccessfull(stackToSend.stackSize, false, null);
            }
            if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                // fetch but not remove.
                nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
            }
        }
    }
}
Also used : LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) SinkReply(logisticspipes.utils.SinkReply) ItemStack(net.minecraft.item.ItemStack) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 9 with SinkReply

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

the class ModuleCreativeTabBasedItemSink 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 10 with SinkReply

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

the class ModuleElectricBuffer method tick.

@Override
public void tick() {
    if (++currentTickCount < ticksToAction) {
        return;
    }
    currentTickCount = 0;
    IInventoryUtil inv = _service.getPointedInventory(true);
    if (inv == null) {
        return;
    }
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.getStackInSlot(i);
        if (stack == null) {
            continue;
        }
        if (SimpleServiceLocator.IC2Proxy.isElectricItem(stack)) {
            Triplet<Integer, SinkReply, List<IFilter>> reply = SimpleServiceLocator.logisticsManager.hasDestinationWithMinPriority(ItemIdentifier.get(stack), _service.getSourceID(), true, FixedPriority.ElectricManager);
            if (reply == null) {
                continue;
            }
            _service.spawnParticle(Particles.OrangeParticle, 2);
            _service.sendStack(inv.decrStackSize(i, 1), reply, ItemSendMode.Normal);
            return;
        }
        continue;
    }
}
Also used : SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) List(java.util.List) 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