Search in sources :

Example 16 with ItemIdentifier

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

the class ModuleCrafter method enabledUpdateEntity.

public void enabledUpdateEntity() {
    if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
        if (_service.isNthTick(6)) {
            cacheAreAllOrderesToBuffer();
        }
        if (_service.getItemOrderManager().isFirstOrderWatched()) {
            TileEntity tile = lastAccessedCrafter.get();
            if (tile != null) {
                _service.getItemOrderManager().setMachineProgress(SimpleServiceLocator.machineProgressProvider.getProgressForTile(tile));
            } else {
                _service.getItemOrderManager().setMachineProgress((byte) 0);
            }
        }
    } else {
        cachedAreAllOrderesToBuffer = false;
    }
    if (!_service.isNthTick(6)) {
        return;
    }
    waitingForCraft = false;
    if ((!_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
        if (getUpgradeManager().getCrafterCleanup() > 0) {
            List<AdjacentTileEntity> crafters = locateCrafters();
            ItemStack extracted = null;
            for (AdjacentTileEntity adjacentCrafter : crafters) {
                extracted = extractFiltered(adjacentCrafter, _cleanupInventory, cleanupModeIsExclude, getUpgradeManager().getCrafterCleanup() * 3);
                if (extracted != null && extracted.stackSize > 0) {
                    break;
                }
            }
            if (extracted != null && extracted.stackSize > 0) {
                _service.queueRoutedItem(SimpleServiceLocator.routedItemHelper.createNewTravelItem(extracted), ForgeDirection.UP);
                _service.getCacheHolder().trigger(CacheTypes.Inventory);
            }
        }
        return;
    }
    waitingForCraft = true;
    List<AdjacentTileEntity> adjacentCrafters = locateCrafters();
    if (adjacentCrafters.size() < 1) {
        if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
            _service.getItemOrderManager().sendFailed();
        }
        return;
    }
    List<ItemIdentifierStack> wanteditem = getCraftedItems();
    if (wanteditem == null || wanteditem.isEmpty()) {
        return;
    }
    _service.spawnParticle(Particles.VioletParticle, 2);
    int itemsleft = itemsToExtract();
    int stacksleft = stacksToExtract();
    while (itemsleft > 0 && stacksleft > 0 && (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA))) {
        // fetch but not remove.
        LogisticsItemOrder nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
        int maxtosend = Math.min(itemsleft, nextOrder.getResource().stack.getStackSize());
        maxtosend = Math.min(nextOrder.getResource().getItem().getMaxStackSize(), maxtosend);
        // retrieve the new crafted items
        ItemStack extracted = null;
        AdjacentTileEntity adjacent = null;
        for (AdjacentTileEntity adjacentCrafter : adjacentCrafters) {
            adjacent = adjacentCrafter;
            extracted = extract(adjacent, nextOrder.getResource(), maxtosend);
            if (extracted != null && extracted.stackSize > 0) {
                break;
            }
        }
        if (extracted == null || extracted.stackSize == 0) {
            _service.getItemOrderManager().deferSend();
            break;
        }
        _service.getCacheHolder().trigger(CacheTypes.Inventory);
        lastAccessedCrafter = new WeakReference<>(adjacent.tileEntity);
        // send the new crafted items to the destination
        ItemIdentifier extractedID = ItemIdentifier.get(extracted);
        while (extracted.stackSize > 0) {
            if (!doesExtractionMatch(nextOrder, extractedID)) {
                LogisticsItemOrder startOrder = nextOrder;
                if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                    do {
                        _service.getItemOrderManager().deferSend();
                        nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
                    } while (!doesExtractionMatch(nextOrder, extractedID) && startOrder != nextOrder);
                }
                if (startOrder == nextOrder) {
                    int numtosend = Math.min(extracted.stackSize, extractedID.getMaxStackSize());
                    if (numtosend == 0) {
                        break;
                    }
                    stacksleft -= 1;
                    itemsleft -= numtosend;
                    ItemStack stackToSend = extracted.splitStack(numtosend);
                    //Route the unhandled item
                    _service.sendStack(stackToSend, -1, ItemSendMode.Normal, null);
                    continue;
                }
            }
            int numtosend = Math.min(extracted.stackSize, extractedID.getMaxStackSize());
            numtosend = Math.min(numtosend, nextOrder.getResource().stack.getStackSize());
            if (numtosend == 0) {
                break;
            }
            stacksleft -= 1;
            itemsleft -= numtosend;
            ItemStack stackToSend = extracted.splitStack(numtosend);
            if (nextOrder.getDestination() != null) {
                SinkReply reply = LogisticsManager.canSink(nextOrder.getDestination().getRouter(), null, true, ItemIdentifier.get(stackToSend), null, true, false);
                boolean defersend = false;
                if (reply == null || reply.bufferMode != BufferMode.NONE || reply.maxNumberOfItems < 1) {
                    defersend = true;
                }
                IRoutedItem item = SimpleServiceLocator.routedItemHelper.createNewTravelItem(stackToSend);
                item.setDestination(nextOrder.getDestination().getRouter().getSimpleID());
                item.setTransportMode(TransportMode.Active);
                item.setAdditionalTargetInformation(nextOrder.getInformation());
                _service.queueRoutedItem(item, adjacent.direction);
                _service.getItemOrderManager().sendSuccessfull(stackToSend.stackSize, defersend, item);
            } else {
                _service.sendStack(stackToSend, -1, ItemSendMode.Normal, nextOrder.getInformation());
                _service.getItemOrderManager().sendSuccessfull(stackToSend.stackSize, false, null);
            }
            if (_service.getItemOrderManager().hasOrders(ResourceType.CRAFTING, ResourceType.EXTRA)) {
                // fetch but not remove.
                nextOrder = _service.getItemOrderManager().peekAtTopRequest(ResourceType.CRAFTING, ResourceType.EXTRA);
            }
        }
    }
}
Also used : LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) SinkReply(logisticspipes.utils.SinkReply) ItemStack(net.minecraft.item.ItemStack) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 17 with ItemIdentifier

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

