Friday Facts #394 - Assembler flipping and circuit control

Posted by kovarex, Josh on 2024-01-19

let me show you another dose of things we just can't stop ourselves from doing.

Assembling machine circuit controlkovarex

Being able to change the recipe of an assembling machine using circuit network is an obvious feature, and we considered it in the past.

The idea was always postponed, as we didn't see an easy way to solve the problem of potentially having unrelated items to deal with when the recipe was changed.
But, the solution is actually pretty easy, we just create a special "dump inventory" in the assembling machine and put the extra items there.

Assembling machine controlled to produce wooden chests right after it was producing electronic circuits.

The dump inventory is right next to the products, and can be removed from the assembling machine in the same way as the normal products. This means you have to be careful when creating designs which use the circuit network to set recipes, as you must ensure that you handle the leftover item output.

Another important part about setting the recipe, is that it will only check the 'Set recipe' signal when it finishes crafting, so it won't cancel any in-progress crafts, and you don't have to worry about precise timing.

Once we figured out how to handle setting the recipe, we could easily add some more utilities:

  • Enable/Disable - Simple on/off switch like a lot of circuit controls
  • Set recipe - Set the recipe of the assembler based on the incoming signals
  • Read ingredients - Outputs the ingredients and count required for the current recipe
  • Read recipe finished - A one tick signal emitted when a crafting cycle completes
  • Read working - Outputs a signal continuously while the assembler is crafting

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.

A 'Generic assembler' setup configured to craft high quality inserters from raw ingredients.

Flipping for realJosh

With the release of version 1.1 Blueprint Flipping was introduced, allowing you to flip a whole set of items horizontally or vertically before placing them (FFF-364). It came with some caveats however, many buildings with fluid inputs/outputs couldn't be flipped.

For most entities in the game, flipping them is simple. Mirror their position about the centre of the blueprint, then rotate 180 degrees if necessary, since if something is facing northwards then flipping horizontally has no effect on the direction. Repeat this for every item in a blueprint and you've got yourself a flipped blueprint.

There are some interesting caveats to this, like undergrounds, which you rarely want to actually turn around, since now the outputs would be facing each other, you generally want to just reverse the direction their belts travel. Splitters also need input and output priorities flipping. The flipped splitters in this image have opposite priorities, the left splitter has its priority as "left" and the right has its priority as "right" to achieve the same effect of prioritising items from the north.

There are some more complex cases that just don't work with this rotation method and therefore have to be blocked for now, like Oil Refineries. If you ask to flip a refinery, the blueprint will block you, because it just doesn't make sense, there is no way to rotate a refinery into a flipped state. At best your fluid setup wouldn't work, at worst you would now be mixing fluids like this (notice the steam pipes now lead to the oil inputs on the copied refinery):

The only proper solution is to flip for real. Actually flip the building about an axis to produce a mirrored result so that the inputs and outputs are where you might expect them to be. This is easier said than done though, the pipes still have to line up with the connection points on the building itself or we end up in even weirder territory of fluids going into walls. There needed to be limits on how buildings could flip.

After a lot of doodling on graph paper to visualise all the options, I ended up only allowing buildings to flip over their line of symmetry, so all inputs and outputs would still match once flipped. If a building doesn't have any symmetry, it still can't be flipped as there's nowhere for the pipe to go on the other side of the building (looking at you Pumpjack).

The Oil Refinery has horizontal symmetry, so you can flip all the coordinates of the inputs and outputs over the vertical axis and still land on a usable pipe connection. Those of you who remember your high school geometry will realise that to perform a vertical flip, you can mirror horizontally, then perform a 180 degree rotation to get the same result. So every building only needs one line of symmetry to be mirrored, and can then be rotated to suit. With the pipe connections mirrored the fluid inputs/outputs now match what the flipped pipe setup needs.

The available symmetry for each building is detected automatically when the game loads, so mods can make use of this feature without changing anything too. If their buildings have symmetry of their fluid connections, they can be flipped. So I could finally tidy up some of the builds on my Space Exploration playthrough.
That's when I stumbled into:

The Final Boss

This is the Space Manufactory from the Space Exploration mod. It has 12 pipe connections and only diagonal symmetry. It had me back to pen and paper scratching at corners of my brain I haven't used for a while. Flipping over a diagonal doesn't just move the position, it also rotates by 90 degrees, throwing off all my current code that could reliably just rotate 180 degrees. After some mild weeping I began reworking large chunks of code to take into account a direction adjustment when diagonal symmetry was in play.

Eventually it worked again and I could bask in nice, clean, back to back, mirrored builds.

Now that flipping is working on all buildings and items we decided it was worth expanding that to everywhere you might want to flip something (not just when holding a blueprint):

  • Hovering over a building and pressing F or G
  • Flipping something in your hand before you place it
  • When copy and pasting from one machine to another (though this won't change the direction, just the flipped nature of the pipe connections)

In this way Flipping becomes a first class operation alongside things like rotate, in that you should be able to use it anywhere that feels natural and have it do a sensible thing.

Stack Vs. Bulk inserterKlonan

After last weeks FFF there was a lot of discussion about the naming of Stack inserters and Bulk inserters. In short, it makes no sense that Stack inserters don't stack items on belts and Bulk inserters do stack items on belts.

And we tend to agree, normally we try not to change too much when we are adding new features, but in this case it just makes it too confusing.
So in 2.0, Stack inserters will be renamed to Bulk inserters, and the new inserter which can place stacks of items on belts, will take the name of Stack inserter.

As always, flip your thoughts onto us at the usual places.