Crafting Efficiency


Adds technology to increase the efficiency of some recipes, auto updates recipes in assembly machines and adds a function for modders to add efficiency recipes for their items

Content
14 days ago
1.1 - 2.0
5.99K
Manufacturing

g [BugFix] [SE] some recipe results not updated

2 months ago
(updated 2 months ago)

Bug originally found in Space Exploration:

In some recipes, improved recipes use the original value for result amount instead of the calculated one
For instance, SE recipe for utility science pack has
original recipe: (1 solar panel and some ,ore) to (4 science packs, 4 junk cards, 100 thermofluid)
recipe level 1 (x5) is (5 solar panel and some ,ore) to (4,4,110)
while it obviously should be (22,22,110)

Found the problem: SE defines some recipe results as {"utility-science-pack", 4} instead of {amount = 4, name = "utility-science-pack"}

Here's a quick fix that seems to work (in recipe.lua line 154)

    if check then
        for a, b in pairs(CE_recipes[name][tostring(count)].results) do

            if not b.amount and not b.amount_min then
                local oldB=Deepcopy(b)
                for i, v in ipairs(b) do b[i] = nil end
                b.amount=oldB[2]
                b.name=oldB[1]
                log("Normalized recipe result: ".. serpent.line(oldB) .. " to " .. serpent.line(b))
            end

I'm not familiar with LUA so there should be a much cleaner way to proceed :)

Also, for SE recipes that output heated coolant or junk data cards, there should be exclusions so that output is not multiplied: it wouldn't make sense taht an improved recipe provides more coolant that you input (also it would create a terrible mess in your fluids setup)

2 months ago

Also, for the "do not multiply coolant" issue, here's another quick fix

functions.lua

function Cost_multiplier(ingredients, time, results1, multiplier, results2, resultsNames)

[...]
for i, v in ipairs(results1) do
    if string.find(resultsNames[i], "junk") or string.find(resultsNames[i], "thermofluid") then
        log("Forcing multiplier to 1 (was "..multiplier..") for product '" .. resultsNames[i].."'")
        multiplier = 1
    end

    results1[i] = results1[i] * multiplier * (10 ^ decimal_count)
end

for i, v in ipairs(results2) do
    if string.find(resultsNames[i], "junk") or string.find(resultsNames[i], "thermofluid") then
        log("Forcing multiplier to 1 (was "..multiplier..") for product '" .. resultsNames[i].."'")
        multiplier = 1
    end

    results2[i] = results2[i] * multiplier * (10 ^ decimal_count)
end

and in recipes.lua, line 37+

if CE_recipes[name].base.result then
    table.insert(result, CE_recipes[name].base.result[1])
    result_count1 = { CE_recipes[name].base.result_count }

    log("Using result name (single): " .. serpent.line(CE_recipes[name].base.result))
    results = CE_recipes[name].base.result
else
    for a, b in pairs(CE_recipes[name].base.results) do
        if b.name then
            log("Using result name (iterating): " .. serpent.line(b))
            table.insert(results, b.name)
2 months ago

Also, recipe results should also be normalized in recipes.lua line 131
(This may or may not be redundant with original fix. Again, this is very lightly tested)

    for a, b in pairs(CE_recipes[name].base.results) do
        log("processing result key (a)=" .. serpent.line(a))
        log("                  val (b)=" .. serpent.line(b))
        if b.name then
            --log("   CHECK")
            check = true
        elseif type(b[1]) == "string" and type(b[2]) == "number" then
            local oldB=Deepcopy(b)
            for i, v in ipairs(b) do b[i] = nil end
            b.amount=oldB[2]
            b.name=oldB[1]
            log("Normalized CE_recipe result: ".. serpent.line(oldB) .. " to " .. serpent.line(b))
            check = true
        else
            log("B has no name !! -- b=" .. serpent.block(b))
        end
    end
2 months ago

I fixed the bug, but I prefer to keep the multiplier on all results, in your fix on the file functions.lua you introduced a hypothetical bug that I have not tested but that theoretically should happen, since you go to reset the multiplier variable to 1, and in case afterwards there is a result on which you care to have the efficiency, this is not applied since the variabbile is set to 1, to dispose of the excess liquid and item you can use the flare stack-se mod, which adds 1x1 structures to incinerate the surplus of what you don't need, surely in the future when I rewrite the mod I will make sure that you can apply the efficacy to certain outputs of your choice, without them being hard-coded, anyways good game.

a month ago

I fixed the bug, but I prefer to keep the multiplier on all results, in your fix on the file functions.lua you introduced a hypothetical bug that I have not tested but that theoretically should happen, since you go to reset the multiplier variable to 1, and in case afterwards there is a result on which you care to have the efficiency, this is not applied since the variabbile is set to 1, to dispose of the excess liquid and item you can use the flare stack-se mod, which adds 1x1 structures to incinerate the surplus of what you don't need, surely in the future when I rewrite the mod I will make sure that you can apply the efficacy to certain outputs of your choice, without them being hard-coded, anyways good game.
Hi,when i use the newest version,this question still exists,in K2+SE,the production science pack's efficiency recipe require more time and fluid,but items not change,and production don't change,just like original recipe.it seems not fixed correctly.

New response