Better API for interacting with the crafting queue

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
Danielv123
Inserter
Inserter
Posts: 48
Joined: Sun Jan 03, 2016 10:28 am
Contact:

Better API for interacting with the crafting queue

Post by Danielv123 »

The current crafting queue API allows you to read the item type, item amount and order of items shown in the crafting queue GUI. But this does not include all the information the crafting system stores.

* Finished intermediate crafts are not shown at all
* There is no way to tell what is an intermediate craft vs final product without using ugly hacks

Here is the code required to read all the information from the crafting queue:

https://github.com/clusterio/clusterio/ ... crafts.lua

Basically, we cancel a craft and read what items we got back, and which items got removed from the crafting queue. This has to repeat until the entire queue is canceled. After that we reconstruct the queue.

This is just silly. There is also no way to preserve the crafting progess for the frontmost item when readding the craft.

https://lua-api.factorio.com/latest/Lua ... ting_queue
https://lua-api.factorio.com/latest/Con ... gQueueItem
https://lua-api.factorio.com/latest/Lua ... n_crafting

The current code works fine, but the reason for this interface request is that we would like to do this frequently in the background, and the current code could lead to lagspikes.

User avatar
_CodeGreen
Long Handed Inserter
Long Handed Inserter
Posts: 60
Joined: Sat Mar 05, 2022 11:30 am
Contact:

Re: Better API for interacting with the crafting queue

Post by _CodeGreen »

Bumping this because I'm also running into this issue.
I'm trying to read the crafting queue for which recipes are final recipe crafts, and doing the hacky workaround of cancelling all of the recipes backwards is so much more complicated than reading a value.

Something as simple as adding a boolean to the CraftingQueueItem class indicating whether or not it is an intermediate craft or a final craft should be very helpful and easy.
This can be added to the on_player_cancelled_crafting event as well, to differentiate between what you cancelled.

Also, there is no way to tell what other recipes are cancelled from cancelling an intermediate recipe, so maybe making on_player_cancelled_crafting fire for those recipes would help as well, but there's probably a better solution than I can think of for that.
My Mods | If you can't make it perfect, make it adjustable

Xorimuth
Filter Inserter
Filter Inserter
Posts: 624
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: Better API for interacting with the crafting queue

Post by Xorimuth »

Danielv123 wrote:
Sun Aug 15, 2021 12:44 pm
* There is no way to tell what is an intermediate craft vs final product without using ugly hacks
https://lua-api.factorio.com/latest/Con ... gQueueItem 'prerequisite' was added in 1.1.61.
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

Post Reply

Return to “Modding interface requests”