Adding custom fluids - ksmonkey123/factorio_dieselTrains GitHub Wiki
The safest way to add new fluids to the DieselTrains mod is to create a small mod on top of this one that injects additional fluids. This is safer than a config file tweak as it ensures consistency even for multiplayer games. For multiplayer games you simply have to share this mod with all players and they are good to go.
Such a mod would consist of only 3 files:
info.json
This is the root file for the mod. Please choose your own name
, version
and title
. Make sure the dieselTrains mod is listed in the dependencies
alongside any mods that create the fluid you want to add. Listing the fluid source mod as a dependency ensures proper loading order.
{
"name": "dieselTrains_customFluid",
"version": "0.0.1",
"title": "Custom Diesel Fluid",
"author": "",
"contact": "",
"homepage": "",
"description": "",
"factorio_version": "0.18",
"dependencies": [ "dieselTrains >= 0.18.3" ]
}
data-final-fixes.lua
This file generates the fake item for the fluid you want to add and configures the barrel for this fluid to be usable as fuel as well.
local fluid
local function patchBarrel(barrel, energy)
if barrel then
if not barrel.fuel_category then
barrel.fuel_category = "Diesel-Locomotive-fluid"
barrel.fuel_value = energy
barrel.burnt_result = "empty-barrel"
end
end
end
-- add your fluid (as an example here: crude oil)
fluid = data.raw["fluid"]["crude-oil"]
if fluid then
local proxy = {
type = "item",
icon = fluid.icon,
icon_size = fluid.icon_size,
icon_mipmaps = fluid.icon_mipmaps,
icons = icons,
stack_size = 4294967295, -- stack size does not matter, just choose it large enough
fuel_category = "Diesel-Locomotive-fluid",
flags = {"hidden"},
group = "fluidTrains_fake",
-- here follow the important parameters to be changed:
name = "Diesel-Locomotive-crude-oil",
localised_name = {"", {"fluid.crude-oil"}},
fuel_value = "0.5MJ",
fuel_acceleration_multiplier = 1.0,
fuel_top_speed_multiplier = 1.0
}
data:extend({proxy})
end
-- add the barrel
patchBarrel(data.raw["item"]["crude-oil-barrel"], "25MJ") -- 1 barrel = 50 fluid
control.lua
This file configures the fluid configured in data-final-fixes.lua
to be actually usable in-game. For the moment this separation into data- and control-phase is necessary due to factorio constraints.
local function ON_INIT()
-- this call registers the fluid "crude-oil" as a member of the fuel category "Diesel-Locomotive-fluid"
-- and with the item-representation "Diesel-Locomotive-crude-oil"
remote.call("fluidTrains_hook", "addFluid", "Diesel-Locomotive-fluid", "crude-oil", {{item = "Diesel-Locomotive-crude-oil"}})
end
script.on_init(ON_INIT)
script.on_configuration_changed(ON_INIT)