Search in sources :

Example 6 with ItemIdentifier

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

the class ModuleCrafter method extractFromIInventoryFiltered.

private ItemStack extractFromIInventoryFiltered(IInventory inv, ItemIdentifierInventory filter, boolean isExcluded, int filterInvLimit, ForgeDirection dir) {
    IInventoryUtil invUtil = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(inv, dir);
    ItemIdentifier wanteditem = null;
    for (ItemIdentifier item : invUtil.getItemsAndCount().keySet()) {
        if (isExcluded) {
            boolean found = false;
            for (int i = 0; i < filter.getSizeInventory() && i < filterInvLimit; i++) {
                ItemIdentifierStack identStack = filter.getIDStackInSlot(i);
                if (identStack == null) {
                    continue;
                }
                if (identStack.getItem().equalsWithoutNBT(item)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                wanteditem = item;
            }
        } else {
            boolean found = false;
            for (int i = 0; i < filter.getSizeInventory() && i < filterInvLimit; i++) {
                ItemIdentifierStack identStack = filter.getIDStackInSlot(i);
                if (identStack == null) {
                    continue;
                }
                if (identStack.getItem().equalsWithoutNBT(item)) {
                    found = true;
                    break;
                }
            }
            if (found) {
                wanteditem = item;
            }
        }
    }
    if (wanteditem == null) {
        return null;
    }
    int available = invUtil.itemCount(wanteditem);
    if (available == 0) {
        return null;
    }
    if (!_service.useEnergy(neededEnergy() * Math.min(64, available))) {
        return null;
    }
    return invUtil.getMultipleItems(wanteditem, Math.min(64, available));
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack)

Example 7 with ItemIdentifier

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

the class ModuleCrafter method spaceFor.

protected int spaceFor(ItemIdentifier item, boolean includeInTransit) {
    Pair<String, ItemIdentifier> key = new Pair<>("spaceFor", item);
    Object cache = _service.getCacheHolder().getCacheFor(CacheTypes.Inventory, key);
    if (cache != null) {
        int count = (Integer) cache;
        if (includeInTransit) {
            count -= _service.countOnRoute(item);
        }
        return count;
    }
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(getWorld(), _service.getX(), _service.getY(), _service.getZ());
    //@formatter:off
    int count = worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IInventory).map(adjacent -> new Pair<>((IInventory) adjacent.tileEntity, adjacent.direction)).map(invDirPair -> {
        if (invDirPair.getValue1() instanceof ISidedInventory) {
            invDirPair.setValue1(new SidedInventoryMinecraftAdapter((ISidedInventory) invDirPair.getValue1(), invDirPair.getValue2().getOpposite(), false));
        }
        if (getUpgradeManager().hasSneakyUpgrade()) {
            invDirPair.setValue2(getUpgradeManager().getSneakyOrientation());
        }
        IInventoryUtil inv = SimpleServiceLocator.inventoryUtilFactory.getInventoryUtil(invDirPair.getValue1(), invDirPair.getValue2());
        return inv.roomForItem(item, 9999);
    }).reduce(Integer::sum).orElse(0);
    _service.getCacheHolder().setCache(CacheTypes.Inventory, key, count);
    if (includeInTransit) {
        count -= _service.countOnRoute(item);
    }
    return count;
}
Also used : IInventory(net.minecraft.inventory.IInventory) FluidCraftingPipeAdvancedSatellitePrevPacket(logisticspipes.network.packets.pipe.FluidCraftingPipeAdvancedSatellitePrevPacket) CraftingPipeNextAdvancedSatellitePacket(logisticspipes.network.packets.block.CraftingPipeNextAdvancedSatellitePacket) CPipeSatelliteImportBack(logisticspipes.network.packets.cpipe.CPipeSatelliteImportBack) CraftingAdvancedSatelliteId(logisticspipes.network.packets.cpipe.CraftingAdvancedSatelliteId) Constants(net.minecraftforge.common.util.Constants) MainProxy(logisticspipes.proxy.MainProxy) FluidCraftingAmount(logisticspipes.network.packets.pipe.FluidCraftingAmount) SinkReply(logisticspipes.utils.SinkReply) Block(net.minecraft.block.Block) HUDStopModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStopModuleWatchingPacket) ItemCraftingTemplate(logisticspipes.request.ItemCraftingTemplate) Map(java.util.Map) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) CPipeSatelliteId(logisticspipes.network.packets.cpipe.CPipeSatelliteId) FluidCraftingAdvancedSatelliteId(logisticspipes.network.packets.pipe.FluidCraftingAdvancedSatelliteId) NewGuiHandler(logisticspipes.network.NewGuiHandler) SideOnly(cpw.mods.fml.relauncher.SideOnly) CPipeNextSatellite(logisticspipes.network.packets.cpipe.CPipeNextSatellite) FluidCraftingPipeAdvancedSatelliteNextPacket(logisticspipes.network.packets.pipe.FluidCraftingPipeAdvancedSatelliteNextPacket) LogisticsExtraPromise(logisticspipes.routing.LogisticsExtraPromise) LogisticsManager(logisticspipes.logistics.LogisticsManager) LogisticsGuiModule(logisticspipes.modules.abstractmodules.LogisticsGuiModule) Set(java.util.Set) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ExitRoute(logisticspipes.routing.ExitRoute) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) IFilter(logisticspipes.interfaces.routing.IFilter) LogisticsCraftingTableTileEntity(logisticspipes.blocks.crafting.LogisticsCraftingTableTileEntity) BufferMode(logisticspipes.utils.SinkReply.BufferMode) ICraftingRecipeProvider(logisticspipes.proxy.interfaces.ICraftingRecipeProvider) CraftingModuleInHand(logisticspipes.network.guis.module.inhand.CraftingModuleInHand) CraftingPipeOpenConnectedGuiPacket(logisticspipes.network.packets.cpipe.CraftingPipeOpenConnectedGuiPacket) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) CraftingModuleSlot(logisticspipes.network.guis.module.inpipe.CraftingModuleSlot) IWorldProvider(logisticspipes.interfaces.IWorldProvider) LogisticsDictPromise(logisticspipes.routing.LogisticsDictPromise) World(net.minecraft.world.World) CraftingPipePrevAdvancedSatellitePacket(logisticspipes.network.packets.block.CraftingPipePrevAdvancedSatellitePacket) LogisticsItemOrder(logisticspipes.routing.order.LogisticsItemOrder) CraftingPipePriorityDownPacket(logisticspipes.network.packets.pipe.CraftingPipePriorityDownPacket) LogisticsExtraDictPromise(logisticspipes.routing.LogisticsExtraDictPromise) DelayedGeneric(logisticspipes.utils.DelayedGeneric) ItemSendMode(logisticspipes.pipes.basic.CoreRoutedPipe.ItemSendMode) CPipeSatelliteImport(logisticspipes.network.packets.cpipe.CPipeSatelliteImport) AdjacentTileEntity(network.rs485.logisticspipes.world.WorldCoordinatesWrapper.AdjacentTileEntity) IIcon(net.minecraft.util.IIcon) HUDStartModuleWatchingPacket(logisticspipes.network.packets.hud.HUDStartModuleWatchingPacket) IResource(logisticspipes.request.resources.IResource) ChassiTargetInformation(logisticspipes.pipes.PipeLogisticsChassi.ChassiTargetInformation) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) TileEntity(net.minecraft.tileentity.TileEntity) ItemBlock(net.minecraft.item.ItemBlock) IRoutedItem(logisticspipes.logisticspipes.IRoutedItem) ModuleInHandGuiProvider(logisticspipes.network.abstractguis.ModuleInHandGuiProvider) PipeItemsSatelliteLogistics(logisticspipes.pipes.PipeItemsSatelliteLogistics) IRouter(logisticspipes.routing.IRouter) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) ItemUpgrade(logisticspipes.items.ItemUpgrade) LogisticsModule(logisticspipes.modules.abstractmodules.LogisticsModule) ICraftingTemplate(logisticspipes.request.ICraftingTemplate) Particles(logisticspipes.pipefxhandlers.Particles) PlayerCollectionList(logisticspipes.utils.PlayerCollectionList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DictCraftingTemplate(logisticspipes.request.DictCraftingTemplate) NBTTagList(net.minecraft.nbt.NBTTagList) FluidIdentifier(logisticspipes.utils.FluidIdentifier) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) ICraftItems(logisticspipes.interfaces.routing.ICraftItems) IAdditionalTargetInformation(logisticspipes.interfaces.routing.IAdditionalTargetInformation) IIconRegister(net.minecraft.client.renderer.texture.IIconRegister) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ModernPacket(logisticspipes.network.abstractpackets.ModernPacket) Side(cpw.mods.fml.relauncher.Side) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) FluidResource(logisticspipes.request.resources.FluidResource) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) IFuzzyRecipeProvider(logisticspipes.proxy.interfaces.IFuzzyRecipeProvider) RequestTreeNode(logisticspipes.request.RequestTreeNode) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) TransportMode(logisticspipes.logisticspipes.IRoutedItem.TransportMode) IItemSpaceControl(logisticspipes.interfaces.routing.IItemSpaceControl) List(java.util.List) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) CacheTypes(logisticspipes.utils.CacheHolder.CacheTypes) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IHUDModuleHandler(logisticspipes.interfaces.IHUDModuleHandler) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IPromise(logisticspipes.request.IPromise) PipeItemsCraftingLogistics(logisticspipes.pipes.PipeItemsCraftingLogistics) ItemResource(logisticspipes.request.resources.ItemResource) Getter(lombok.Getter) ModuleCoordinatesGuiProvider(logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider) CPipePrevSatellite(logisticspipes.network.packets.cpipe.CPipePrevSatellite) IPipeServiceProvider(logisticspipes.interfaces.IPipeServiceProvider) IReqCraftingTemplate(logisticspipes.request.IReqCraftingTemplate) ResourceType(logisticspipes.routing.order.IOrderInfoProvider.ResourceType) CoordinatesPacket(logisticspipes.network.abstractpackets.CoordinatesPacket) IRequestItems(logisticspipes.interfaces.routing.IRequestItems) CraftingPipePriorityUpPacket(logisticspipes.network.packets.pipe.CraftingPipePriorityUpPacket) IModuleWatchReciver(logisticspipes.interfaces.IModuleWatchReciver) ISlotUpgradeManager(logisticspipes.interfaces.ISlotUpgradeManager) DelayQueue(java.util.concurrent.DelayQueue) WeakReference(java.lang.ref.WeakReference) PipeFluidSatellite(logisticspipes.pipes.PipeFluidSatellite) CraftingPriority(logisticspipes.network.packets.pipe.CraftingPriority) IHUDModuleRenderer(logisticspipes.interfaces.IHUDModuleRenderer) FixedPriority(logisticspipes.utils.SinkReply.FixedPriority) CraftingPipeUpdatePacket(logisticspipes.network.packets.pipe.CraftingPipeUpdatePacket) LogisticsPromise(logisticspipes.routing.LogisticsPromise) RequestTree(logisticspipes.request.RequestTree) ISidedInventory(net.minecraft.inventory.ISidedInventory) IInventory(net.minecraft.inventory.IInventory) SidedInventoryMinecraftAdapter(logisticspipes.utils.SidedInventoryMinecraftAdapter) IInventoryUtil(logisticspipes.interfaces.IInventoryUtil) ISidedInventory(net.minecraft.inventory.ISidedInventory) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Pair(logisticspipes.utils.tuples.Pair)

