Search in sources :

Example 11 with IInventoryUtil

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

the class PipeItemsProviderLogistics method sendStack.

private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
    ItemIdentifier item = stack.getItem();
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
    //@formatter:off
    Iterator<Pair<IInventoryUtil, ForgeDirection>> iterator = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> !SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>(getAdaptedInventoryUtil(adjacent), adjacent.direction)).iterator();
    while (iterator.hasNext()) {
        Pair<IInventoryUtil, ForgeDirection> next = iterator.next();
        int available = next.getValue1().itemCount(item);
        if (available == 0) {
            continue;
        }
        int wanted = Math.min(available, stack.getStackSize());
        wanted = Math.min(wanted, maxCount);
        wanted = Math.min(wanted, item.getMaxStackSize());
        IRouter dRtr = SimpleServiceLocator.routerManager.getRouterUnsafe(destination, false);
        if (dRtr == null) {
            _orderManager.sendFailed();
            return 0;
        }
        SinkReply reply = LogisticsManager.canSink(dRtr, null, true, stack.getItem(), null, true, false);
        boolean defersend = false;
        if (reply != null) {
            // some pipes are not aware of the space in the adjacent inventory, so they return null
            if (reply.maxNumberOfItems < wanted) {
                wanted = reply.maxNumberOfItems;
                if (wanted <= 0) {
                    _orderManager.deferSend();
                    return 0;
                }
                defersend = true;
            }
        }
        if (!canUseEnergy(wanted * neededEnergy())) {
            return -1;
        }
        ItemStack removed = next.getValue1().getMultipleItems(item, wanted);
        if (removed == null || removed.stackSize == 0) {
            continue;
        }
        int sent = removed.stackSize;
        useEnergy(sent * neededEnergy());
        IRoutedItem routedItem = SimpleServiceLocator.routedItemHelper.createNewTravelItem(removed);
        routedItem.setDestination(destination);
        routedItem.setTransportMode(TransportMode.Active);
        routedItem.setAdditionalTargetInformation(info);
        super.queueRoutedItem(routedItem, next.getValue2());
        _orderManager.sendSuccessfull(sent, defersend, routedItem);
        return sent;
    }
    _orderManager.sendFailed();
    return 0;
}
Also used : IRouter(logisticspipes.routing.IRouter) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Textures(logisticspipes.textures.Textures) Item(net.minecraft.item.Item) LogisticsPipes(logisticspipes.LogisticsPipes) ProviderPipeInclude(logisticspipes.network.packets.modules.ProviderPipeInclude) Particles(logisticspipes.pipefxhandlers.Particles) ChestContent(logisticspipes.network.packets.hud.ChestContent) MainProxy(logisticspipes.proxy.MainProxy) IHeadUpDisplayRenderer(logisticspipes.interfaces.IHeadUpDisplayRenderer) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) HUDStartWatchingPacket(logisticspipes.network.packets.hud.HUDStartWatchingPacket) SinkReply(logisticspipes.utils.SinkReply) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) Map(java.util.Map) ModuleProvider(logisticspipes.modules.ModuleProvider) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IChangeListener(logisticspipes.interfaces.IChangeListener) HUDStopWatchingPacket(logisticspipes.network.packets.hud.HUDStopWatchingPacket) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsManager(logisticspipes.logistics.LogisticsManager) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) Set(java.util.Set) PacketHandler(logisticspipes.network.PacketHandler) RequestTreeNode(logisticspipes.request.RequestTreeNode) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IChestContentReceiver(logisticspipes.interfaces.IChestContentReceiver) IFilter(logisticspipes.interfaces.routing.IFilter) OrdererManagerContent(logisticspipes.network.packets.orderer.OrdererManagerContent) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) GuiIDs(logisticspipes.network.GuiIDs) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ItemResource(logisticspipes.request.resources.ItemResource) LogisticsOrder(logisticspipes.routing.order.LogisticsOrder) HashMap(java.util.HashMap) HUDProvider(logisticspipes.gui.hud.HUDProvider) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) IHeadUpDisplayRendererProvider(logisticspipes.interfaces.IHeadUpDisplayRendererProvider) ExtractionMode(logisticspipes.logisticspipes.ExtractionMode) LogisticsItemOrderManager(logisticspipes.routing.order.LogisticsItemOrderManager) LinkedList(java.util.LinkedList) Iterator(java.util.Iterator) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) LogisticsPromise(logisticspipes.routing.LogisticsPromise) TextureType(logisticspipes.textures.Textures.TextureType) RequestTree(logisticspipes.request.RequestTree) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) IResource(logisticspipes.request.resources.IResource) TreeMap(java.util.TreeMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ProviderPipeMode(logisticspipes.network.packets.modules.ProviderPipeMode) IInventory(net.minecraft.inventory.IInventory) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IOrderManagerContentReceiver(logisticspipes.interfaces.IOrderManagerContentReceiver) IInventory(net.minecraft.inventory.IInventory) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) ItemStack(net.minecraft.item.ItemStack) Pair(logisticspipes.utils.tuples.Pair)

Example 12 with IInventoryUtil

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

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

the class ModuleActiveSupplier method tick.

