Page 1 of 1

Easy ability to detect whether crafting machine can use fluids

Posted: Wed May 20, 2020 2:44 pm
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.

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

Posted: Sun May 31, 2020 1:29 am
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.

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

Posted: Sun May 31, 2020 9:42 am
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