Factorio crafting graph

from Red Blob Games
26 Apr 2020

Table of Contents

A few years ago I looked at crafting graphs[1] for Minecraft. I’ve been playing modded Factorio lately and wanted to see what the graph looked like in Factorio. The main mods are Krastorio2 and Space Exploration, but there are a bunch of others thrown in there too.

I ran Factorio and exported the recipes (type: LuaRecipePrototype[2]) to factorio-recipes.txt.

/c
lines = {}
for k, v in pairs(game.recipe_prototypes) do
  table.insert(lines, serpent.line({name=v.name, group=v.group.name, subgroup=v.subgroup.name, ingredients=v.ingredients, products=v.products}))
end
game.write_file("factorio-recipes.txt", table.concat(lines, "\n"))

I then hackily converted this to factorio-recipes.json:

echo '[' >build/factorio-recipes.json
perl -p -e 's/ = /: /g;' -e 's/{{/[{/g;' -e 's/}}/}]/g;' -e 's/$/,/;' -e 's/(\w+):/"\1":/g' <factorio-recipes.txt >>build/factorio-recipes.json
echo '{}]' >>build/factorio-recipes.json

Now I want to convert it to graphviz format. I tried rendering one category at a time with viz.js[3] but it was kind of slow for some categories so I decided it’d be better to do it offline and save it to images.

node factorio-crafting-graph.js >build/factorio-crafting-graph.html

 1  Output#

fluid-filtration#

Category fluid-filtration has 4 recipes - vert - horiz - fdp

space-astrometrics#

Category space-astrometrics has 10 recipes - vert - horiz - fdp

space-supercomputing-1#

Category space-supercomputing-1 has 32 recipes - vert - horiz - fdp

space-supercomputing-2#

Category space-supercomputing-2 has 9 recipes - vert - horiz - fdp

space-supercomputing-3#

Category space-supercomputing-3 has 9 recipes - vert - horiz - fdp

space-growth#

Category space-growth has 7 recipes - vert - horiz - fdp

space-biochemical#

Category space-biochemical has 11 recipes - vert - horiz - fdp

space-decontamination#

Category space-decontamination has 5 recipes - vert - horiz - fdp

space-accelerator#

Category space-accelerator has 4 recipes - vert - horiz - fdp

space-materialisation#

Category space-materialisation has 8 recipes - vert - horiz - fdp

space-recycling#

Category space-recycling has 6 recipes - vert - horiz - fdp

space-thermodynamics#

Category space-thermodynamics has 9 recipes - vert - horiz - fdp

crafting#

skipped for size: 472

crafting-with-fluid#

Category crafting-with-fluid has 91 recipes - vert - horiz - fdp

condenser-turbine#

Category condenser-turbine has 1 recipes - vert - horiz - fdp

spaceship-antimatter-engine#

Category spaceship-antimatter-engine has 1 recipes - vert - horiz - fdp

spaceship-rocket-engine#

Category spaceship-rocket-engine has 1 recipes - vert - horiz - fdp

space-electromagnetics#

Category space-electromagnetics has 13 recipes - vert - horiz - fdp

space-manufacturing#

Category space-manufacturing has 41 recipes - vert - horiz - fdp

space-spectrometry#

Category space-spectrometry has 4 recipes - vert - horiz - fdp

space-genetics#

Category space-genetics has 6 recipes - vert - horiz - fdp

space-observation-radio#

Category space-observation-radio has 1 recipes - vert - horiz - fdp

space-mechanical#

Category space-mechanical has 8 recipes - vert - horiz - fdp

space-observation-microwave#

Category space-observation-microwave has 1 recipes - vert - horiz - fdp

space-plasma#

Category space-plasma has 3 recipes - vert - horiz - fdp

space-radiation#

Category space-radiation has 8 recipes - vert - horiz - fdp

space-collider#

Category space-collider has 12 recipes - vert - horiz - fdp

space-observation-infrared#

Category space-observation-infrared has 1 recipes - vert - horiz - fdp

lifesupport#

Category lifesupport has 9 recipes - vert - horiz - fdp

space-gravimetrics#

Category space-gravimetrics has 5 recipes - vert - horiz - fdp

space-observation-visible#

Category space-observation-visible has 1 recipes - vert - horiz - fdp

space-laser#

Category space-laser has 5 recipes - vert - horiz - fdp

space-observation-uv#

Category space-observation-uv has 1 recipes - vert - horiz - fdp

space-observation-xray#

Category space-observation-xray has 1 recipes - vert - horiz - fdp

space-observation-gammaray#

Category space-observation-gammaray has 1 recipes - vert - horiz - fdp

growing#

Category growing has 11 recipes - vert - horiz - fdp

t3-tech-cards#

Category t3-tech-cards has 6 recipes - vert - horiz - fdp

core-fragment-processing#

Category core-fragment-processing has 10 recipes - vert - horiz - fdp

smelting#

Category smelting has 11 recipes - vert - horiz - fdp

chemistry#

Category chemistry has 22 recipes - vert - horiz - fdp

atmosphere-condensation#

Category atmosphere-condensation has 4 recipes - vert - horiz - fdp

bioprocessing#

Category bioprocessing has 1 recipes - vert - horiz - fdp

smelting-crafting#

Category smelting-crafting has 8 recipes - vert - horiz - fdp

fuel-burning#

Category fuel-burning has 39 recipes - vert - horiz - fdp

oil-processing#

Category oil-processing has 5 recipes - vert - horiz - fdp

crushing#

skipped for size: 1081

space-radiator#

Category space-radiator has 3 recipes - vert - horiz - fdp

t2-tech-cards#

Category t2-tech-cards has 2 recipes - vert - horiz - fdp

fuel-refining#

Category fuel-refining has 5 recipes - vert - horiz - fdp

space-hypercooling#

Category space-hypercooling has 2 recipes - vert - horiz - fdp

electrolysis#

Category electrolysis has 4 recipes - vert - horiz - fdp

centrifuging#

Category centrifuging has 5 recipes - vert - horiz - fdp

fuel-processing#

Category fuel-processing has 8 recipes - vert - horiz - fdp

fuel-refinery#

Category fuel-refinery has 8 recipes - vert - horiz - fdp

rocket-building#

Category rocket-building has 2 recipes - vert - horiz - fdp

matter-deconversion#

Category matter-deconversion has 24 recipes - vert - horiz - fdp

stabilizer-charging#

Category stabilizer-charging has 1 recipes - vert - horiz - fdp

matter-conversion#

Category matter-conversion has 17 recipes - vert - horiz - fdp

nuclear-fusion#

Category nuclear-fusion has 1 recipes - vert - horiz - fdp

air-purification#

Category air-purification has 1 recipes - vert - horiz - fdp

 2  More#

Some of these were interesting but graph layout is just hard. I generated graphviz circo, neato, twopi, dot with vertical, dot with horizontal, and fdp. Of these, circo was pretty useless, and neato and twopi were not readable because the nodes overlapped. So I generated the remaining three and chose the most compact output to show here.

I think it’d be useful to have an interactive version here using viz.js that lets you choose an item and then it shows you what creates and also what you can do with it, but I wasn’t thrilled with the graphs so far and didn’t end up making the interactive version.

Email me , or tweet @redblobgames, or comment: