Search in sources :

Example 1 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class PipeItemsInvSysConnector method checkOneConnectedInv.

private boolean checkOneConnectedInv(IInventoryUtil inv, ForgeDirection dir) {
    boolean contentchanged = false;
    if (!itemsOnRoute.isEmpty()) {
        // don't check the inventory if you don't want anything
        List<ItemIdentifier> items = new ArrayList<>(itemsOnRoute.keySet());
        items.retainAll(inv.getItems());
        Map<ItemIdentifier, Integer> amounts = null;
        if (!items.isEmpty()) {
            amounts = inv.getItemsAndCount();
        }
        for (ItemIdentifier ident : items) {
            if (!amounts.containsKey(ident)) {
                continue;
            }
            int itemAmount = amounts.get(ident);
            List<ItemRoutingInformation> needs = itemsOnRoute.get(ident);
            for (Iterator<ItemRoutingInformation> iterator = needs.iterator(); iterator.hasNext(); ) {
                ItemRoutingInformation need = iterator.next();
                if (need.getItem().getStackSize() <= itemAmount) {
                    if (!useEnergy(6)) {
                        return contentchanged;
                    }
                    ItemStack toSend = inv.getMultipleItems(ident, need.getItem().getStackSize());
                    if (toSend == null) {
                        return contentchanged;
                    }
                    if (toSend.stackSize != need.getItem().getStackSize()) {
                        if (inv instanceof ITransactor) {
                            ((ITransactor) inv).add(toSend, dir.getOpposite(), true);
                        } else {
                            container.getWorldObj().spawnEntityInWorld(ItemIdentifierStack.getFromStack(toSend).makeEntityItem(getWorld(), container.xCoord, container.yCoord, container.zCoord));
                        }
                        new UnsupportedOperationException("The extracted amount didn't match the requested one. (" + inv + ")").printStackTrace();
                        return contentchanged;
                    }
                    sendStack(need, dir);
                    // finished with this need, we sent part of a stack, lets see if anyone where needs the current item type.
                    iterator.remove();
                    contentchanged = true;
                    if (needs.isEmpty()) {
                        itemsOnRoute.remove(ident);
                    }
                    //Refresh Available Items
                    amounts = inv.getItemsAndCount();
                    if (amounts.containsKey(ident)) {
                        itemAmount = amounts.get(ident);
                    } else {
                        itemAmount = 0;
                        break;
                    }
                }
            }
        }
    }
    return contentchanged;
}
Also used : ArrayList(java.util.ArrayList) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) ItemStack(net.minecraft.item.ItemStack) ITransactor(logisticspipes.utils.transactor.ITransactor)

Example 2 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class PipeTransportLogistics method resolveRoutedDestination.

public RoutingResult resolveRoutedDestination(LPTravelingItemServer data) {
    EnumFacing blocked = null;
    if (data.getDestinationUUID() == null) {
        ItemIdentifierStack stack = data.getItemIdentifierStack();
        ItemRoutingInformation result = getRoutedPipe().getQueuedForItemStack(stack);
        if (result != null) {
            data.setInformation(result);
            data.getInfo().setItem(stack);
            blocked = data.input.getOpposite();
        }
    }
    if (data.getItemIdentifierStack() != null) {
        getRoutedPipe().relayedItem(data.getItemIdentifierStack().getStackSize());
    }
    if (data.getDestination() >= 0 && !getRoutedPipe().getRouter().hasRoute(data.getDestination(), data.getTransportMode() == TransportMode.Active, data.getItemIdentifierStack().getItem()) && data.getBufferCounter() < MAX_DESTINATION_UNREACHABLE_BUFFER) {
        _itemBuffer.add(new Triplet<>(data.getItemIdentifierStack(), new Pair<>(_bufferTimeOut, data.getBufferCounter()), data));
        return new RoutingResult(null, false);
    }
    EnumFacing value;
    if (getRoutedPipe().stillNeedReplace() || getRoutedPipe().initialInit()) {
        data.setDoNotBuffer(false);
        value = null;
    } else {
        value = getRoutedPipe().getRouteLayer().getOrientationForItem(data, blocked);
    }
    if (value == null && MainProxy.isClient(getWorld())) {
        return new RoutingResult(null, true);
    }
    if (value == null && !data.getDoNotBuffer() && data.getBufferCounter() < 5) {
        _itemBuffer.add(new Triplet<>(data.getItemIdentifierStack(), new Pair<>(_bufferTimeOut, data.getBufferCounter()), null));
        return new RoutingResult(null, false);
    }
    if (value != null && !getRoutedPipe().getRouter().isRoutedExit(value)) {
        if (isItemUnwanted(data.getItemIdentifierStack())) {
            return new RoutingResult(null, false);
        }
    }
    data.resetDelay();
    return new RoutingResult(value, true);
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) EnumFacing(net.minecraft.util.EnumFacing) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) Pair(logisticspipes.utils.tuples.Pair)

