Issue with Chemical Plants, "Read ingredients" circuit
Posted: Sun Dec 15, 2024 12:57 am
TL:DR;
When playing Factorio [Version: 2.0.23, Vanilla] with the new assembly machine + circuit mechanics, an issue arises for machines with multiple fluid inputs. If you try to build a circuit that uses the new "Read ingredients" option, it is ambiguous which fluid input it should go into. This cannot be sensed or determined with the circuit network directly. This causes issues when attempting to make a dynamic crafting system using one of these machines. I propose that recipes order their fluid inputs consistently with how the circuit network orders signals but also propose another solution.
What:
When a crafting machine with multiple fluid inputs is connected to a circuit network with the "Read ingredients" option enabled, there is no direct way to determine which input each fluid from a multi-fluid recipe is supposed to go into. This could affect any machine with multiple fluid inputs (and circuit connections):
In practice, this is only an issue (in vanilla) with the chemical plant's double-fluid recipes: Light oil cracking and heavy oil cracking. All three of the (vanilla) oil refinery recipes work with the following circuit, and match to the results of Light oil cracking. One way to approach such a machine is as shown below: Here, a chemical plant has the "Read ingredients" option selected and outputs it onto the red line. Then, the fluids are filtered (using the constant and arithmetic combinator), and output on the green line. This is indexed using the new Selector combinator, with an index of 1 on one, and 0 on the other. The resulting fluid is then displayed on the Display panel. It can be seen that the Light oil cracking is incorrect while the Heavy oil cracking is. You could reverse the indices of the Selector combinators, but then the heavy oil combinator would be wrong.
Why:
What does the circuit do: The circuit outputs the greatest value signal to the left, and least to the right.
What does the recipe/chemical plant do:
When a recipe is loaded for a type with a machine, the ingredients are in an array of 'ingredient' prototypes. The order of these changes which input the fluid required in. This can easily be seen with an example mod that introduces 'flipped' versions of two-fluid-input existing recipes.
Also arbitrary to players, but I would be interested to hear from a dev if there was a specific reason that the inputs are ordered like this) This disconnect leads to issues when trying to use the circuit network to control fluid inputs
How (I propose to fix it):
Follows are some proposed fixes, ranked by my preference (most to least preferred):
Before you comment one of these things, read why I am proposing my change, and not just doing one of the following.
When playing Factorio [Version: 2.0.23, Vanilla] with the new assembly machine + circuit mechanics, an issue arises for machines with multiple fluid inputs. If you try to build a circuit that uses the new "Read ingredients" option, it is ambiguous which fluid input it should go into. This cannot be sensed or determined with the circuit network directly. This causes issues when attempting to make a dynamic crafting system using one of these machines. I propose that recipes order their fluid inputs consistently with how the circuit network orders signals but also propose another solution.
What:
When a crafting machine with multiple fluid inputs is connected to a circuit network with the "Read ingredients" option enabled, there is no direct way to determine which input each fluid from a multi-fluid recipe is supposed to go into. This could affect any machine with multiple fluid inputs (and circuit connections):
- In the base game: Chemical plants and oil refineries
- In Space Age: Foundries, electromagnetic plants and cryogenic plants (Cannot confirm, I do not own Space Age. I would love to see a reply with results)
- In any mods: Any modded recipes with multiple fluid ingredients in vanilla machines
- In any modded machines with multiple fluid inputs.
In practice, this is only an issue (in vanilla) with the chemical plant's double-fluid recipes: Light oil cracking and heavy oil cracking. All three of the (vanilla) oil refinery recipes work with the following circuit, and match to the results of Light oil cracking. One way to approach such a machine is as shown below: Here, a chemical plant has the "Read ingredients" option selected and outputs it onto the red line. Then, the fluids are filtered (using the constant and arithmetic combinator), and output on the green line. This is indexed using the new Selector combinator, with an index of 1 on one, and 0 on the other. The resulting fluid is then displayed on the Display panel. It can be seen that the Light oil cracking is incorrect while the Heavy oil cracking is. You could reverse the indices of the Selector combinators, but then the heavy oil combinator would be wrong.
Why:
What does the circuit do: The circuit outputs the greatest value signal to the left, and least to the right.
- For Heavy oil cracking, the recipe consumes 40 heavy oil and 30 water, so heavy oil on the left and water on the right.
- For Light oil cracking, the recipe consumes 30 light oil and 30 water, since these are at the same value, they are ordered by the order property. This means that the water is on the left, and light oil on the right.[\list]
- For the two oil refinery recipes with two fluid inputs (Advanced oil processing and Coal liquefaction) have the ingredient needed in greater quantity on the right.
What does the recipe/chemical plant do:
When a recipe is loaded for a type with a machine, the ingredients are in an array of 'ingredient' prototypes. The order of these changes which input the fluid required in. This can easily be seen with an example mod that introduces 'flipped' versions of two-fluid-input existing recipes.
The mod, and results
In summary: a circuit network orders the signals based on the amount of ingredient, and then a property hidden to players (essentially arbitrary). The chemical plant (and other multi-fluid machines) orders the fluid inputs based on the order of the ingredients in the RecipePrototype. (How (I propose to fix it):
Follows are some proposed fixes, ranked by my preference (most to least preferred):
- Add a condition to the selector combinator for "Sort by recipe"/"Sort by fluid input order". Feeding the recipe and its ingredients into a selector combinator could allow it to "sort" these based on the prototype definition. This change does not add any entities and is only noticeable to those who use the circuit network to a detailed level. Seems like the least invasive solution.
-
In the factorio "/base/prototypes/recipe.lua", change the order of the Heavy oil cracking recipe, as it is the only one where the highest fluid in the "Read ingredient" signal is on the left instead of right. In the future (and someone with the Space Age DLC should check those buildings as well) this should be standardized in base game content. It could be possible that recipe loading of these could default to this behavior, as there is an option in FluidIngredientPrototype for overriding this behavior.This solution has been ruled out since there is a pretty good reason that the two multi-fluid recipes in the chemical plant are the way that they are. See this post. - Somehow detect which fluid is preferred in each input port with the circuit network. This could be in the machine itself, or letting the fluid preference propagate to tanks. The difficulty here is that machines already have issues with how many circuit conditions they have (~6) compared to the number wires that can be connected (2, but signals output by the machine are on both.) Perhaps multiple connection points, like combinators, on each fluid input? It seems like a large change for such a small fringe case, but this still allows for the freedom to arbirarily order fluid inputs in a recipe.
Before you comment one of these things, read why I am proposing my change, and not just doing one of the following.
- "Why not just make a mod to change the one vanilla recipe that is wrong?"
Because if I want to share a blueprint for a dynamic crafting chemical plant, it would not work without this mod. One of the big promises with the new circuit control is "All these things together should make it possible to make more generic assembler setups for those who like to dig deep into the automation of automation." That is all well and good for the assemblers, but the circuit control is clearly lacking for other machines (oil refinery, chemical plant, and furnace)
- "You know that you can flip the chemical plant, right?"
If you flip the chemical plant, it flips the fluid inputs for every recipe in it. Not just the offending one. And standing there and flipping the machine each time it changes recipe goes against the principal of automation. The double-edged sword on this argument, my first proposed solution is not technically a breaking change as you can just mirror the chemical plant in every Heavy oil cracking setup. - "Why not account for the edge case in circuitry?"
This is a good point actually. I have made a solution that uses two decider combinators and a constant combinator to hold the recipe. The problem with this is if the order of fluids in the recipe is truly arbitrarily chosen, then why not have it so that this is not even an issue? Of all 5 of the vanilla recipes that use two fluids, only one does this. Also having to identify these cases for any non-vanilla playthrough also seems pointless if the ordering of ingredients is arbitrary.