Page 1 of 1

Better API for interacting with the crafting queue

Posted: Sun Aug 15, 2021 12:44 pm
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.

Re: Better API for interacting with the crafting queue

Posted: Sat May 07, 2022 3:52 pm
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.

Re: Better API for interacting with the crafting queue

Posted: Sun Jun 26, 2022 1:13 am
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.