Search in sources :

Example 21 with IInventoryUtil

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

the class ModuleElectricManager method tick.

@Override
public void tick() {
    if (++currentTick < ticksToAction) {
        return;
    }
    currentTick = 0;
    IInventoryUtil inv = _service.getSneakyInventory(true, slot, positionInt);
    if (inv == null) {
        return;
    }
    for (int i = 0; i < inv.getSizeInventory(); i++) {
        ItemStack stack = inv.getStackInSlot(i);
        if (stack == null) {
            return;
        }
        if (isOfInterest(stack)) {
            //If item set to discharge and its fully discharged, then extract it.
            if (_dischargeMode && SimpleServiceLocator.IC2Proxy.isFullyDischarged(stack)) {
                Triplet<Integer, SinkReply, List<IFilter>> reply = SimpleServiceLocator.logisticsManager.hasDestinationWithMinPriority(ItemIdentifier.get(stack), _service.getSourceID(), true, FixedPriority.ElectricBuffer);
                if (reply == null) {
                    continue;
                }
                if (_service.useEnergy(10)) {
                    _service.spawnParticle(Particles.OrangeParticle, 2);
                    _service.sendStack(inv.decrStackSize(i, 1), reply, ItemSendMode.Normal);
                    return;
                }
            }
            //If item set to charge  and its fully charged, then extract it.
            if (!_dischargeMode && SimpleServiceLocator.IC2Proxy.isFullyCharged(stack)) {
                Triplet<Integer, SinkReply, List<IFilter>> reply = SimpleServiceLocator.logisticsManager.hasDestinationWithMinPriority(ItemIdentifier.get(stack), _service.getSourceID(), true, FixedPriority.ElectricBuffer);
                if (reply == null) {
                    continue;
                }
                if (_service.useEnergy(10)) {
                    _service.spawnParticle(Particles.OrangeParticle, 2);
                    _service.sendStack(inv.decrStackSize(i, 1), reply, ItemSendMode.Normal);
                    return;
                }
            }
        }
    }
}
Also used : SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 22 with IInventoryUtil

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

the class PipeItemsBasicLogistics method getPointedInventory.

@Override
public IInventoryUtil getPointedInventory(boolean forExtraction) {
    IInventoryUtil inv = super.getPointedInventory(forExtraction);
    if (inv == null) {
        Optional<Pair<IInventory, ForgeDirection>> first = new WorldCoordinatesWrapper(container).getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacentInventory -> new Pair<>(InventoryHelper.getInventory((IInventory) adjacentInventory.tileEntity), adjacentInventory.direction)).filter(inventoryDirectionPair -> inventoryDirectionPair.getValue1() != null).findFirst();
        if (first.isPresent()) {
            Pair<IInventory, ForgeDirection> p = first.get();
            inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(p.getValue1(), p.getValue2().getOpposite());
        }
    }
    return inv;
}
Also used : OrientationsUtil(logisticspipes.utils.OrientationsUtil) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) TreeSet(java.util.TreeSet) LogisticsPowerJunctionTileEntity(logisticspipes.blocks.powertile.LogisticsPowerJunctionTileEntity) LogisticsSecurityTileEntity(logisticspipes.blocks.LogisticsSecurityTileEntity) InventoryHelper(logisticspipes.utils.InventoryHelper) ModulePositionType(logisticspipes.modules.abstractmodules.LogisticsModule.ModulePositionType) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Set(java.util.Set) TextureType(logisticspipes.textures.Textures.TextureType) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) PipeTransportLogistics(logisticspipes.transport.PipeTransportLogistics) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ModuleItemSink(logisticspipes.modules.ModuleItemSink) Pair(logisticspipes.utils.tuples.Pair) IInventory(net.minecraft.inventory.IInventory) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IInventory(net.minecraft.inventory.IInventory) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Pair(logisticspipes.utils.tuples.Pair)

Example 23 with IInventoryUtil

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

the class PipeTransportLogistics method handleTileReachedServer_internal.

