Search in sources :

Example 26 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class PipeItemsRequestLogistics method getProvidedItems.

/* IRequestAPI */
@Override
public List<ItemStack> getProvidedItems() {
    if (stillNeedReplace()) {
        return new ArrayList<>();
    }
    Map<ItemIdentifier, Integer> items = SimpleServiceLocator.logisticsManager.getAvailableItems(getRouter().getIRoutersByCost());
    List<ItemStack> list = new ArrayList<>(items.size());
    for (Entry<ItemIdentifier, Integer> item : items.entrySet()) {
        ItemStack is = item.getKey().unsafeMakeNormalStack(item.getValue());
        list.add(is);
    }
    return list;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 27 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class PipeLogisticsChassi method getSpecificInterests.

@Override
public Set<ItemIdentifier> getSpecificInterests() {
    Set<ItemIdentifier> l1 = new TreeSet<>();
    //if we don't have a pointed inventory we can't be interested in anything
    if (getRealInventory() == null) {
        return l1;
    }
    for (int moduleIndex = 0; moduleIndex < getChassiSize(); moduleIndex++) {
        LogisticsModule module = _module.getSubModule(moduleIndex);
        if (module != null && module.interestedInAttachedInventory()) {
            IInventoryUtil inv = getSneakyInventory(false, module.getSlot(), module.getPositionInt());
            if (inv == null) {
                continue;
            }
            Set<ItemIdentifier> items = inv.getItems();
            l1.addAll(items);
            //also add tag-less variants ... we should probably add a module.interestedIgnoringNBT at some point
            l1.addAll(items.stream().map(ItemIdentifier::getIgnoringNBT).collect(Collectors.toList()));
            boolean modulesInterestedInUndamged = false;
            for (int i = 0; i < getChassiSize(); i++) {
                if (_module.getSubModule(moduleIndex).interestedInUndamagedID()) {
                    modulesInterestedInUndamged = true;
                    break;
                }
            }
            if (modulesInterestedInUndamged) {
                l1.addAll(items.stream().map(ItemIdentifier::getUndamaged).collect(Collectors.toList()));
            }
            // no need to check other modules for interest in the inventory, when we know that 1 already is.
            break;
        }
    }
    for (int i = 0; i < getChassiSize(); i++) {
        LogisticsModule module = _module.getSubModule(i);
        if (module != null) {
            Collection<ItemIdentifier> current = module.getSpecificInterests();
            if (current != null) {
                l1.addAll(current);
            }
        }
    }
    return l1;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) TreeSet(java.util.TreeSet) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil)

Example 28 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class PipeItemsInvSysConnector method addItem.