the class LogisticsManager method getCraftableItems.

/**
	 * @param validDestinations
	 *            a List of ExitRoute of valid destinations.
	 * @return LinkedList with ItemIdentifier
	 */
@Override
public LinkedList<ItemIdentifier> getCraftableItems(List<ExitRoute> validDestinations) {
    LinkedList<ItemIdentifier> craftableItems = new LinkedList<>();
    BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
    outer: for (ExitRoute r : validDestinations) {
        if (r == null) {
            continue;
        }
        if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            continue;
        }
        if (used.get(r.destination.getSimpleID())) {
            continue;
        }
        if (!(r.destination.getPipe() instanceof ICraftItems)) {
            continue;
        }
        for (IFilter filter : r.filters) {
            if (filter.blockCrafting()) {
                continue outer;
            }
        }
        ICraftItems crafter = (ICraftItems) r.destination.getPipe();
        List<ItemIdentifierStack> craftedItems = crafter.getCraftedItems();
        if (craftedItems != null) {
            outer2: for (ItemIdentifierStack craftedItem : craftedItems) {
                if (craftedItem != null && !craftableItems.contains(craftedItem.getItem())) {
                    for (IFilter filter : r.filters) {
                        if (filter.isBlocked() == filter.isFilteredItem(craftedItem.getItem())) {
                            continue outer2;
                        }
                    }
                    craftableItems.add(craftedItem.getItem());
                }
            }
        }
        used.set(r.destination.getSimpleID(), true);
    }
    return craftableItems;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IFilter(logisticspipes.interfaces.routing.IFilter) BitSet(java.util.BitSet) ICraftItems(logisticspipes.interfaces.routing.ICraftItems) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExitRoute(logisticspipes.routing.ExitRoute) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) LinkedList(java.util.LinkedList)

Example 18 with ItemIdentifier

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

the class ModuleEnchantmentSinkMK2 method getSpecificInterests.

