Search in sources :

Example 1 with ITransactor

use of logisticspipes.utils.transactor.ITransactor 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 ITransactor

use of logisticspipes.utils.transactor.ITransactor in project LogisticsPipes by RS485.

the class LogisticsRoutingBoardRobot method handleItem.

public LPTravelingItemServer handleItem(LPTravelingItemServer arrivingItem) {
    if (robot.isDead) {
        return arrivingItem;
    }
    ITransactor trans = InventoryHelper.getTransactorFor(robot, ForgeDirection.UNKNOWN);
    ItemStack inserted = trans.add(arrivingItem.getItemIdentifierStack().makeNormalStack(), ForgeDirection.UNKNOWN, false);
    if (inserted.stackSize != arrivingItem.getItemIdentifierStack().getStackSize()) {
        acceptsItems = false;
        startTransport();
        return arrivingItem;
    }
    inserted = trans.add(arrivingItem.getItemIdentifierStack().makeNormalStack(), ForgeDirection.UNKNOWN, true);
    if (inserted.stackSize != arrivingItem.getItemIdentifierStack().getStackSize()) {
        throw new UnsupportedOperationException("" + trans);
    }
    items.add(arrivingItem);
    if (currentTarget == null) {
        currentTarget = findTarget();
        refreshRoutingTable();
    }
    ticksWithContent = 0;
    return null;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ITransactor(logisticspipes.utils.transactor.ITransactor)

Example 3 with ITransactor

use of logisticspipes.utils.transactor.ITransactor in project LogisticsPipes by RS485.

the class PipeItemsInvSysConnector method checkOneConnectedInv.

private boolean checkOneConnectedInv(@Nonnull IInventoryUtil inv, EnumFacing 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.isEmpty()) {
                        return contentchanged;
                    }
                    if (toSend.getCount() != need.getItem().getStackSize()) {
                        if (inv instanceof ITransactor) {
                            ((ITransactor) inv).add(toSend, dir.getOpposite(), true);
                        } else {
                            container.getWorld().spawnEntity(ItemIdentifierStack.getFromStack(toSend).makeEntityItem(getWorld(), container.getX(), container.getY(), container.getZ()));
                        }
                        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 {
                        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)

Aggregations

ITransactor (logisticspipes.utils.transactor.ITransactor)3 ItemStack (net.minecraft.item.ItemStack)3 ArrayList (java.util.ArrayList)2 ItemRoutingInformation (logisticspipes.routing.ItemRoutingInformation)2 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)2