@Override
public void addItem(ItemRoutingInformation info) {
    if (info.getItem() != null && info.getItem().getStackSize() > 0 && info.destinationint >= 0) {
        ItemIdentifier insertedType = info.getItem().getItem();
        List<ItemRoutingInformation> entry = itemsOnRoute.get(insertedType);
        if (entry == null) {
            // linked list as this is almost always very small, but experiences random removal
            entry = new LinkedList<>();
            itemsOnRoute.put(insertedType, entry);
        }
        entry.add(info);
        updateContentListener();
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation)

Example 29 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier 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 30 with ItemIdentifier

use of logisticspipes.utils.item.ItemIdentifier in project LogisticsPipes by RS485.

the class PipeBlockRequestTable method getOutput.

public ItemStack getOutput(boolean oreDict) {
    if (cache == null) {
        cacheRecipe();
        if (cache == null) {
            return null;
        }
    }
    if (resultInv.getIDStackInSlot(0) == null) {
        return null;
    }
    int[] toUse = new int[9];
    int[] used = new int[inv.getSizeInventory()];
    outer: for (int i = 0; i < 9; i++) {
        ItemStack item = matrix.getStackInSlot(i);
        if (item == null) {
            toUse[i] = -1;
            continue;
        }
        ItemIdentifier ident = ItemIdentifier.get(item);
        for (int j = 0; j < inv.getSizeInventory(); j++) {
            item = inv.getStackInSlot(j);
            if (item == null) {
                continue;
            }
            ItemIdentifier withIdent = ItemIdentifier.get(item);
            if (ident.equalsForCrafting(withIdent)) {
                if (item.stackSize > used[j]) {
                    used[j]++;
                    toUse[i] = j;
                    continue outer;
                }
            }
            if (oreDict) {
                if (ident.getDictIdentifiers() != null && withIdent.getDictIdentifiers() != null && ident.getDictIdentifiers().canMatch(withIdent.getDictIdentifiers(), true, false)) {
                    if (item.stackSize > used[j]) {
                        used[j]++;
                        toUse[i] = j;
                        continue outer;
                    }
                }
            }
        }
        //Not enough material
        return null;
    }
    //TODO
    AutoCraftingInventory crafter = new AutoCraftingInventory(null);
    for (int i = 0; i < 9; i++) {
        int j = toUse[i];
        if (j != -1) {
            crafter.setInventorySlotContents(i, inv.getStackInSlot(j));
        }
    }
    if (!cache.matches(crafter, getWorld())) {
        //Fix MystCraft
        return null;
    }
    ItemStack result = cache.getCraftingResult(crafter);
    if (result == null) {
        return null;
    }
    if (!resultInv.getIDStackInSlot(0).getItem().equalsWithoutNBT(ItemIdentifier.get(result))) {
        return null;
    }
    //TODO
    crafter = new AutoCraftingInventory(null);
    for (int i = 0; i < 9; i++) {
        int j = toUse[i];
        if (j != -1) {
            crafter.setInventorySlotContents(i, inv.decrStackSize(j, 1));
        }
    }
    result = cache.getCraftingResult(crafter);
    if (fake == null) {
        fake = MainProxy.getFakePlayer(container);
    }
    result = result.copy();
    SlotCrafting craftingSlot = new SlotCrafting(fake, crafter, resultInv, 0, 0, 0);
    craftingSlot.onPickupFromSlot(fake, result);
    for (int i = 0; i < 9; i++) {
        ItemStack left = crafter.getStackInSlot(i);
        crafter.setInventorySlotContents(i, null);
        if (left != null) {
            left.stackSize = inv.addCompressed(left, false);
            if (left.stackSize > 0) {
                ItemIdentifierInventory.dropItems(getWorld(), left, getX(), getY(), getZ());
            }
        }
    }
    for (int i = 0; i < fake.inventory.getSizeInventory(); i++) {
        ItemStack left = fake.inventory.getStackInSlot(i);
        fake.inventory.setInventorySlotContents(i, null);
        if (left != null) {
            left.stackSize = inv.addCompressed(left, false);
            if (left.stackSize > 0) {
                ItemIdentifierInventory.dropItems(getWorld(), left, getX(), getY(), getZ());
            }
        }
    }
    return result;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) AutoCraftingInventory(logisticspipes.blocks.crafting.AutoCraftingInventory) ItemStack(net.minecraft.item.ItemStack) SlotCrafting(net.minecraft.inventory.SlotCrafting)

Aggregations

ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)69 ItemStack (net.minecraft.item.ItemStack)37 ArrayList (java.util.ArrayList)23 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)23 HashMap (java.util.HashMap)14 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)13 TreeSet (java.util.TreeSet)12 IFilter (logisticspipes.interfaces.routing.IFilter)11 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)11 LinkedList (java.util.LinkedList)10 List (java.util.List)10 Map (java.util.Map)10 SinkReply (logisticspipes.utils.SinkReply)10 CoreRoutedPipe (logisticspipes.pipes.basic.CoreRoutedPipe)9 IRouter (logisticspipes.routing.IRouter)9 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)9 BitSet (java.util.BitSet)8 Entry (java.util.Map.Entry)7 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)7