Search in sources :

Example 6 with ItemResource

use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.

the class ServerRouter method getRoutersInterestedIn.

public static BitSet getRoutersInterestedIn(IResource item) {
    if (item instanceof ItemResource) {
        return ServerRouter.getRoutersInterestedIn(((ItemResource) item).getItem());
    } else if (item instanceof FluidResource) {
        return ServerRouter.getRoutersInterestedIn(((FluidResource) item).getFluid().getItemIdentifier());
    } else if (item instanceof DictResource) {
        DictResource dict = (DictResource) item;
        BitSet s = new BitSet(ServerRouter.getBiggestSimpleID() + 1);
        for (IRouter r : ServerRouter.genericInterests) {
            s.set(r.getSimpleID());
        }
        ServerRouter.globalSpecificInterests.entrySet().stream().filter(entry -> dict.matches(entry.getKey(), IResource.MatchSettings.NORMAL)).flatMap(entry -> entry.getValue().stream()).forEach(router -> s.set(router.simpleID));
        return s;
    }
    return new BitSet(ServerRouter.getBiggestSimpleID() + 1);
}
Also used : PriorityQueue(java.util.PriorityQueue) LogisticsPipes(logisticspipes.LogisticsPipes) Quartet(logisticspipes.utils.tuples.Quartet) Particles(logisticspipes.pipefxhandlers.Particles) MainProxy(logisticspipes.proxy.MainProxy) ILogisticsPowerProvider(logisticspipes.api.ILogisticsPowerProvider) Configs(logisticspipes.config.Configs) StackTraceUtil(logisticspipes.utils.StackTraceUtil) LogisticsModule(logisticspipes.modules.LogisticsModule) Map(java.util.Map) ObjectSets(it.unimi.dsi.fastutil.objects.ObjectSets) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) EnumSet(java.util.EnumSet) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) EnumMap(java.util.EnumMap) FluidResource(logisticspipes.request.resources.FluidResource) CacheHolder(logisticspipes.utils.CacheHolder) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) NavigableSet(java.util.NavigableSet) LPTickHandler(logisticspipes.ticks.LPTickHandler) UUID(java.util.UUID) DictResource(logisticspipes.request.resources.DictResource) Collectors(java.util.stream.Collectors) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates) Info(logisticspipes.utils.StackTraceUtil.Info) List(java.util.List) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) Stream(java.util.stream.Stream) IFilter(logisticspipes.interfaces.routing.IFilter) Pair(logisticspipes.utils.tuples.Pair) Entry(java.util.Map.Entry) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) ItemResource(logisticspipes.request.resources.ItemResource) Getter(lombok.Getter) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ISubSystemPowerProvider(logisticspipes.interfaces.ISubSystemPowerProvider) IRoutingDebugAdapter(logisticspipes.interfaces.IRoutingDebugAdapter) BiConsumer(java.util.function.BiConsumer) LPTileEntityObject(logisticspipes.asm.te.LPTileEntityObject) PathFinder(logisticspipes.routing.pathfinder.PathFinder) OneList(logisticspipes.utils.OneList) WeakReference(java.lang.ref.WeakReference) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) DimensionManager(net.minecraftforge.common.DimensionManager) RoutingTableUpdateThread(logisticspipes.ticks.RoutingTableUpdateThread) ReentrantLock(java.util.concurrent.locks.ReentrantLock) World(net.minecraft.world.World) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IResource(logisticspipes.request.resources.IResource) Lock(java.util.concurrent.locks.Lock) PipeItemsFirewall(logisticspipes.pipes.PipeItemsFirewall) TileEntity(net.minecraft.tileentity.TileEntity) BitSet(java.util.BitSet) Collections(java.util.Collections) FluidResource(logisticspipes.request.resources.FluidResource) DictResource(logisticspipes.request.resources.DictResource) BitSet(java.util.BitSet) ItemResource(logisticspipes.request.resources.ItemResource)

