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.
Better API for interacting with the crafting queue
-
- Inserter
- Posts: 48
- Joined: Sun Jan 03, 2016 10:28 am
- Contact:
- _CodeGreen
- Long Handed Inserter
- Posts: 72
- Joined: Sat Mar 05, 2022 11:30 am
- Contact:
Re: Better API for interacting with the crafting queue
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.
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
Re: Better API for interacting with the crafting queue
https://lua-api.factorio.com/latest/Con ... gQueueItem 'prerequisite' was added in 1.1.61.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
My mods
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings
Content: Lunar Landings | Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings