Search in sources :

Example 11 with SinkReply

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

the class ModuleElectricManager method registerPosition.

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

Example 12 with SinkReply

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

the class LogisticsManager method getBestReply.

private Triplet<Integer, SinkReply, List<IFilter>> getBestReply(ItemIdentifier stack, IRouter sourceRouter, List<ExitRoute> validDestinations, boolean excludeSource, List<Integer> jamList, Triplet<Integer, SinkReply, List<IFilter>> result, boolean allowDefault) {
    if (result == null) {
        result = new Triplet<>(null, null, null);
    }
    outer: for (ExitRoute candidateRouter : validDestinations) {
        if (excludeSource) {
            if (candidateRouter.destination.getId().equals(sourceRouter.getId())) {
                continue;
            }
        }
        if (jamList.contains(candidateRouter.destination.getSimpleID())) {
            continue;
        }
        if (!candidateRouter.containsFlag(PipeRoutingConnectionType.canRouteTo)) {
            continue;
        }
        for (IFilter filter : candidateRouter.filters) {
            if (filter.blockRouting() || (filter.isBlocked() == filter.isFilteredItem(stack))) {
                continue outer;
            }
        }
        SinkReply reply = LogisticsManager.canSink(candidateRouter.destination, sourceRouter, excludeSource, stack, result.getValue2(), false, allowDefault);
        if (reply == null) {
            continue;
        }
        if (result.getValue1() == null) {
            result.setValue1(candidateRouter.destination.getSimpleID());
            result.setValue2(reply);
            List<IFilter> list = new LinkedList<>();
            result.setValue3(list);
            continue;
        }
        if (reply.fixedPriority.ordinal() > result.getValue2().fixedPriority.ordinal()) {
            result.setValue1(candidateRouter.destination.getSimpleID());
            result.setValue2(reply);
            List<IFilter> list = new LinkedList<>();
            result.setValue3(list);
            continue;
        }
        if (reply.fixedPriority == result.getValue2().fixedPriority && reply.customPriority > result.getValue2().customPriority) {
            result.setValue1(candidateRouter.destination.getSimpleID());
            result.setValue2(reply);
            List<IFilter> list = new LinkedList<>();
            result.setValue3(list);
            continue;
        }
    }
    if (result.getValue1() != null) {
        CoreRoutedPipe pipe = SimpleServiceLocator.routerManager.getRouterUnsafe(result.getValue1(), false).getPipe();
        pipe.useEnergy(result.getValue2().energyUse);
        pipe.spawnParticle(Particles.BlueParticle, 10);
    }
    return result;
}
Also used : IFilter(logisticspipes.interfaces.routing.IFilter) SinkReply(logisticspipes.utils.SinkReply) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExitRoute(logisticspipes.routing.ExitRoute)

Example 13 with SinkReply

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

the class LogisticsManager method hasDestination.

/**
	 * Method used to check if a given stack has a destination.
	 * 
	 * @return Triplet of destinationSimpleID, sinkreply, relays; null if
	 *         nothing found
	 * @param stack
	 *            The stack to check if it has destination.
	 * @param allowDefault
	 *            Boolean, if true then a default route will be considered a
	 *            valid destination.
	 * @param sourceRouter
	 *            The UUID of the router pipe that wants to send the stack.
	 * @param excludeSource
	 *            Boolean, true means it will not consider the pipe itself as a
	 *            valid destination.
	 */
@Override
public Triplet<Integer, SinkReply, List<IFilter>> hasDestination(ItemIdentifier stack, boolean allowDefault, int sourceID, List<Integer> routerIDsToExclude) {
    IRouter sourceRouter = SimpleServiceLocator.routerManager.getRouter(sourceID);
    if (sourceRouter == null) {
        return null;
    }
    BitSet routersIndex = ServerRouter.getRoutersInterestedIn(stack);
    // get the routing table
    List<ExitRoute> validDestinations = new ArrayList<>();
    for (int i = routersIndex.nextSetBit(0); i >= 0; i = routersIndex.nextSetBit(i + 1)) {
        IRouter r = SimpleServiceLocator.routerManager.getRouterUnsafe(i, false);
        List<ExitRoute> exits = sourceRouter.getDistanceTo(r);
        if (exits != null) {
            validDestinations.addAll(exits.stream().filter(e -> e.containsFlag(PipeRoutingConnectionType.canRouteTo)).collect(Collectors.toList()));
        }
    }
    Collections.sort(validDestinations);
    Triplet<Integer, SinkReply, List<IFilter>> search = getBestReply(stack, sourceRouter, validDestinations, true, routerIDsToExclude, null, allowDefault);
    if (search.getValue2() == null) {
        return null;
    }
    if (!allowDefault && search.getValue2().isDefault) {
        return null;
    }
    return search;
}
Also used : IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) BitSet(java.util.BitSet) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExitRoute(logisticspipes.routing.ExitRoute)

Example 14 with SinkReply

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

the class ModuleExtractor method tick.

@Override
public void tick() {
    if (++currentTick < ticksToAction()) {
        return;
    }
    currentTick = 0;
    //Extract Item
    IInventory realInventory = _service.getRealInventory();
    if (realInventory == null) {
        return;
    }
    ForgeDirection extractOrientation = _sneakyDirection;
    if (extractOrientation == ForgeDirection.UNKNOWN) {
        extractOrientation = _service.inventoryOrientation().getOpposite();
    }
    IInventoryUtil targetUtil = _service.getSneakyInventory(extractOrientation, true);
    for (int i = 0; i < targetUtil.getSizeInventory(); i++) {
        ItemStack slot = targetUtil.getStackInSlot(i);
        if (slot == null) {
            continue;
        }
        ItemIdentifier slotitem = ItemIdentifier.get(slot);
        List<Integer> jamList = new LinkedList<>();
        Pair<Integer, SinkReply> reply = _service.hasDestination(slotitem, true, jamList);
        if (reply == null) {
            continue;
        }
        int itemsleft = itemsToExtract();
        while (reply != null) {
            int count = Math.min(itemsleft, slot.stackSize);
            count = Math.min(count, slotitem.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 = targetUtil.decrStackSize(i, count);
            if (stackToSend == null || stackToSend.stackSize == 0) {
                break;
            }
            count = stackToSend.stackSize;
            _service.sendStack(stackToSend, reply, itemSendMode());
            itemsleft -= count;
            if (itemsleft <= 0) {
                break;
            }
            slot = targetUtil.getStackInSlot(i);
            if (slot == null) {
                break;
            }
            jamList.add(reply.getValue1());
            reply = _service.hasDestination(ItemIdentifier.get(slot), true, jamList);
        }
        break;
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Example 15 with SinkReply

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

the class ModuleFluidSupplier method registerPosition.

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

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