@Override
public List<ItemIdentifier> getSpecificInterests() {
    Map<ItemIdentifier, Integer> mapIC = _filterInventory.getItemsAndCount();
    List<ItemIdentifier> li = new ArrayList<>(mapIC.size());
    li.addAll(mapIC.keySet());
    for (ItemIdentifier id : mapIC.keySet()) {
        li.add(id.getUndamaged());
        li.add(id.getUndamaged().getIgnoringNBT());
    }
    return li;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ArrayList(java.util.ArrayList)

Example 19 with ItemIdentifier

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

the class ModuleExtractor method tick.

@Override
public void tick() {
    if (++currentTick < ticksToAction()) {
        return;
    }
    currentTick = 0;
    //Extract Item
    IInventory realInventory = _service.getRealInventory();
    if (realInventory == null) {
        return;
    }
    ForgeDirection extractOrientation = _sneakyDirection;
    if (extractOrientation == ForgeDirection.UNKNOWN) {
        extractOrientation = _service.inventoryOrientation().getOpposite();
    }
    IInventoryUtil targetUtil = _service.getSneakyInventory(extractOrientation, true);
    for (int i = 0; i < targetUtil.getSizeInventory(); i++) {
        ItemStack slot = targetUtil.getStackInSlot(i);
        if (slot == null) {
            continue;
        }
        ItemIdentifier slotitem = ItemIdentifier.get(slot);
        List<Integer> jamList = new LinkedList<>();
        Pair<Integer, SinkReply> reply = _service.hasDestination(slotitem, true, jamList);
        if (reply == null) {
            continue;
        }
        int itemsleft = itemsToExtract();
        while (reply != null) {
            int count = Math.min(itemsleft, slot.stackSize);
            count = Math.min(count, slotitem.getMaxStackSize());
            if (reply.getValue2().maxNumberOfItems > 0) {
                count = Math.min(count, reply.getValue2().maxNumberOfItems);
            }
            while (!_service.useEnergy(neededEnergy() * count) && count > 0) {
                _service.spawnParticle(Particles.OrangeParticle, 2);
                count--;
            }
            if (count <= 0) {
                break;
            }
            ItemStack stackToSend = targetUtil.decrStackSize(i, count);
            if (stackToSend == null || stackToSend.stackSize == 0) {
                break;
            }
            count = stackToSend.stackSize;
            _service.sendStack(stackToSend, reply, itemSendMode());
            itemsleft -= count;
            if (itemsleft <= 0) {
                break;
            }
            slot = targetUtil.getStackInSlot(i);
            if (slot == null) {
                break;
            }
            jamList.add(reply.getValue1());
            reply = _service.hasDestination(ItemIdentifier.get(slot), true, jamList);
        }
        break;
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Example 20 with ItemIdentifier

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

the class ModuleItemSink method getSpecificInterests.

@Override
public List<ItemIdentifier> getSpecificInterests() {
    if (_isDefaultRoute) {
        return null;
    }
    Map<ItemIdentifier, Integer> mapIC = _filterInventory.getItemsAndCount();
    List<ItemIdentifier> li = new ArrayList<>(mapIC.size());
    li.addAll(mapIC.keySet());
    li.addAll(mapIC.keySet().stream().map(ItemIdentifier::getUndamaged).collect(Collectors.toList()));
    if (_service.getUpgradeManager(slot, positionInt).isFuzzyUpgrade()) {
        for (Pair<ItemIdentifierStack, Integer> stack : _filterInventory) {
            if (stack.getValue1() == null) {
                continue;
            }
            ItemIdentifier ident = stack.getValue1().getItem();
            if (ignoreData.get(stack.getValue2())) {
                li.add(ident.getIgnoringData());
            }
            if (ignoreNBT.get(stack.getValue2())) {
                li.add(ident.getIgnoringNBT());
            }
            if (ignoreData.get(stack.getValue2()) && ignoreNBT.get(stack.getValue2())) {
                li.add(ident.getIgnoringData().getIgnoringNBT());
            }
        }
    }
    return li;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ArrayList(java.util.ArrayList) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

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