Example 8 with ItemIdentifier

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

the class LogisticsManager method getAvailableItems.

/**
	 * @param validDestinations
	 *            a list of ExitRoute of valid destinations.
	 * @return HashMap with ItemIdentifier and Integer item count of available
	 *         items.
	 */
@Override
public HashMap<ItemIdentifier, Integer> getAvailableItems(List<ExitRoute> validDestinations) {
    //TODO: Replace this entire function wiht a fetch from the pre-built arrays (path incoming later)
    List<Map<ItemIdentifier, Integer>> items = new ArrayList<>(ServerRouter.getBiggestSimpleID());
    for (int i = 0; i < ServerRouter.getBiggestSimpleID(); i++) {
        items.add(new HashMap<>());
    }
    BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
    outer: for (ExitRoute r : validDestinations) {
        if (r == null) {
            continue;
        }
        if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            continue;
        }
        if (!(r.destination.getPipe() instanceof IProvideItems)) {
            continue;
        }
        for (IFilter filter : r.filters) {
            if (filter.blockProvider()) {
                continue outer;
            }
        }
        IProvideItems provider = (IProvideItems) r.destination.getPipe();
        provider.getAllItems(items.get(r.destination.getSimpleID()), r.filters);
        used.set(r.destination.getSimpleID(), true);
    }
    //TODO: Fix this doubly nested list
    HashMap<ItemIdentifier, Integer> allAvailableItems = new HashMap<>();
    for (Map<ItemIdentifier, Integer> allItems : items) {
        for (Entry<ItemIdentifier, Integer> item : allItems.entrySet()) {
            Integer currentItem = allAvailableItems.get(item.getKey());
            if (currentItem == null) {
                allAvailableItems.put(item.getKey(), item.getValue());
            } else {
                allAvailableItems.put(item.getKey(), currentItem + item.getValue());
            }
        }
    }
    return allAvailableItems;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IFilter(logisticspipes.interfaces.routing.IFilter) ExitRoute(logisticspipes.routing.ExitRoute) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with ItemIdentifier

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

