Search in sources :

Example 1 with IAdditionalTargetInformation

use of logisticspipes.interfaces.routing.IAdditionalTargetInformation in project LogisticsPipes by RS485.

the class ModuleCrafter method tick.

@Override
public void tick() {
    enabledUpdateEntity();
    if (_lostItems.isEmpty()) {
        return;
    }
    // if(true) return;
    DelayedGeneric<Pair<ItemIdentifierStack, IAdditionalTargetInformation>> lostItem = _lostItems.poll();
    int rerequested = 0;
    while (lostItem != null && rerequested < 100) {
        Pair<ItemIdentifierStack, IAdditionalTargetInformation> pair = lostItem.get();
        if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING)) {
            SinkReply reply = LogisticsManager.canSink(getRouter(), null, true, pair.getValue1().getItem(), null, true, true);
            if (reply == null || reply.maxNumberOfItems < 1) {
                _lostItems.add(new DelayedGeneric<>(pair, 9000 + (int) (Math.random() * 2000)));
                lostItem = _lostItems.poll();
                continue;
            }
        }
        int received = RequestTree.requestPartial(pair.getValue1(), (CoreRoutedPipe) _service, pair.getValue2());
        rerequested++;
        if (received < pair.getValue1().getStackSize()) {
            pair.getValue1().setStackSize(pair.getValue1().getStackSize() - received);
            _lostItems.add(new DelayedGeneric<>(pair, 4500 + (int) (Math.random() * 1000)));
        }
        lostItem = _lostItems.poll();
    }
}
Also used : SinkReply(logisticspipes.utils.SinkReply) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Pair(logisticspipes.utils.tuples.Pair) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation)

Example 2 with IAdditionalTargetInformation

use of logisticspipes.interfaces.routing.IAdditionalTargetInformation in project LogisticsPipes by RS485.

the class ModuleActiveSupplier method createPatternRequest.

private void createPatternRequest(IInventoryUtil invUtil) {
    _service.getDebug().log("Supplier: Start calculating pattern request");
    setRequestFailed(false);
    for (int i = 0; i < 9; i++) {
        ItemIdentifierStack needed = dummyInventory.getIDStackInSlot(i);
        if (needed == null) {
            continue;
        }
        if (invUtil.getSizeInventory() <= slotArray[i]) {
            continue;
        }
        ItemStack stack = invUtil.getStackInSlot(slotArray[i]);
        ItemIdentifierStack have = null;
        if (stack != null) {
            have = ItemIdentifierStack.getFromStack(stack);
        }
        int haveCount = 0;
        if (have != null) {
            if (!have.getItem().equals(needed.getItem())) {
                _service.getDebug().log("Supplier: Slot for " + i + ", " + needed + " already taken by " + have);
                setRequestFailed(true);
                continue;
            }
            haveCount = have.getStackSize();
        }
        if ((_patternMode == PatternMode.Bulk50 && haveCount > needed.getStackSize() / 2) || (_patternMode == PatternMode.Bulk100 && haveCount >= needed.getStackSize())) {
            continue;
        }
        Integer requestedCount = _requestedItems.get(needed.getItem());
        if (requestedCount != null) {
            haveCount += requestedCount;
        }
        int neededCount = needed.getStackSize() - haveCount;
        if (neededCount < 1) {
            continue;
        }
        ItemIdentifierStack toRequest = new ItemIdentifierStack(needed.getItem(), neededCount);
        _service.getDebug().log("Supplier: Missing for slot " + i + ": " + toRequest);
        if (!_service.useEnergy(10)) {
            break;
        }
        boolean success = false;
        IAdditionalTargetInformation targetInformation = new PatternSupplierTargetInformation(slotArray[i], needed.getStackSize());
        if (_patternMode != PatternMode.Full) {
            _service.getDebug().log("Supplier: Requesting partial: " + toRequest);
            neededCount = RequestTree.requestPartial(toRequest, this, targetInformation);
            _service.getDebug().log("Supplier: Requested: " + toRequest.getItem().makeStack(neededCount));
            if (neededCount > 0) {
                success = true;
            }
        } else {
            _service.getDebug().log("Supplier: Requesting: " + toRequest);
            success = RequestTree.request(toRequest, this, null, targetInformation);
            if (success) {
                _service.getDebug().log("Supplier: Request success");
            } else {
                _service.getDebug().log("Supplier: Request failed");
            }
        }
        if (success) {
            Integer currentRequest = _requestedItems.get(toRequest.getItem());
            if (currentRequest == null) {
                _requestedItems.put(toRequest.getItem(), neededCount);
            } else {
                _requestedItems.put(toRequest.getItem(), currentRequest + neededCount);
            }
        } else {
            setRequestFailed(true);
        }
    }
}
Also used : ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemStack(net.minecraft.item.ItemStack) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation)

Example 3 with IAdditionalTargetInformation

use of logisticspipes.interfaces.routing.IAdditionalTargetInformation in project LogisticsPipes by RS485.

