Easy ability to detect whether crafting machine can use fluids

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Easy ability to detect whether crafting machine can use fluids

Post by Therenas »

I was looking for a way to detect whether a machine can use fluids in its crafting, and it turns out this is not easy, if possible at all, to know.
One way is to look at fluidbox_prototypes, but since those also include sources for fuel and such, it's super convoluted to find out from there, if you even can.

Now I also saw the fluid_capacity field, which seemed to be perfect for my use case. It does however show 0 for every crafting machine. This is noted upon in the documentation, but it's not very helpful. What would make more sense is to have it show 0 for machines that can use fluids, and nil for those that can't, like assembling-machine-1.

Alternatively, one could also add a new flag or attribute that just tells me whether it can use fluids. I need this for Factory Planner so I can detect which machines should be offered for which recipes.

Honktown
Smart Inserter
Smart Inserter
Posts: 1026
Joined: Thu Oct 03, 2019 7:10 am
Contact:

Re: Easy ability to detect whether crafting machine can use fluids

Post by Honktown »

Why doesn't checking for LuaEntityPrototype->fluidbox_prototypes->production_type "input" or "input-output" work? To be perfectly accurate you need to check the crafting categories and whatnot to see if there is a recipe it could craft which uses fluid as an ingredient, but I don't see why that would give any trouble.
I have mods! I guess!
Link

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: Easy ability to detect whether crafting machine can use fluids

Post by Therenas »

You're right, you can actually work this out from what is provided. I was looking at the wrong thing here, I found a solution that seems to work fine. I'll leave the code here for posterity. The request does not need to be implemented, although it would be a nice-to-have.

Code: Select all

-- Determine fluid input/output channels
local fluid_channels = {input = 0, output = 0}
if proto.fluid_energy_source_prototype then fluid_channels.input = fluid_channels.input - 1 end

for _, fluidbox in pairs(proto.fluidbox_prototypes) do
    if fluidbox.production_type == "output" then
        fluid_channels.output = fluid_channels.output + 1
    else  -- "input" and "input-output"
        fluid_channels.input = fluid_channels.input + 1
    end
end

Post Reply

Return to “Modding interface requests”