Example 7 with ItemResource

use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.

the class RequestTree method request.

public static boolean request(List<ItemIdentifierStack> items, IRequestItems requester, RequestLog log, EnumSet<ActiveRequestType> requestFlags, IAdditionalTargetInformation info) {
    Map<IResource, Integer> messages = new HashMap<>();
    RequestTree tree = new RequestTree(new ItemResource(new ItemIdentifierStack(ItemIdentifier.get(Item.getItemFromBlock(Blocks.STONE), 0, null), 0), requester), null, requestFlags, info);
    boolean isDone = true;
    for (ItemIdentifierStack stack : items) {
        ItemIdentifier item = stack.getItem();
        Integer count = messages.get(item);
        if (count == null) {
            count = 0;
        }
        count += stack.getStackSize();
        ItemResource req = new ItemResource(stack, requester);
        messages.put(req, count);
        RequestTree node = new RequestTree(req, tree, requestFlags, info);
        isDone = isDone && node.isDone();
    }
    if (isDone) {
        LinkedLogisticsOrderList list = tree.fullFillAll();
        if (log != null) {
            log.handleSucessfullRequestOfList(RequestTreeNode.shrinkToList(messages), list);
        }
        return true;
    } else {
        if (log != null) {
            tree.logFailedRequestTree(log);
        }
        return false;
    }
}
Also used : LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) HashMap(java.util.HashMap) ItemIdentifierStack(logisticspipes.utils.item.ItemIdentifierStack) ItemResource(logisticspipes.request.resources.ItemResource) IResource(logisticspipes.request.resources.IResource)

Example 8 with ItemResource

use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.

the class PipeItemsProviderLogistics method canProvide.

