Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /c --[[ hold blueprint when using this --]]
- local player = game.player
- local counts = {}
- for k,v in pairs(player.get_blueprint_entities() or error("Need blueprint on cursor", 0)) do
- counts[v.name] = (counts[v.name] or 0) + 1
- end
- repeat
- local ingredient_has_ingredients = false
- local next_counts = {}
- for name, count in pairs(counts) do
- local recipe = game.recipe_prototypes[name]
- if recipe then
- ingredient_has_ingredients = true
- for _,ing in pairs(recipe.ingredients) do
- --[[ type, name, amount --]]
- local partname, partamount = ing.name, ing.amount
- local modded_count = count / recipe.main_product.amount * recipe.main_product.probability
- next_counts[partname] = (next_counts[partname] or 0) + (modded_count * partamount)
- end
- else
- next_counts[name] = (next_counts[name] or 0) + count
- end
- end
- counts = next_counts
- until not ingredient_has_ingredients
- local ordered_counts = {}
- for name, count in pairs(counts) do
- table.insert(ordered_counts, { name=name, count=count })
- end
- table.sort(ordered_counts, function(a, b) return a.name < b.name end)
- player.print("rawcount:")
- for _,t in pairs(ordered_counts) do
- player.print(t.name..": "..t.count)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement