Allow furnaces' recipe to be reset using .set_recipe(nil)

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
nullium21
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Sep 25, 2021 7:57 am
Contact:

Allow furnaces' recipe to be reset using .set_recipe(nil)

Post by nullium21 »

Basically what the title says.
Tried to do this and got an error:
Image

The entity is a furnace, which, according to prototype wiki, is a crafting machine:
Image
sent from nullium21's Smart Fridge

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Allow furnaces' recipe to be reset using .set_recipe(nil)

Post by boskid »

I see there is a documentation error. As for 1.1.41, LuaEntity::set_recipe() is incorrectly documented saying it can be used with CraftingMachine while it should say it can only be used with AssemblingMachine. LuaEntity::get_recipe() is correct saying it works on CraftingMachine.

nullium21
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Sep 25, 2021 7:57 am
Contact:

Re: Allow furnaces' recipe to be reset using .set_recipe(nil)

Post by nullium21 »

boskid wrote:
Sun Sep 26, 2021 10:25 am
I see there is a documentation error. As for 1.1.41, LuaEntity::set_recipe() is incorrectly documented saying it can be used with CraftingMachine while it should say it can only be used with AssemblingMachine. LuaEntity::get_recipe() is correct saying it works on CraftingMachine.
Is there a reason for why it can't be used with other crafting machine types? Or, maybe, a workaround to clear the recipe?
sent from nullium21's Smart Fridge

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Allow furnaces' recipe to be reset using .set_recipe(nil)

Post by boskid »

nullium21 wrote:
Sun Sep 26, 2021 11:58 am
Is there a reason for why it can't be used with other crafting machine types?
Yes of course there is a reason. LuaEntity::set_recipe() works by calling AssemblingMachine::setupForCrafting() on the c++ side which is only available on entities that can be casted to AssemblingMachine class. Furnaces have completly different recipe changing routine which looks at first item from source inventory or first fluid in the input fluid box.

nullium21
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sat Sep 25, 2021 7:57 am
Contact:

Re: Allow furnaces' recipe to be reset using .set_recipe(nil)

Post by nullium21 »

boskid wrote: LuaEntity::set_recipe() works by calling AssemblingMachine::setupForCrafting() on the c++ side which is only available on entities that can be casted to AssemblingMachine class. Furnaces have completly different recipe changing routine which looks at first item from source inventory or first fluid in the input fluid box.
And what about clearing the recipe (.set_recipe(nil))?

Also, just noticed, the alt-view looks like the furnace keeps the recipe, but debug info says "Recipe: <none>". Is it a bug?

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2241
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Allow furnaces' recipe to be reset using .set_recipe(nil)

Post by boskid »

Clearing recipe on assembling machine is done through AssemblingMachine::reset which is also available only on AssemblingMachine. AssemblingMachine::setupForCrafting internally calls the AssemblingMachine::reset when it is given a RecipeID of "no recipe".

Furnaces have a "previous recipe id" which is used in certain cases (showing recipes on map, showing recipe in alt mode when furnace is not working). Value of the "previous recipe id" is accessible through LuaEntity::previous_recipe [R] which only works for Furnaces. It has no effects on furnace working state, its just a visualisation stuff due to how furnaces work: when a furnace finishes crafting, its recipe is automatically cleared and thats why the debug info says "Recipe: <none>" - debug stuff shows furnace's true current recipe without any layers of hiding them using previous recipe id.

Post Reply

Return to “Modding interface requests”