@Override
public void canProvide(RequestTreeNode tree, RequestTree root, List<IFilter> filters) {
    if (!isEnabled()) {
        return;
    }
    if (tree.getRequestType() instanceof ItemResource) {
        ItemIdentifier item = ((ItemResource) tree.getRequestType()).getItem();
        for (IFilter filter : filters) {
            if (filter.isBlocked() == filter.isFilteredItem(item.getUndamaged()) || filter.blockProvider()) {
                return;
            }
        }
        // Check the transaction and see if we have helped already
        int canProvide = getAvailableItemCount(item);
        canProvide -= root.getAllPromissesFor(this, item);
        if (canProvide < 1) {
            return;
        }
        LogisticsPromise promise = new LogisticsPromise(item, Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
        tree.addPromise(promise);
    } else if (tree.getRequestType() instanceof DictResource) {
        DictResource dict = (DictResource) tree.getRequestType();
        HashMap<ItemIdentifier, Integer> available = new HashMap<>();
        getAllItems(available, filters);
        for (Entry<ItemIdentifier, Integer> item : available.entrySet()) {
            if (!dict.matches(item.getKey(), IResource.MatchSettings.NORMAL)) {
                continue;
            }
            int canProvide = getAvailableItemCount(item.getKey());
            canProvide -= root.getAllPromissesFor(this, item.getKey());
            if (canProvide < 1) {
                continue;
            }
            LogisticsPromise promise = new LogisticsPromise(item.getKey(), Math.min(canProvide, tree.getMissingAmount()), this, ResourceType.PROVIDER);
            tree.addPromise(promise);
            if (tree.getMissingAmount() <= 0) {
                break;
            }
        }
    }
}
Also used : ItemIdentifier(logisticspipes.utils.item.ItemIdentifier) Entry(java.util.Map.Entry) IFilter(logisticspipes.interfaces.routing.IFilter) HashMap(java.util.HashMap) LogisticsPromise(logisticspipes.routing.LogisticsPromise) DictResource(logisticspipes.request.resources.DictResource) ItemResource(logisticspipes.request.resources.ItemResource)

Example 9 with ItemResource

use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.

the class PipeItemsRequestLogistics method performRequest.

@Override
public List<ItemStack> performRequest(ItemStack wanted) {
    final List<IResource> missing = new ArrayList<>();
    RequestTree.request(ItemIdentifier.get(wanted).makeStack(wanted.stackSize), this, new RequestLog() {

        @Override
        public void handleMissingItems(List<IResource> items) {
            missing.addAll(items);
        }

        @Override
        public void handleSucessfullRequestOf(IResource item, LinkedLogisticsOrderList parts) {
        }

        @Override
        public void handleSucessfullRequestOfList(List<IResource> items, LinkedLogisticsOrderList parts) {
        }
    }, null);
    List<ItemStack> missingList = new ArrayList<>(missing.size());
    for (IResource e : missing) {
        if (e instanceof ItemResource) {
            missingList.add(((ItemResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        } else if (e instanceof DictResource) {
            missingList.add(((DictResource) e).getItem().unsafeMakeNormalStack(e.getRequestedAmount()));
        }
    }
    return missingList;
}
Also used : LinkedLogisticsOrderList(logisticspipes.routing.order.LinkedLogisticsOrderList) RequestLog(logisticspipes.request.RequestLog) ArrayList(java.util.ArrayList) DictResource(logisticspipes.request.resources.DictResource) ItemStack(net.minecraft.item.ItemStack) ItemResource(logisticspipes.request.resources.ItemResource) IResource(logisticspipes.request.resources.IResource)

Example 10 with ItemResource

use of logisticspipes.request.resources.ItemResource in project LogisticsPipes by RS485.

the class ModuleCrafter method extractFromLogisticsCraftingTable.

private ItemStack extractFromLogisticsCraftingTable(LogisticsCraftingTableTileEntity tile, IResource wanteditem, int count, ForgeDirection dir) {
    ItemStack extracted = extractFromIInventory(tile, wanteditem, count, dir);
    if (extracted != null) {
        return extracted;
    }
    ItemStack retstack = null;
    while (count > 0) {
        ItemStack stack = tile.getOutput(wanteditem, _service);
        if (stack == null || stack.stackSize == 0) {
            break;
        }
        if (retstack == null) {
            if (!wanteditem.matches(ItemIdentifier.get(stack), wanteditem instanceof ItemResource ? IResource.MatchSettings.WITHOUT_NBT : IResource.MatchSettings.NORMAL)) {
                break;
            }
        } else {
            if (!retstack.isItemEqual(stack)) {
                break;
            }
            if (!ItemStack.areItemStackTagsEqual(retstack, stack)) {
                break;
            }
        }
        if (!_service.useEnergy(neededEnergy() * stack.stackSize)) {
            break;
        }
        if (retstack == null) {
            retstack = stack;
        } else {
            retstack.stackSize += stack.stackSize;
        }
        count -= stack.stackSize;
        if (getUpgradeManager().isFuzzyUpgrade()) {
            break;
        }
    }
    return retstack;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemResource(logisticspipes.request.resources.ItemResource)

Aggregations

ItemResource (logisticspipes.request.resources.ItemResource)12 DictResource (logisticspipes.request.resources.DictResource)8 IResource (logisticspipes.request.resources.IResource)6 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)6 ItemStack (net.minecraft.item.ItemStack)6 ArrayList (java.util.ArrayList)4 Nonnull (javax.annotation.Nonnull)4 LinkedLogisticsOrderList (logisticspipes.routing.order.LinkedLogisticsOrderList)4 HashMap (java.util.HashMap)3 IPipeServiceProvider (logisticspipes.interfaces.IPipeServiceProvider)3 IFilter (logisticspipes.interfaces.routing.IFilter)3 ItemIdentifierStack (logisticspipes.utils.item.ItemIdentifierStack)3 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 IInventoryUtil (logisticspipes.interfaces.IInventoryUtil)2 IRequestItems (logisticspipes.interfaces.routing.IRequestItems)2 Particles (logisticspipes.pipefxhandlers.Particles)2