the class LogisticsManager method getAmountFor.

@Override
public int getAmountFor(ItemIdentifier itemType, List<ExitRoute> validDestinations) {
    // TODO: Replace this entire function wiht a fetch from the pre-built arrays (path incoming later)
    List<Map<ItemIdentifier, Integer>> items = new ArrayList<>(ServerRouter.getBiggestSimpleID());
    for (int i = 0; i < ServerRouter.getBiggestSimpleID(); i++) {
        items.add(new HashMap<>());
    }
    BitSet used = new BitSet(ServerRouter.getBiggestSimpleID());
    outer: for (ExitRoute r : validDestinations) {
        if (r == null) {
            continue;
        }
        if (!r.containsFlag(PipeRoutingConnectionType.canRequestFrom)) {
            continue;
        }
        if (!(r.destination.getPipe() instanceof IProvideItems)) {
            continue;
        }
        for (IFilter filter : r.filters) {
            if (filter.blockProvider()) {
                continue outer;
            }
        }
        IProvideItems provider = (IProvideItems) r.destination.getPipe();
        provider.getAllItems(items.get(r.destination.getSimpleID()), r.filters);
        used.set(r.destination.getSimpleID(), true);
    }
    // TODO: Fix this doubly nested list
    int amount = 0;
    for (Map<ItemIdentifier, Integer> allItems : items) {
        for (Entry<ItemIdentifier, Integer> item : allItems.entrySet()) {
            if (item.getKey().equals(itemType)) {
                amount += item.getValue();
            }
        }
    }
    return amount;
}
Also used : ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) IProvideItems(logisticspipes.interfaces.routing.IProvideItems) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) IFilter(logisticspipes.interfaces.routing.IFilter) ExitRoute(logisticspipes.routing.ExitRoute) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with ItemIdentifier

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

the class ModuleActiveSupplier method addStatusInformation.

public void addStatusInformation(List<StatusEntry> status) {
    StatusEntry entry = new StatusEntry();
    entry.name = "Requested Items";
    entry.subEntry = new ArrayList<>();
    for (Entry<ItemIdentifier, Integer> part : _requestedItems.entrySet()) {
        StatusEntry subEntry = new StatusEntry();
        subEntry.name = part.toString();
        entry.subEntry.add(subEntry);
    }
    status.add(entry);
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) StatusEntry(logisticspipes.pipes.basic.debug.StatusEntry)

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