Ingredients not removed when crafting_progress raised to 1

Place to get help with not working mods / modding interface.
Post Reply
BuilderOfAges
Inserter
Inserter
Posts: 35
Joined: Thu Aug 02, 2018 3:02 pm
Contact:

Ingredients not removed when crafting_progress raised to 1

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13225
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Ingredients not removed when crafting_progress raised to 1

Post by Rseding91 »

That's intended. Manually setting the crafting_progress overrides the built-in mechanics of running the machine.
If you want to get ahold of me I'm almost always on Discord.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2904
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Ingredients not removed when crafting_progress raised to 1

Post 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?

BuilderOfAges
Inserter
Inserter
Posts: 35
Joined: Thu Aug 02, 2018 3:02 pm
Contact:

Re: Ingredients not removed when crafting_progress raised to 1

Post 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

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Ingredients not removed when crafting_progress raised to 1

Post 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.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

BuilderOfAges
Inserter
Inserter
Posts: 35
Joined: Thu Aug 02, 2018 3:02 pm
Contact:

Re: Ingredients not removed when crafting_progress raised to 1

Post 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.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Ingredients not removed when crafting_progress raised to 1

Post 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).
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Modding help”