Add auto_recycle to RecipePrototype

Place to report issues and suggest improvements to the API documentation.
User avatar
PennyJim
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Add auto_recycle to RecipePrototype

Post by PennyJim »

The FluidPrototype has auto_barrel listed, why does RecipePrototype not have the auto_recycle as well? This would help people realize it's there so they can disable alternative recipes from accidentally being picked as the recycling recipe.

It'd need a disclaimer that it does nothing without the Quality mod from the Space Age dlc (I'd say that means it should get the SA icon, but that's up to you) as part of a similar note to what auto_barrel has about it being a lua only field.
Zaflis
Filter Inserter
Filter Inserter
Posts: 521
Joined: Sun Apr 24, 2016 12:51 am
Contact:

Re: Add auto_recycle to RecipePrototype

Post by Zaflis »

I would not have been able to find this information; auto_recycle, can_recycle without google. So here it is again:
https://github.com/wube/factorio-data/b ... g.lua#L153

Main part is this though:
local can_recycle = can_recycle or default_can_recycle
If you already set the can_recycle it won't even go for a default value.

Basically the symptom was unwanted modded items coming out of recycler.
User avatar
IsaacOscar
Filter Inserter
Filter Inserter
Posts: 843
Joined: Sat Nov 09, 2024 2:36 pm
Contact:

Re: Add auto_recycle to RecipePrototype

Post by IsaacOscar »

Zaflis wrote: Wed Jan 01, 2025 1:45 pm I would not have been able to find this information; auto_recycle, can_recycle without google. So here it is again:
https://github.com/wube/factorio-data/b ... g.lua#L153

Main part is this though:
local can_recycle = can_recycle or default_can_recycle
If you already set the can_recycle it won't even go for a default value.

Basically the symptom was unwanted modded items coming out of recycler.
In the base game, the original value of can_recycle is nil, so I think it's simply there to allow mods to force generate a recycling recipe for something the base game doesn't want to.
curiosity
Filter Inserter
Filter Inserter
Posts: 559
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: Add auto_recycle to RecipePrototype

Post by curiosity »

Zaflis wrote: Wed Jan 01, 2025 1:45 pm If you already set the can_recycle it won't even go for a default value.
It will, if you set it to false.

...Oh, it's supposed to be a function. This is why it needs to be documented.
User avatar
IsaacOscar
Filter Inserter
Filter Inserter
Posts: 843
Joined: Sat Nov 09, 2024 2:36 pm
Contact:

Re: Add auto_recycle to RecipePrototype

Post by IsaacOscar »

curiosity wrote: Wed Jan 01, 2025 3:25 pm It will, if you set it to false.

...Oh, it's supposed to be a function. This is why it needs to be documented.
For anyone confused by what's going on
auto_recycle is a field on recipe prototypes, it should be false, true, or nil (the last two are the same as not setting it)

can_recycle is the paramater to the generate_recycling_recipe function, it should be a function that returns true, false, or nil, or itself be nil (the last is the same as ommitting it).

Neither auto_recycle nor can_recycle should be a function

There are two ways to call the generate_recycling_recipe function:

Code: Select all

local recycling = require("__quality__.prototypes.recycling")
recycling.generate_recycling_recipe(recipe)
recycling.generate_recycling_recipe(recipe, function(r)
    ...
end)
The first call will not generate a recycling recipe if either auto_recycle is false (and not nil), or, one of the built in exclusions apply.

The second call will generate a recycling recipe if the given function returns true, of some other non-false/nil value (the r parameter will always equal the given recipe, so I don't know why it doesn't just let you pass a boolean).
(Except that neither will generate a recipe if the recipe does not hace exactly one non-fluid output, or if the recipe has no non-fluid ingredients).

Note that auto_recycle is only read by the lua code in the quality mod, so if you don't call generate_recycling_recipe or it isn't called automatically, the game will completely ignore it. Also can_recycle is never actually passed by the games lua code, so I think it's just their for modders or something they forgot to delete.
Last edited by IsaacOscar on Wed Jan 01, 2025 4:07 pm, edited 2 times in total.
User avatar
PennyJim
Long Handed Inserter
Long Handed Inserter
Posts: 87
Joined: Wed Jan 18, 2023 3:49 am
Contact:

Re: Add auto_recycle to RecipePrototype

Post by PennyJim »

IsaacOscar wrote: Wed Jan 01, 2025 3:46 pm can_recycle is the paramater to the generate_recycling_recipe function, it should be true, false, or nil (the last two are the same as ommitting it).

Neither auto_recycle nor can_recycle should be a function
Passing true to can_recycle will cause it to crash.
It is supposed to be an optional function that returns a boolean:
https://github.com/wube/factorio-data/b ... #L179-L181

Also, the random functions that we can use in data aren't normally documented. They probably should be, but that's a separate documentation request.
User avatar
IsaacOscar
Filter Inserter
Filter Inserter
Posts: 843
Joined: Sat Nov 09, 2024 2:36 pm
Contact:

Re: Add auto_recycle to RecipePrototype

Post by IsaacOscar »

PennyJim wrote: Wed Jan 01, 2025 4:00 pm
IsaacOscar wrote: Wed Jan 01, 2025 3:46 pm can_recycle is the paramater to the generate_recycling_recipe function, it should be true, false, or nil (the last two are the same as ommitting it).

Neither auto_recycle nor can_recycle should be a function
Passing true to can_recycle will cause it to crash.
It is supposed to be an optional function that returns a boolean:
https://github.com/wube/factorio-data/b ... #L179-L181

Also, the random functions that we can use in data aren't normally documented. They probably should be, but that's a separate documentation request.
Dammit, I misread the code. I've fixed my dumb comment.
Post Reply

Return to “Documentation Improvement Requests”