Page 1 of 1
Ingredients not removed when crafting_progress raised to 1
Posted: Sat Sep 29, 2018 3:03 pm
by BuilderOfAges
When I set crafting_progress = 1 manually on an assembling-machine, then the recipe result is put in the building's output inventory, but the ingredients are not removed from the source inventory. Is this intended, or a bug?
To reproduce: place an assembler building e.g. pipes, insert 10 iron plates and select the machine.
Code: Select all
/c game.players[1].selected.crafting_progress = 1
Now there's 10 iron plates and 1 pipe.
Re: Ingredients not removed when crafting_progress raised to 1
Posted: Sun Sep 30, 2018 2:08 am
by Rseding91
That's intended. Manually setting the crafting_progress overrides the built-in mechanics of running the machine.
Re: Ingredients not removed when crafting_progress raised to 1
Posted: Sun Sep 30, 2018 9:27 am
by darkfrei
Rseding91 wrote: Sun Sep 30, 2018 2:08 am
That's intended. Manually setting the crafting_progress overrides the built-in mechanics of running the machine.
How to complete the crafing process properly?
Re: Ingredients not removed when crafting_progress raised to 1
Posted: Sun Sep 30, 2018 10:58 am
by BuilderOfAges
I did it like this, which seems to work:
Code: Select all
local recipe = assembler.get_recipe()
local assembler_input = assembler.get_inventory(defines.inventory.assembling_machine_input)
assembler.crafting_progress = 1
for _, ingredient in ipairs(recipe.ingredients) do
assembler_input.remove{name = ingredient.name, count = ingredient.amount}
end
Re: Ingredients not removed when crafting_progress raised to 1
Posted: Mon Oct 01, 2018 9:06 am
by eradicator
BuilderOfAges wrote: Sun Sep 30, 2018 10:58 am
I did it like this, which seems to work:
Code: Select all
local recipe = assembler.get_recipe()
local assembler_input = assembler.get_inventory(defines.inventory.assembling_machine_input)
assembler.crafting_progress = 1
for _, ingredient in ipairs(recipe.ingredients) do
assembler_input.remove{name = ingredient.name, count = ingredient.amount}
end
Not sure what exactly you're doing, but pretty sure
that will craft for free even with insufficient ingredients.
Would it be sufficient to check if crafting_process > 0 and then set it to 1? That way you wouldn't have to care about ingredient consumption.
Re: Ingredients not removed when crafting_progress raised to 1
Posted: Mon Oct 01, 2018 4:23 pm
by BuilderOfAges
Yes it's only a fragment, focusing on taking out the necessary ingredients. You'd have to check yourself whether all the necessary ingredients were already present.
In my case, I wanted to make an
anvil where the recipe never completes automatically, but every time you add a hammer the crafting progress increases by a third.
P.S.: thanks for hand-crank generator BTW. I want to add something similar to my mod, will definitely take a look at your code.
Re: Ingredients not removed when crafting_progress raised to 1
Posted: Mon Oct 01, 2018 5:31 pm
by eradicator
BuilderOfAges wrote: Mon Oct 01, 2018 4:23 pm
Yes it's only a fragment, focusing on taking out the necessary ingredients. You'd have to check yourself whether all the necessary ingredients were already present.
In my case, I wanted to make an
anvil where the recipe never completes automatically, but every time you add a hammer the crafting progress increases by a third.
Ah, the anvil thing. Hadn't thought to much about it last time. If the anivil (==assembler?) uses a burner energy source you could manipulate the energy instead of the progress directly. I.e. add a bit of energy with every hammer stroke (would also be visible in the tooltip as a short spike). Ofc you'd have to tune the crafting speed/consumpition to exactly match your desired stroke count. But it'd remove the need to manually do resource reduction.
BuilderOfAges wrote: Mon Oct 01, 2018 4:23 pm
P.S.: thanks for hand-crank generator BTW. I want to add something similar to my mod, will definitely take a look at your code.
Thanks :). I don't get much (read: none) feedback on it. Nice to know if someone finds it useful, even if it's just for using the code (that was after all the original idea).