Search in sources :

Example 6 with IInventoryUtil

use of logisticspipes.interfaces.IInventoryUtil in project LogisticsPipes by RS485.

the class ModuleCrafter method extractFromIInventory.

private ItemStack extractFromIInventory(IInventory inv, IResource wanteditem, int count, ForgeDirection dir) {
    IInventoryUtil invUtil = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv, dir);
    ItemIdentifier itemToExtract = null;
    if (wanteditem instanceof ItemResource) {
        itemToExtract = ((ItemResource) wanteditem).getItem();
    } else if (wanteditem instanceof DictResource) {
        int max = Integer.MIN_VALUE;
        ItemIdentifier toExtract = null;
        for (Map.Entry<ItemIdentifier, Integer> content : invUtil.getItemsAndCount().entrySet()) {
            if (wanteditem.matches(content.getKey(), IResource.MatchSettings.NORMAL)) {
                if (content.getValue() > max) {
                    max = content.getValue();
                    toExtract = content.getKey();
                }
            }
        }
        if (toExtract == null) {
            return null;
        }
        itemToExtract = toExtract;
    }
    int available = invUtil.itemCount(itemToExtract);
    if (available == 0) {
        return null;
    }
    if (!_service.useEnergy(neededEnergy() * Math.min(count, available))) {
        return null;
    }
    return invUtil.getMultipleItems(itemToExtract, Math.min(count, available));
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) DictResource(logisticspipes.request.resources.DictResource) ItemResource(logisticspipes.request.resources.ItemResource)

Example 7 with IInventoryUtil

use of logisticspipes.interfaces.IInventoryUtil in project LogisticsPipes by RS485.

the class ModuleElectricBuffer method tick.

@Override
public void tick() {
    if (++currentTickCount < ticksToAction) {
        return;
    }
    currentTickCount = 0;
    IInventoryUtil inv = _service.getPointedInventory(true);
    if (inv == null) {
        return;
    }
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.getStackInSlot(i);
        if (stack == null) {
            continue;
        }
        if (SimpleServiceLocator.IC2Proxy.isElectricItem(stack)) {
            Triplet<Integer, SinkReply, List<IFilter>> reply = SimpleServiceLocator.logisticsManager.hasDestinationWithMinPriority(ItemIdentifier.get(stack), _service.getSourceID(), true, FixedPriority.ElectricManager);
            if (reply == null) {
                continue;
            }
            _service.spawnParticle(Particles.OrangeParticle, 2);
            _service.sendStack(inv.decrStackSize(i, 1), reply, ItemSendMode.Normal);
            return;
        }
        continue;
    }
}
Also used : SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 8 with IInventoryUtil

use of logisticspipes.interfaces.IInventoryUtil 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 9 with IInventoryUtil

use of logisticspipes.interfaces.IInventoryUtil in project LogisticsPipes by RS485.

the class ModuleCCBasedQuickSort method tick.

@Override
public void tick() {
    IInventoryUtil invUtil = _service.getPointedInventory(true);
    if (invUtil == null) {
        return;
    }
    handleSinkResponses(invUtil);
    if (--currentTick > 0) {
        return;
    }
    if (stalled) {
        currentTick = stalledDelay;
    } else {
        currentTick = normalDelay;
    }
    if (!_service.canUseEnergy(500)) {
        stalled = true;
        return;
    }
    if ((!(invUtil instanceof SpecialInventoryHandler) && invUtil.getSizeInventory() == 0) || !_service.canUseEnergy(500)) {
        stalled = true;
        return;
    }
    //incremented at the end of the previous loop.
    if (lastStackLookedAt >= invUtil.getSizeInventory()) {
        lastStackLookedAt = 0;
    }
    ItemStack slot = invUtil.getStackInSlot(lastStackLookedAt);
    while (slot == null) {
        lastStackLookedAt++;
        if (lastStackLookedAt >= invUtil.getSizeInventory()) {
            lastStackLookedAt = 0;
        }
        slot = invUtil.getStackInSlot(lastStackLookedAt);
        if (lastStackLookedAt == lastSuceededStack) {
            stalled = true;
            send();
            // then we have been around the list without sending, halt for now
            return;
        }
    }
    send();
    if (!sinkResponses.containsKey(lastStackLookedAt)) {
        createSinkMessage(lastStackLookedAt, ItemIdentifierStack.getFromStack(slot));
    }
    lastStackLookedAt++;
    checkSize();
}
Also used : IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SpecialInventoryHandler(logisticspipes.proxy.specialinventoryhandler.SpecialInventoryHandler) ItemStack(net.minecraft.item.ItemStack)