protected final void handleTileReachedServer_internal(LPTravelingItemServer arrivingItem, TileEntity tile, ForgeDirection dir) {
    if (isRouted && getPipe().container.tilePart.getBCPipePluggable(dir) != null && getPipe().container.tilePart.getBCPipePluggable(dir).isAcceptingItems(arrivingItem)) {
        LPTravelingItemServer remainingItem = getPipe().container.tilePart.getBCPipePluggable(dir).handleItem(arrivingItem);
        if (remainingItem != null) {
            getRoutedPipe().getRouter().update(true, getRoutedPipe());
            this.injectItem(remainingItem, dir);
        }
        return;
    }
    if (getPipe() instanceof PipeItemsFluidSupplier) {
        ((PipeItemsFluidSupplier) getPipe()).endReached(arrivingItem, tile);
        if (arrivingItem.getItemIdentifierStack().getStackSize() <= 0) {
            return;
        }
    }
    markChunkModified(tile);
    if (MainProxy.isServer(getWorld()) && arrivingItem.getInfo() != null && arrivingItem.getArrived() && isRouted) {
        getRoutedPipe().notifyOfItemArival(arrivingItem.getInfo());
    }
    if (getPipe() instanceof FluidRoutedPipe) {
        if (((FluidRoutedPipe) getPipe()).endReached(arrivingItem, tile)) {
            return;
        }
    }
    boolean isSpecialConnectionInformationTransition = false;
    if (MainProxy.isServer(getWorld())) {
        if (SimpleServiceLocator.specialtileconnection.needsInformationTransition(tile)) {
            isSpecialConnectionInformationTransition = true;
            SimpleServiceLocator.specialtileconnection.transmit(tile, arrivingItem);
        }
    }
    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
        if (passToNextPipe(arrivingItem, tile)) {
            return;
        }
    } else if (tile instanceof IInventory && isRouted) {
        getRoutedPipe().getCacheHolder().trigger(CacheTypes.Inventory);
        // items.scheduleRemoval(arrivingItem);
        if (MainProxy.isServer(getWorld())) {
            // destroy the item on exit if it isn't exitable
            if (!isSpecialConnectionInformationTransition && !isItemExitable(arrivingItem.getItemIdentifierStack())) {
                return;
            }
            // last chance for chassi to back out
            if (arrivingItem != null) {
                if (arrivingItem.getTransportMode() != TransportMode.Active && !getRoutedPipe().getTransportLayer().stillWantItem(arrivingItem)) {
                    reverseItem(arrivingItem);
                    return;
                }
            }
            ISlotUpgradeManager slotManager;
            {
                ModulePositionType slot = null;
                int positionInt = -1;
                if (arrivingItem.getInfo().targetInfo instanceof ChassiTargetInformation) {
                    positionInt = ((ChassiTargetInformation) arrivingItem.getInfo().targetInfo).getModuleSlot();
                    slot = ModulePositionType.SLOT;
                } else if (LPConstants.DEBUG && container.pipe instanceof PipeLogisticsChassi) {
                    System.out.println(arrivingItem);
                    new RuntimeException("[ItemInsertion] Information weren't ment for a chassi pipe").printStackTrace();
                }
                slotManager = getRoutedPipe().getUpgradeManager(slot, positionInt);
            }
            boolean tookSome = false;
            if (arrivingItem.getAdditionalTargetInformation() instanceof ITargetSlotInformation) {
                ITargetSlotInformation information = (ITargetSlotInformation) arrivingItem.getAdditionalTargetInformation();
                IInventory inv = (IInventory) tile;
                if (inv instanceof ISidedInventory) {
                    inv = new SidedInventoryMinecraftAdapter((ISidedInventory) inv, ForgeDirection.UNKNOWN, false);
                }
                IInventoryUtil util = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv);
                if (util instanceof ISpecialInsertion) {
                    int slot = information.getTargetSlot();
                    int amount = information.getAmount();
                    if (util.getSizeInventory() > slot) {
                        ItemStack content = util.getStackInSlot(slot);
                        ItemStack toAdd = arrivingItem.getItemIdentifierStack().makeNormalStack();
                        toAdd.stackSize = Math.min(toAdd.stackSize, Math.max(0, amount - (content != null ? content.stackSize : 0)));
                        if (toAdd.stackSize > 0) {
                            if (util.getSizeInventory() > slot) {
                                int added = ((ISpecialInsertion) util).addToSlot(toAdd, slot);
                                arrivingItem.getItemIdentifierStack().lowerStackSize(added);
                                if (added > 0) {
                                    tookSome = true;
                                }
                            }
                        }
                    }
                    if (information.isLimited()) {
                        if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                            reverseItem(arrivingItem);
                        }
                        return;
                    }
                }
            }
            // sneaky insertion
            if (!getRoutedPipe().getUpgradeManager().hasCombinedSneakyUpgrade() || slotManager.hasOwnSneakyUpgrade()) {
                ForgeDirection insertion = arrivingItem.output.getOpposite();
                if (slotManager.hasSneakyUpgrade()) {
                    insertion = slotManager.getSneakyOrientation();
                }
                ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
                arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
                if (added.stackSize > 0 && arrivingItem instanceof IRoutedItem) {
                    tookSome = true;
                    arrivingItem.setBufferCounter(0);
                }
                ItemRoutingInformation info;
                if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                    // we have some leftovers, we are splitting the stack, we need to clone the info
                    info = arrivingItem.getInfo().clone();
                    // For InvSysCon
                    info.getItem().setStackSize(added.stackSize);
                    insertedItemStack(info, tile);
                } else {
                    info = arrivingItem.getInfo();
                    info.getItem().setStackSize(added.stackSize);
                    // For InvSysCon
                    insertedItemStack(info, tile);
                    // every item has been inserted.
                    return;
                }
            } else {
                ForgeDirection[] dirs = getRoutedPipe().getUpgradeManager().getCombinedSneakyOrientation();
                for (ForgeDirection insertion : dirs) {
                    if (insertion == null) {
                        continue;
                    }
                    ItemStack added = InventoryHelper.getTransactorFor(tile, insertion).add(arrivingItem.getItemIdentifierStack().makeNormalStack(), insertion, true);
                    arrivingItem.getItemIdentifierStack().lowerStackSize(added.stackSize);
                    if (added.stackSize > 0) {
                        tookSome = true;
                        arrivingItem.setBufferCounter(0);
                    }
                    ItemRoutingInformation info;
                    if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                        // we have some leftovers, we are splitting the stack, we need to clone the info
                        info = arrivingItem.getInfo().clone();
                        // For InvSysCon
                        info.getItem().setStackSize(added.stackSize);
                        insertedItemStack(info, tile);
                    } else {
                        info = arrivingItem.getInfo();
                        info.getItem().setStackSize(added.stackSize);
                        // For InvSysCon
                        insertedItemStack(info, tile);
                        // every item has been inserted.
                        return;
                    }
                }
            }
            if (arrivingItem.getItemIdentifierStack().getStackSize() > 0) {
                reverseItem(arrivingItem);
            }
        }
        // the item is handled
        return;
    }
    // end of insert into IInventory
    dropItem(arrivingItem);
}
Also used : IInventory(net.minecraft.inventory.IInventory) ITargetSlotInformation(logisticspipes.interfaces.routing.ITargetSlotInformation) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) FluidRoutedPipe(logisticspipes.pipes.basic.fluid.FluidRoutedPipe) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ModulePositionType(logisticspipes.modules.abstractmodules.LogisticsModule.ModulePositionType) ISidedInventory(net.minecraft.inventory.ISidedInventory) PipeItemsFluidSupplier(logisticspipes.pipes.PipeItemsFluidSupplier) ISpecialInsertion(logisticspipes.interfaces.ISpecialInsertion) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) PipeLogisticsChassi(logisticspipes.pipes.PipeLogisticsChassi) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ItemRoutingInformation(logisticspipes.routing.ItemRoutingInformation) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) LPTravelingItemServer(logisticspipes.transport.LPTravelingItem.LPTravelingItemServer)

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