Page 1 of 1
Expose FluidBox::production_type
Posted: Tue Jul 24, 2018 7:44 am
by Therax
It would nice to be able to determine whether a given pipe connection and/or fluid box was for input or output, whether exposed via LuaEntityPrototype or LuaFluidBox.
I'm making a mod that does bulk long-distance transfer of liquids, and it would be nice to be able to automatically determine which connections are sources and which are sinks. While I can hard-code the mapping for vanilla entities, for modded entities it's impossible to predict. The goal of the mod is mitigating the UPS cost of large nuclear power setups, but could be used with any fluid.
Re: Expose FluidBox::production_type
Posted: Tue Jul 24, 2018 7:54 am
by Bilka
Do you want this for LuaEntity or LuaEntityPrototype? If you want it for the prototype, it's already exposed in 0.17 via LuaEntityPrototype::fluidbox_prototypes and
https://lua-api.factorio.com/0.17.0-pre ... otype.html
If you want it from LuaEntity/LuaFluidBox I'll look into getting the fluid box prototype from the LuaFluidBox.
Re: Expose FluidBox::production_type
Posted: Tue Jul 24, 2018 9:49 am
by Klonan
Bilka wrote:Do you want this for LuaEntity or LuaEntityPrototype? If you want it for the prototype, it's already exposed in 0.17 via LuaEntityPrototype::fluidbox_prototypes and
https://lua-api.factorio.com/0.17.0-pre ... otype.html
If you want it from LuaEntity/LuaFluidBox I'll look into getting the fluid box prototype from the LuaFluidBox.
If its in the prototype its enough, as the production type can't be changed at runtime anyway
But it could be nice to have a fluidbox.prototype as a shortcut
Re: Expose FluidBox::production_type
Posted: Tue Jul 24, 2018 5:15 pm
by Therax
Perfect. I missed that LuaFluidBoxPrototype was introduced in 0.17.
Re: Expose FluidBox::production_type
Posted: Tue Jul 24, 2018 6:32 pm
by Therax
This is actually related: is there or can there be a way to determine which pipe_connection of a fluidbox is connected? Here's the scenario:
I have a pump. I know from examining the LuaFluidBoxPrototype and FluidBoxConnection (and why isn't that named FluidBoxConnectionPrototype?) that the pump has 1 fluidbox and 2 connections on that fluidbox, with the 1st being output and the 2nd being input.
I start with a reference to a pipe connected to the pump. I can call pipe.fluidbox.get_connections(1) to get a reference to the pump's LuaFluidBox, and pump_fluidbox.owner to get a reference to the pump entity. I don't know whether my pipe is connected to the pump's input or output, and I need to learn this information.
If nothing else is connected to the pump, I can call pump_fluidbox.get_connections(1) and get an array of LuaFluidBox references, containing only one entry, which is my pipe's LuaFluidBox. I can't see any way to determine from here whether this is an input or output connection.
If something else is connected to the pump, calling pump_fluidbox.get_connections(1) returns an array of 2 LuaFluidBox references, one of which is my pipe's LuaFluidBox. However, the order of the array returned from pump_fluidbox.get_connections(1) is unpredictable. Sometimes the input connection appears first, sometimes the output connection appears first, and it appears to be determined by entity construction order.