Example 10 with IInventoryUtil

use of logisticspipes.interfaces.IInventoryUtil in project LogisticsPipes by RS485.

the class SlotFinderNumberPacket method processPacket.

@Override
@SuppressWarnings("unchecked")
public void processPacket(EntityPlayer player) {
    IInventory inv = this.getTile(player.worldObj, IInventory.class);
    if (inv instanceof ISidedInventory) {
        inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
    }
    IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);
    Slot result = null;
    if (((List<Slot>) player.openContainer.inventorySlots).get(inventorySlot).slotNumber == inventorySlot) {
        result = ((List<Slot>) player.openContainer.inventorySlots).get(inventorySlot);
    }
    if (result == null) {
        for (Slot slotObject : (List<Slot>) player.openContainer.inventorySlots) {
            if (slotObject.slotNumber == inventorySlot) {
                result = slotObject;
                break;
            }
        }
    }
    if (result == null) {
        player.addChatComponentMessage(new ChatComponentTranslation("lp.chat.slotnotfound"));
    }
    int resultIndex = -1;
    if (resultIndex == -1) {
        ItemStack content = result.getStack();
        if (content != null) {
            for (int i = 0; i < util.getSizeInventory(); i++) {
                if (content == util.getStackInSlot(i)) {
                    resultIndex = i;
                    break;
                }
            }
        } else {
            ItemStack dummyStack = new ItemStack(Blocks.stone, 0, 0);
            NBTTagCompound nbt = new NBTTagCompound();
            //Make it unique
            nbt.setBoolean("LPStackFinderBoolean", true);
            dummyStack.setTagCompound(nbt);
            result.putStack(dummyStack);
            for (int i = 0; i < util.getSizeInventory(); i++) {
                if (dummyStack == util.getStackInSlot(i)) {
                    resultIndex = i;
                    break;
                }
            }
            if (resultIndex == -1) {
                for (int i = 0; i < util.getSizeInventory(); i++) {
                    ItemStack stack = util.getStackInSlot(i);
                    if (stack == null) {
                        continue;
                    }
                    if (ItemIdentifier.get(stack).equals(ItemIdentifier.get(dummyStack)) && stack.stackSize == dummyStack.stackSize) {
                        resultIndex = i;
                        break;
                    }
                }
            }
            result.putStack(null);
        }
    }
    if (resultIndex == -1) {
        player.addChatComponentMessage(new ChatComponentTranslation("lp.chat.slotnotfound"));
    } else {
        //Copy pipe to coordinates to use the getPipe method
        setPosX(getPipePosX());
        setPosY(getPipePosY());
        setPosZ(getPipePosZ());
        ModuleActiveSupplier module = this.getLogisticsModule(player, ModuleActiveSupplier.class);
        if (module != null) {
            module.slotArray[slot] = resultIndex;
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ISidedInventory(net.minecraft.inventory.ISidedInventory) ModuleActiveSupplier(logisticspipes.modules.ModuleActiveSupplier) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Slot(net.minecraft.inventory.Slot) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)23 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)14 SinkReply (logisticspipes.utils.SinkReply)13 ItemStack (net.minecraft.item.ItemStack)13 IInventory (net.minecraft.inventory.IInventory)9 LogisticsModule (logisticspipes.modules.abstractmodules.LogisticsModule)8 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)8 List (java.util.List)7 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)6 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)6 ArrayList (java.util.ArrayList)5 Collection (java.util.Collection)5 IRoutedItem (logisticspipes.logisticspipes.IRoutedItem)5 IRouter (logisticspipes.routing.IRouter)5 ConnectionPipeType (logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType)5 PlayerCollectionList (logisticspipes.utils.PlayerCollectionList)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 Side (cpw.mods.fml.relauncher.Side)4 SideOnly (cpw.mods.fml.relauncher.SideOnly)4 Map (java.util.Map)4