Search in sources :

Example 21 with SinkReply

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

the class LogisticsManager method canSink.

public static SinkReply canSink(IRouter destination, IRouter sourceRouter, boolean excludeSource, ItemIdentifier stack, SinkReply result, boolean activeRequest, boolean allowDefault) {
    SinkReply reply = null;
    LogisticsModule module = destination.getLogisticsModule();
    CoreRoutedPipe crp = destination.getPipe();
    if (module == null) {
        return null;
    }
    if (!(module.recievePassive() || activeRequest)) {
        return null;
    }
    if (crp == null || !crp.isEnabled()) {
        return null;
    }
    if (excludeSource && sourceRouter != null) {
        if (destination.getPipe().sharesInterestWith(sourceRouter.getPipe())) {
            return null;
        }
    }
    if (result == null) {
        reply = module.sinksItem(stack, -1, 0, allowDefault, true);
    } else {
        reply = module.sinksItem(stack, result.fixedPriority.ordinal(), result.customPriority, allowDefault, true);
    }
    if (result != null && result.maxNumberOfItems < 0) {
        return null;
    }
    return reply;
}
Also used : SinkReply(logisticspipes.utils.SinkReply) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe)

Example 22 with SinkReply

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

the class ModuleCrafter 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()));
}
Also used : ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) SinkReply(logisticspipes.utils.SinkReply)

Example 23 with SinkReply

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

the class ModulePassiveSupplier method sinksItem.

@Override
public SinkReply sinksItem(ItemIdentifier item, int bestPriority, int bestCustomPriority, boolean allowDefault, boolean includeInTransit) {
    if (bestPriority > _sinkReply.fixedPriority.ordinal() || (bestPriority == _sinkReply.fixedPriority.ordinal() && bestCustomPriority >= _sinkReply.customPriority)) {
        return null;
    }
    IInventoryUtil targetUtil = _service.getSneakyInventory(false, slot, positionInt);
    if (targetUtil == null) {
        return null;
    }
    if (!_filterInventory.containsItem(item)) {
        return null;
    }
    int targetCount = _filterInventory.itemCount(item);
    int haveCount = targetUtil.itemCount(item);
    if (targetCount <= haveCount) {
        return null;
    }
    if (_service.canUseEnergy(2)) {
        return new SinkReply(_sinkReply, targetCount - haveCount);
    }
    return null;
}
Also used : SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil)

Example 24 with SinkReply

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

the class ModulePolymorphicItemSink method registerPosition.

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

Example 25 with SinkReply

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

the class ModuleProvider method sendStack.

// returns -1 on permanently failed, don't try another stack this tick
// returns 0 on "unable to do this delivery"
private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
    ItemIdentifier item = stack.getItem();
    IInventoryUtil inv = _service.getPointedInventory(_extractionMode, true);
    if (inv == null) {
        _service.getItemOrderManager().sendFailed();
        return 0;
    }
    int available = inv.itemCount(item);
    if (available == 0) {
        _service.getItemOrderManager().sendFailed();
        return 0;
    }
    int wanted = Math.min(available, stack.getStackSize());
    wanted = Math.min(wanted, maxCount);
    wanted = Math.min(wanted, item.getMaxStackSize());
    IRouter dRtr = SimpleServiceLocator.routerManager.getRouterUnsafe(destination, false);
    if (dRtr == null) {
        _service.getItemOrderManager().sendFailed();
        return 0;
    }
    SinkReply reply = LogisticsManager.canSink(dRtr, null, true, stack.getItem(), null, true, false);
    boolean defersend = false;
    if (reply != null) {
        // some pipes are not aware of the space in the adjacent inventory, so they return null
        if (reply.maxNumberOfItems < wanted) {
            wanted = reply.maxNumberOfItems;
            if (wanted <= 0) {
                _service.getItemOrderManager().deferSend();
                return 0;
            }
            defersend = true;
        }
    }
    if (!_service.canUseEnergy(wanted * neededEnergy())) {
        return -1;
    }
    ItemStack removed = inv.getMultipleItems(item, wanted);
    if (removed == null || removed.stackSize == 0) {
        _service.getItemOrderManager().sendFailed();
        return 0;
    }
    int sent = removed.stackSize;
    _service.useEnergy(sent * neededEnergy());
    IRoutedItem sendedItem = _service.sendStack(removed, destination, itemSendMode(), info);
    _service.getItemOrderManager().sendSuccessfull(sent, defersend, sendedItem);
    return sent;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) 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