the class ModuleActiveSupplier method createSupplyRequest.

private void createSupplyRequest(IInventoryUtil invUtil) {
    _service.getDebug().log("Supplier: Start calculating supply request");
    //How many do I want?
    HashMap<ItemIdentifier, Integer> needed = new HashMap<>(dummyInventory.getItemsAndCount());
    _service.getDebug().log("Supplier: Needed: " + needed);
    //How many do I have?
    Map<ItemIdentifier, Integer> have = invUtil.getItemsAndCount();
    _service.getDebug().log("Supplier: Have:   " + have);
    //How many do I have?
    HashMap<ItemIdentifier, Integer> haveUndamaged = new HashMap<>();
    for (Entry<ItemIdentifier, Integer> item : have.entrySet()) {
        Integer n = haveUndamaged.get(item.getKey().getUndamaged());
        if (n == null) {
            haveUndamaged.put(item.getKey().getUndamaged(), item.getValue());
        } else {
            haveUndamaged.put(item.getKey().getUndamaged(), item.getValue() + n);
        }
    }
    //Reduce what I have and what have been requested already
    for (Entry<ItemIdentifier, Integer> item : needed.entrySet()) {
        Integer haveCount = haveUndamaged.get(item.getKey().getUndamaged());
        if (haveCount == null) {
            haveCount = 0;
        }
        int spaceAvailable = invUtil.roomForItem(item.getKey());
        if (_requestMode == SupplyMode.Infinite) {
            Integer requestedCount = _requestedItems.get(item.getKey());
            if (requestedCount != null) {
                spaceAvailable -= requestedCount;
            }
            item.setValue(Math.min(item.getKey().getMaxStackSize(), spaceAvailable));
            continue;
        }
        if (spaceAvailable == 0 || (_requestMode == SupplyMode.Bulk50 && haveCount > item.getValue() / 2) || (_requestMode == SupplyMode.Bulk100 && haveCount >= item.getValue())) {
            item.setValue(0);
            continue;
        }
        if (haveCount > 0) {
            item.setValue(item.getValue() - haveCount);
            // so that 1 damaged item can't satisfy a request for 2 other damage values.
            haveUndamaged.put(item.getKey().getUndamaged(), haveCount - item.getValue());
        }
        Integer requestedCount = _requestedItems.get(item.getKey());
        if (requestedCount != null) {
            item.setValue(item.getValue() - requestedCount);
        }
    }
    _service.getDebug().log("Supplier: Missing:   " + needed);
    setRequestFailed(false);
    //Make request
    for (Entry<ItemIdentifier, Integer> need : needed.entrySet()) {
        Integer amountRequested = need.getValue();
        if (amountRequested == null || amountRequested < 1) {
            continue;
        }
        int neededCount = amountRequested;
        if (!_service.useEnergy(10)) {
            break;
        }
        boolean success = false;
        IAdditionalTargetInformation targetInformation = new SupplierTargetInformation();
        if (_requestMode != SupplyMode.Full) {
            _service.getDebug().log("Supplier: Requesting partial: " + need.getKey().makeStack(neededCount));
            neededCount = RequestTree.requestPartial(need.getKey().makeStack(neededCount), this, targetInformation);
            _service.getDebug().log("Supplier: Requested: " + need.getKey().makeStack(neededCount));
            if (neededCount > 0) {
                success = true;
            }
        } else {
            _service.getDebug().log("Supplier: Requesting: " + need.getKey().makeStack(neededCount));
            success = RequestTree.request(need.getKey().makeStack(neededCount), this, null, targetInformation);
            if (success) {
                _service.getDebug().log("Supplier: Request success");
            } else {
                _service.getDebug().log("Supplier: Request failed");
            }
        }
        if (success) {
            Integer currentRequest = _requestedItems.get(need.getKey());
            if (currentRequest == null) {
                _requestedItems.put(need.getKey(), neededCount);
                _service.getDebug().log("Supplier: Inserting Requested Items: " + neededCount);
            } else {
                _requestedItems.put(need.getKey(), currentRequest + neededCount);
                _service.getDebug().log("Supplier: Raising Requested Items from: " + currentRequest + " to: " + currentRequest + neededCount);
            }
        } else {
            setRequestFailed(true);
        }
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) HashMap(java.util.HashMap) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation)

Example 4 with IAdditionalTargetInformation

use of logisticspipes.interfaces.routing.IAdditionalTargetInformation 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)

Aggregations

IAdditionalTargetInformation (logisticspipes.interfaces.routing.IAdditionalTargetInformation)4 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)3 HashMap (java.util.HashMap)2 SinkReply (logisticspipes.utils.SinkReply)2 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)2 Pair (logisticspipes.utils.tuples.Pair)2 ItemStack (net.minecraft.item.ItemStack)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Collectors (java.util.stream.Collectors)1 LogisticsPipes (logisticspipes.LogisticsPipes)1 HUDProvider (logisticspipes.gui.hud.HUDProvider)1 IChangeListener (logisticspipes.interfaces.IChangeListener)1