Search in sources :

Example 16 with SinkReply

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

the class ModuleApiaristTerminus method registerPosition.

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

Example 17 with SinkReply

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

the class ModuleTerminus method registerPosition.

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

Example 18 with SinkReply

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

the class ModuleThaumicAspectSink method registerPosition.

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

Example 19 with SinkReply

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

the class PipeItemsProviderLogistics method sendStack.

private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
    ItemIdentifier item = stack.getItem();
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
    //@formatter:off
    Iterator<Pair<IInventoryUtil, ForgeDirection>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>(getAdaptedInventoryUtil(adjacent), adjacent.direction)).iterator();
    while (iterator.hasNext()) {
        Pair<IInventoryUtil, ForgeDirection> next = iterator.next();
        int available = next.getValue1().itemCount(item);
        if (available == 0) {
            continue;
        }
        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) {
            _orderManager.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) {
                    _orderManager.deferSend();
                    return 0;
                }
                defersend = true;
            }
        }
        if (!canUseEnergy(wanted * neededEnergy())) {
            return -1;
        }
        ItemStack removed = next.getValue1().getMultipleItems(item, wanted);
        if (removed == null || removed.stackSize == 0) {
            continue;
        }
        int sent = removed.stackSize;
        useEnergy(sent * neededEnergy());
        IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(removed);
        routedItem.setDestination(destination);
        routedItem.setTransportMode(TransportMode.Active);
        routedItem.setAdditionalTargetInformation(info);
        super.queueRoutedItem(routedItem, next.getValue2());
        _orderManager.sendSuccessfull(sent, defersend, routedItem);
        return sent;
    }
    _orderManager.sendFailed();
    return 0;
}
Also used : IRouter(logisticspipes.routing.IRouter) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) LogisticsPipes(logisticspipes.LogisticsPipes) ProviderPipeInclude(logisticspipes.network.packets.modules.ProviderPipeInclude) Particles(logisticspipes.pipefxhandlers.Particles) ChestContent(logisticspipes.network.packets.hud.ChestContent) MainProxy(logisticspipes.proxy.MainProxy) IHeadUpDisplayRenderer(logisticspipes.interfaces.IHeadUpDisplayRenderer) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) HUDStartWatchingPacket(logisticspipes.network.packets.hud.HUDStartWatchingPacket) SinkReply(logisticspipes.utils.SinkReply) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) Map(java.util.Map) ModuleProvider(logisticspipes.modules.ModuleProvider) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChangeListener(logisticspipes.interfaces.IChangeListener) HUDStopWatchingPacket(logisticspipes.network.packets.hud.HUDStopWatchingPacket) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsManager(logisticspipes.logistics.LogisticsManager) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) Set(java.util.Set) PacketHandler(logisticspipes.network.PacketHandler) RequestTreeNode(logisticspipes.request.RequestTreeNode) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IChestContentReceiver(logisticspipes.interfaces.IChestContentReceiver) IFilter(logisticspipes.interfaces.routing.IFilter) OrdererManagerContent(logisticspipes.network.packets.orderer.OrdererManagerContent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) GuiIDs(logisticspipes.network.GuiIDs) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ItemResource(logisticspipes.request.resources.ItemResource) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) HashMap(java.util.HashMap) HUDProvider(logisticspipes.gui.hud.HUDProvider) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) ExtractionMode(logisticspipes.logisticspipes.ExtractionMode) LogisticsItemOrderManager(logisticspipes.routing.order.LogisticsItemOrderManager) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) LogisticsPromise(logisticspipes.routing.LogisticsPromise) TextureType(logisticspipes.textures.Textures.TextureType) RequestTree(logisticspipes.request.RequestTree) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) IResource(logisticspipes.request.resources.IResource) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ProviderPipeMode(logisticspipes.network.packets.modules.ProviderPipeMode) IInventory(net.minecraft.inventory.IInventory) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IOrderManagerContentReceiver(logisticspipes.interfaces.IOrderManagerContentReceiver) IInventory(net.minecraft.inventory.IInventory) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ItemStack(net.minecraft.item.ItemStack) Pair(logisticspipes.utils.tuples.Pair)

Example 20 with SinkReply

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

the class LogisticsManager method assignDestinationFor.

/**
	 * Will assign a destination for a IRoutedItem based on a best sink reply
	 * recieved from other pipes.
	 * 
	 * @param item
	 *            The item that needs to be routed.
	 * @param sourceRouterID
	 *            The SimpleID of the pipe that is sending the item. (the
	 *            routedItem will cache the UUID, and that the SimpleID belongs
	 *            to the UUID will be checked when appropriate)
	 * @param excludeSource
	 *            Boolean, true means that it wont set the source as the
	 *            destination.
	 * @return IRoutedItem with a newly assigned destination
	 */
@Override
public IRoutedItem assignDestinationFor(IRoutedItem item, int sourceRouterID, boolean excludeSource) {
    //Assert: only called server side.
    //If we for some reason can't get the router we can't do anything either
    IRouter sourceRouter = SimpleServiceLocator.routerManager.getRouterUnsafe(sourceRouterID, false);
    if (sourceRouter == null) {
        return item;
    }
    //Wipe current destination
    item.clearDestination();
    BitSet routersIndex = ServerRouter.getRoutersInterestedIn(item.getItemIdentifierStack().getItem());
    // 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);
    if (item.getItemIdentifierStack() != null && item.getItemIdentifierStack().makeNormalStack().getItem() instanceof LogisticsFluidContainer) {
        Pair<Integer, Integer> bestReply = SimpleServiceLocator.logisticsFluidManager.getBestReply(SimpleServiceLocator.logisticsFluidManager.getFluidFromContainer(item.getItemIdentifierStack()), sourceRouter, item.getJamList());
        if (bestReply.getValue1() != null && bestReply.getValue1() != 0) {
            item.setDestination(bestReply.getValue1());
        }
        return item;
    } else {
        Triplet<Integer, SinkReply, List<IFilter>> bestReply = getBestReply(item.getItemIdentifierStack().getItem(), sourceRouter, validDestinations, excludeSource, item.getJamList(), null, true);
        if (bestReply.getValue1() != null && bestReply.getValue1() != 0) {
            item.setDestination(bestReply.getValue1());
            if (bestReply.getValue2().isPassive) {
                if (bestReply.getValue2().isDefault) {
                    item.setTransportMode(TransportMode.Default);
                } else {
                    item.setTransportMode(TransportMode.Passive);
                }
            } else {
                item.setTransportMode(TransportMode.Active);
            }
            item.setAdditionalTargetInformation(bestReply.getValue2().addInfo);
        }
        return item;
    }
}
Also used : LogisticsFluidContainer(logisticspipes.items.LogisticsFluidContainer) 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)

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