Example 3 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class PipeTransportLogistics method injectItem.

public int injectItem(LPTravelingItem item, EnumFacing inputOrientation) {
    if (item.isCorrupted()) {
        // stage, avoid adding it to the pipe to avoid further exceptions.
        return 0;
    }
    getPipe().triggerDebug();
    int originalCount = item.getItemIdentifierStack().getStackSize();
    item.input = inputOrientation;
    if (MainProxy.isServer(container.getWorld())) {
        readjustSpeed((LPTravelingItemServer) item);
        ItemRoutingInformation info1 = ((LPTravelingItemServer) item).getInfo().clone();
        RoutingResult result = resolveDestination((LPTravelingItemServer) item);
        item.output = result.getFace();
        if (!result.hasRoute) {
            return 0;
        }
        getPipe().debug.log("Injected Item: [" + item.input + ", " + item.output + "] (" + info1);
    } else {
        item.output = null;
    }
    if (item.getPosition() >= getPipeLength()) {
        reachedEnd(item);
    } else {
        items.add(item);
        if (MainProxy.isServer(container.getWorld()) && !getPipe().isOpaque() && item.getItemIdentifierStack().getStackSize() > 0) {
            sendItemPacket((LPTravelingItemServer) item);
        }
    }
    return originalCount - item.getItemIdentifierStack().getStackSize();
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation)

Example 4 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class BCPipeInformationProvider method acceptItem.

@Override
public boolean acceptItem(LPTravelingItem item, TileEntity from) {
    if (pipe != null && pipe.getPipe() != null && pipe.getPipe().getDefinition().flowType == PipeApi.flowItems) {
        if (!(item instanceof LPTravelingItemServer)) {
            return true;
        }
        ItemRoutingInformation routingInformation = ((LPTravelingItemServer) item).getInfo();
        NBTTagCompound routingData = new NBTTagCompound();
        routingInformation.storeToNBT(routingData);
        ItemStack transportStack = item.getItemIdentifierStack().makeNormalStack();
        if (!transportStack.hasTagCompound()) {
            transportStack.setTagCompound(new NBTTagCompound());
        }
        final NBTTagCompound tag = Objects.requireNonNull(transportStack.getTagCompound());
        tag.setTag("logisticspipes:routingdata_buildcraft", routingData);
        IFlowItems itemPipe = (IFlowItems) pipe.getPipe().getFlow();
        itemPipe.insertItemsForce(transportStack, item.output.getOpposite(), null, item.getSpeed());
        return true;
    }
    return false;
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) IFlowItems(buildcraft.api.transport.pipe.IFlowItems) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

Example 5 with ItemRoutingInformation

use of logisticspipes.routing.ItemRoutingInformation in project LogisticsPipes by RS485.

the class BuildCraftProxy method initProxy.

@Override
public void initProxy() {
    LogisticsTileGenericPipe.pipeInventoryConnectionChecker.addSupportedClassType(TileBC_Neptune.class);
    ItemInsertionHandler.ACCEPTORS.add((pipe, from, stack) -> {
        if (!stack.isEmpty() && stack.hasTagCompound() && stack.getTagCompound().hasKey("logisticspipes:routingdata_buildcraft")) {
            NBTTagCompound routingData = stack.getTagCompound().getCompoundTag("logisticspipes:routingdata_buildcraft");
            ItemRoutingInformation info = ItemRoutingInformation.restoreFromNBT(routingData);
            LPTravelingItem item = new LPTravelingItem.LPTravelingItemServer(info);
            item.output = from.getOpposite();
            return pipe.acceptItem(item, null);
        }
        return false;
    });
}
Also used : ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) LPTravelingItem(logisticspipes.transport.LPTravelingItem)

Aggregations

ItemRoutingInformation (logisticspipes.routing.ItemRoutingInformation)22 ItemStack (net.minecraft.item.ItemStack)7 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 ArrayList (java.util.ArrayList)4 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)4 LPTravelingItemServer (logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)4 Triplet (logisticspipes.utils.tuples.Triplet)4 EnumFacing (net.minecraft.util.EnumFacing)4 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)3 ITransactor (logisticspipes.utils.transactor.ITransactor)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)2 Pair (logisticspipes.utils.tuples.Pair)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 IFlowItems (buildcraft.api.transport.pipe.IFlowItems)1 Collection (java.util.Collection)1