@Override
public void tick() {
    if (!_service.isNthTick(100)) {
        return;
    }
    _requestedItems.values().stream().filter(amount -> amount > 0).forEach(amount -> _service.spawnParticle(Particles.VioletParticle, 2));
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(_world.getWorld(), getX(), getY(), getZ());
    //@formatter:off
    worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).filter(adjacent -> ((IInventory) adjacent.tileEntity).getSizeInventory() > 0).forEach(adjacent -> {
        ForgeDirection direction = adjacent.direction;
        if (_service.getUpgradeManager(slot, positionInt).hasSneakyUpgrade()) {
            direction = _service.getUpgradeManager(slot, positionInt).getSneakyOrientation();
        }
        IInventoryUtil invUtil = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil((IInventory) adjacent.tileEntity, direction);
        if (_service.getUpgradeManager(slot, positionInt).hasPatternUpgrade()) {
            createPatternRequest(invUtil);
        } else {
            createSupplyRequest(invUtil);
        }
    });
}
Also used : ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) IRouter(logisticspipes.routing.IRouter) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) Particles(logisticspipes.pipefxhandlers.Particles) ActiveSupplierInHand(logisticspipes.network.guis.module.inhand.ActiveSupplierInHand) MainProxy(logisticspipes.proxy.MainProxy) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) IRequireReliableTransport(logisticspipes.interfaces.routing.IRequireReliableTransport) SinkReply(logisticspipes.utils.SinkReply) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) Map(java.util.Map) ITargetSlotInformation(logisticspipes.interfaces.routing.ITargetSlotInformation) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) IIconRegister(net.minecraft.client.renderer.texture.IIconRegister) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NewGuiHandler(logisticspipes.network.NewGuiHandler) Side(cpw.mods.fml.relauncher.Side) SideOnly(cpw.mods.fml.relauncher.SideOnly) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) Collection(java.util.Collection) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) LogisticsGuiModule(logisticspipes.modules.abstractmodules.LogisticsGuiModule) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IModuleInventoryReceive(logisticspipes.interfaces.IModuleInventoryReceive) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Entry(java.util.Map.Entry) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Setter(lombok.Setter) Getter(lombok.Getter) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) IClientInformationProvider(logisticspipes.interfaces.IClientInformationProvider) StatusEntry(logisticspipes.pipes.basic.debug.StatusEntry) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) ActiveSupplierSlot(logisticspipes.network.guis.module.inpipe.ActiveSupplierSlot) Iterator(java.util.Iterator) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) RequestTree(logisticspipes.request.RequestTree) IIcon(net.minecraft.util.IIcon) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) ISimpleInventoryEventHandler(logisticspipes.utils.ISimpleInventoryEventHandler) ModuleInventory(logisticspipes.network.packets.module.ModuleInventory) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) IInventory(net.minecraft.inventory.IInventory) IInventory(net.minecraft.inventory.IInventory) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper)

Example 14 with IInventoryUtil

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

the class ModulePassiveSupplier method sinksItem.

@Override
public SinkReply sinksItem(ItemIdentifier item, int bestPriority, int bestCustomPriority, boolean allowDefault, boolean includeInTransit) {
    if (bestPriority > _sinkReply.fixedPriority.ordinal() || (bestPriority == _sinkReply.fixedPriority.ordinal() && bestCustomPriority >= _sinkReply.customPriority)) {
        return null;
    }
    IInventoryUtil targetUtil = _service.getSneakyInventory(false, slot, positionInt);
    if (targetUtil == null) {
        return null;
    }
    if (!_filterInventory.containsItem(item)) {
        return null;
    }
    int targetCount = _filterInventory.itemCount(item);
    int haveCount = targetUtil.itemCount(item);
    if (targetCount <= haveCount) {
        return null;
    }
    if (_service.canUseEnergy(2)) {
        return new SinkReply(_sinkReply, targetCount - haveCount);
    }
    return null;
}
Also used : SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil)

Example 15 with IInventoryUtil

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

the class ModuleProvider method sendStack.

// returns -1 on permanently failed, don't try another stack this tick
// returns 0 on "unable to do this delivery"
private int sendStack(ItemIdentifierStack stack, int maxCount, int destination, IAdditionalTargetInformation info) {
    ItemIdentifier item = stack.getItem();
    IInventoryUtil inv = _service.getPointedInventory(_extractionMode, true);
    if (inv == null) {
        _service.getItemOrderManager().sendFailed();
        return 0;
    }
    int available = inv.itemCount(item);
    if (available == 0) {
        _service.getItemOrderManager().sendFailed();
        return 0;
    }
    int wanted = Math.min(available, stack.getStackSize());
    wanted = Math.min(wanted, maxCount);
    wanted = Math.min(wanted, item.getMaxStackSize());
    IRouter dRtr = SimpleServiceLocator.routerManager.getRouterUnsafe(destination, false);
    if (dRtr == null) {
        _service.getItemOrderManager().sendFailed();
        return 0;
    }
    SinkReply reply = LogisticsManager.canSink(dRtr, null, true, stack.getItem(), null, true, false);
    boolean defersend = false;
    if (reply != null) {
        // some pipes are not aware of the space in the adjacent inventory, so they return null
        if (reply.maxNumberOfItems < wanted) {
            wanted = reply.maxNumberOfItems;
            if (wanted <= 0) {
                _service.getItemOrderManager().deferSend();
                return 0;
            }
            defersend = true;
        }
    }
    if (!_service.canUseEnergy(wanted * neededEnergy())) {
        return -1;
    }
    ItemStack removed = inv.getMultipleItems(item, wanted);
    if (removed == null || removed.stackSize == 0) {
        _service.getItemOrderManager().sendFailed();
        return 0;
    }
    int sent = removed.stackSize;
    _service.useEnergy(sent * neededEnergy());
    IRoutedItem sendedItem = _service.sendStack(removed, destination, itemSendMode(), info);
    _service.getItemOrderManager().sendSuccessfull(sent, defersend, sendedItem);
    return sent;
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) IRouter(logisticspipes.routing.IRouter) SinkReply(logisticspipes.utils.SinkReply) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) 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