Freight Stations (rat's fork)


Fork of Ragingart's Freight Stations with a rework fixing a whole class of bugs: no rail shift on select-new-contents, flipped/shifted pastes no longer strand balancer ghosts inside stations, stations can sit beside the start of curved rail, undo works as well. Removed placement restrictions to get rid of the code causing bugs. Uses the same entity names, so saves migrate over. Replaces the original.

Content
a month ago
2.1
77
Storage

Changelog

Fork of Ragingart's Freight Stations (https://mods.factorio.com/mod/freight-stations),
maintained by rat. Same entities, items, recipes and technologies as the
original, so saves and blueprints carry over - but do not run both mods at
once (duplicate prototypes). Fixes and changes below are on top of 0.12.9;
the untouched upstream history follows after the fork entries.
Version: 1.1.3
Date: 2026-11-07
  Bugfixes:
    - Fixed copying a blueprint crashing the game ("LuaItemStack API call when LuaItemStack was invalid for read"): the cursor blueprint is not always a readable stack (setting up a book entry, an empty cursor), so the blueprint fold is now guarded and a failure degrades to an unfolded copy instead of an error. Pipette was confirmed working by the report - thanks for testing.
Version: 1.1.2
Date: 2026-11-07
  Bugfixes:
    - Fixed Q (pipette) and copy doing nothing on grouped stations: the size-band prototypes have no item of their own (the crafted item places the band-1 prototype), and the engine refuses entities without a placing item as ghosts ("can not be part of an entity ghost") and cannot resolve them for pipette - so only lone, band-1 stations could be pipetted or copied. Band prototypes now declare the axis item as their placeable_by, and blueprint setup folds band variants, dismantling stand-ins and legacy size records down to the base prototype, so every copied row is built from the normal item (construction robots included) and the build events re-band the rebuilt stations.
Version: 1.1.1
Date: 2026-11-06
  Bugfixes:
    - Fixed silently destroyed items in normal play: the band-swap pass checked only its hash-ordered first member, so a station built without crossing a band boundary (the fourth station of a band-4 row, say) stayed on the band-1 prototype - and since link ids are per prototype, it did not even share the group's inventory. Items inserted through such a member sat in private slots the next real swap destroyed. The swap now scans every member, collects every member's inventory, and merges whatever a stranded member is holding into the group.
    - Fixed large overflow spills destroying part of the items (12-36% of a full group's overflow vanished in the lab): spills now spread over a deterministic grid and verify what actually landed, retrying farther out. The engine drops one-item piles and quietly discards what it cannot place past roughly a hundred piles per point.
    - Fixed a station dying (biters, artillery) losing the whole group inventory: a death's loot inventory has nothing to collect it, so contents inserted there were unrecoverable. They now spill on the ground, pickable.
    - Fixed mining an unmarked last-of-group station stranding the shared inventory (the engine keeps it by link id, so a later group reusing the id inherited the lost items): the survivor check no longer counts the removed station as its own surviving mate.
    - Fixed event-less removals (undo, a plain script destroy - neither raises an event) leaving two pieces that still share one inventory: the next build near one piece poured the entire shared inventory into the smaller band, teleporting the items and spilling the overflow. A build now detects holders outside its own component and runs the normal split semantics instead.
    - Fixed building, marking or mining a fluid station crashing the mod: they were routed through the linked-inventory group code, which cannot touch storage-tanks. Fluid stations now only use auto-connect and the engine's own fluid segments, as designed.
    - Fixed cancelling a dismantling stand-in that still had group-mates crashing on the stale entity reference (the rebuild pass may have swapped the station onto its band prototype mid-handler); whatever stands there now receives the contents.
    - Fixed the dismantle mark/cancel round-trip resetting item state: stacks move through a script inventory as real stacks, keeping item health, instead of being rebuilt as name/count/quality tables.
    - Fixed equal splits keeping the items with a hash-order-dependent side: ties now go to the piece with the lowest (y, x) anchor, deterministic on every client.
    - Fixed one-way walk edges between diagonally adjacent stations of different tiers (one is wider), which made a split's keeper depend on which side the walk started from: probes now require the centres to sit on the same line.
    - Fixed legacy migration dropping pending deconstruction marks; a kept mark now flows into the mod's own dismantle flow, and migration pours the old inventory into the station or stand-in that actually stands there.
    - Fixed stations whose build event was missed (another mod's create_entity, a script fast-replace) losing the items they held privately when they joined a group: unlinked stations are drained into the group first, since assigning a link id over held items destroys them.
    - Fixed auto-connect eating the balancer item when the build raced another mod in the same tick: the item is refunded if the placement fails after the charge.
    - Fixed pressing R on a placed stock balancer turning it across its row, silently disconnecting its stations on the next walk: the turn is reverted (blueprint pastes keep their direction).
    - Hardened the theoretical band-swap path where every entity recreation fails: the collected inventory spills around the group's last position instead of being destroyed with the temp inventory.
  Changes:
    - info.json no longer claims saves from 0.12.x/0.13.x do not migrate (they do, since 1.1.0).
Version: 1.1.0
Date: 2026-11-06
  Changes:
    - Capacity grows with the group again, in size bands: the group's inventory is its prototype's fixed size, so members are swapped onto the next band's prototype (powers of two, capped at the tier's max_group: 100 stations for iron, 50 for steel) whenever the group crosses a band - rare, unlike the old one-prototype-per-exact-size replacement on every change. Wires, quality, health, last user and a pending deconstruction order carry over, the link id carries over, and items pour into the new band's inventory (growing always fits; shrinking spills the overflow). A group's window shows its band's capacity, rounded up from the member count.
    - Auto-connect no longer places balancer ghosts: a balancer is only placed when the builder pays for it from their inventory (free in cheat mode). Robot and script builds without a player make no connection until a balancer is built or pasted there.
    - Saves from 0.12.x and 0.13.x migrate: the old size-prototype stations (their prototypes stay in the mod, hidden, so the entities survive loading) are converted to the matching size band's prototype on first load. Every old group becomes one new group with a fresh link id; quality, health and last user carry over, circuit wires do not (re-wire after migrating). Bands round up from the old member count, so the old inventory always fits - nothing spills. Old ghosts convert too; ghosts of the old placer machines cannot be built by anything and are gone.
Version: 1.0.0
Date: 2026-11-06
  Changes:
    - Minimal-core rewrite of the whole mod. Stations and tanks build exactly where you place them and share one inventory per group: every member is an access point to the same linked inventory. Every entity is placed directly by its own item - no placers, no entity swapping, no per-size prototypes - so undo, blueprints, ghosts, pipette and fast-replace are all engine-native. Flipping a blueprint row now builds the exact mirrored row (the old known issue is gone by design).
    - Groups are the world: link ids live on the entities and connectivity is walked live, with no bookkeeping storage to migrate. Two non-empty groups merging pour the loser's items into the survivor's; a group splitting leaves the items with the largest piece and the other pieces start empty.
    - A station marked for deconstruction becomes a plain container stand-in while it is the last of its group, so robots empty it load by load; group-mates are simply mined empty, and cancelling restores the station with its contents.
    - Undo works natively: nothing is replaced behind the engine's back any more.
    - Two items per tier place the two axis prototypes (linked containers cannot rotate); the balancer is one rotatable entity per tier.
    - Engine notes from this rewrite, measured headless on 2.1.24: script_raised_built/revive/destroy lost their on_ prefix in defines.events (a nil in ipairs silently skipped them), and get_contents() on a linked container's inventory reads empty even with items in the slots - slot iteration works.
Bugfixes:
    - Fixed cmd+z leaving the stations behind even after the 0.12.11 fix: every group merge or resize replaces the station entities, and the replacements were created without a player, so the engine dropped the undo record the placer swap had just set up (a script destroy removes the undo steps referencing the destroyed entity, and only create_entity with a player adds one back). Replacements now carry the station's last_user, which keeps every resized station in its builder's undo queue - ctrl+z removes the station and refunds the item. Pasted stations are still removed together when the paste's own undo item is undone.
    - Fixed "select new contents" on a blueprint containing rails shifting every rail one tile down and one right: the station-to-placer swap's half-tile offsets made the engine re-snap stored positions; blueprint entities are now stored verbatim (set_blueprint_entities with fix_positions=false).
    - Fixed the cmd+z undo handler never running (an out-of-scope loop variable made it return early), so blueprint-placed stations are again removed - with the station item refunded - when an undo clears the area they were pasted into.
    - Hardened a handful of theoretical crash paths found in a whole-codebase review (a station replacement racing another mod's build, a failed stand-in restoration leaving a nil in a station list, and two unchecked nils in the pipette and refusal paths).
  Changes:
    - Removed the rail-adjacency placement rule and the wagon-slot snapping entirely: stations and tanks now build exactly where you place them, like vanilla containers, and pasted ghosts stay where you put them. This drops the placement guide, the "must stand beside a rail/stop" refusals and the one-tick ghost retry queue they needed. Flipping a blueprint still lands its balancer ghosts one tile off the stations (the engine cannot mirror the placer's one-sided footprint): a balancer ghost inside a built station's footprint is now removed instead of left unbuildable forever, and auto-connect fills the real gaps. Known issue, tracked for a follow-up: if a robot builds such a balancer before the station, the station ghost can still end up stuck.
    - Freight stations (and their placers) are now fast-replaceable like vanilla containers: a station blueprint can be built over an existing station instead of being blocked red - the old station is mined, and the new one keeps the shared inventory via its link. A pending dismantling stand-in whose spot was taken by a rebuilt station hands its contents to that station instead of spilling them.
Version: 0.12.9 (upstream, unmodified)
Date: 2026-10-17
  Bugfixes:
    - Fixed a crash when a freight station marked for deconstruction was removed instantly, for example by Ctrl+Z after placing it in the map editor. Its contents and the station item are kept.
Version: 0.12.7
Date: 2026-10-15
  Changes:
    - New mod thumbnail, showing freight stations and fluid stations beside a stopped train.
Version: 0.12.5
Date: 2026-10-15
  Bugfixes:
    - Fixed a station placed with a single click getting balancers to its neighbours. Only drag-building, blueprints and robots fill the gaps now, so neighbouring stations can be kept separate again.
    - Fixed a hand-placed underground stock balancer or underground fluid balancer not turning round to face its partner.
Version: 0.12.3
Date: 2026-10-15
  Changes:
    - Fluid stations hold 150,000 (three fluid wagons) instead of 25,000, and steel fluid stations 500,000 (ten fluid wagons) instead of 50,000, in line with how much the freight stations hold. Fluid already stored is kept.
  Bugfixes:
    - Fixed the upgrade planner offering every size and direction of every freight station, the steel stock balancers and the fluid stations as upgrade targets. Each of these items now has one entry there, like any other building.
Version: 0.12.1
Date: 2026-10-14
  Features:
    - Added fluid stations: long fluid tanks that sit beside a stopped train, level with its fluid wagons, placed and snapped like freight stations. Pumps and pipes connect anywhere along a station's long sides, and a sight glass shows its level.
    - Added fluid balancers: placed in the gap between two fluid stations, they join them into one shared fluid. Drag-building and blueprints fill the gaps automatically, and never join two different fluids.
    - Added underground fluid balancers, which join the fluid stations on both sides of the track into one shared fluid.
    - Added steel fluid stations, two tiles wide and holding a whole fluid wagon each, with their own steel fluid balancers and underground fluid balancers.
    - Hovering a fluid station outlines every fluid station it shares its fluid with.
    - New research: Fluid stations (after Freight stations and Fluid wagon) and Steel fluid stations.
Version: 0.11.3
Date: 2026-10-13
  Bugfixes:
    - Fixed flipped blueprints of station rows building only some of their stations. Pasted balancers and underground stock balancers now move into the gaps between wagon slots, the way pasted stations move onto their slot, so a row blueprint also works when it isn't lined up exactly with the train stop.
    - Fixed two underground stock balancers not linking up again after removing a third one that stood sideways between them.
Version: 0.11.1
Date: 2026-10-13
  Changes:
    - Stock balancers and underground stock balancers can be walked and driven over, like belts, so a row of stations no longer has to be walked around.
Version: 0.10.3
Date: 2026-10-13
  Bugfixes:
    - Fixed the game failing to load on Factorio 2.1 ("Value must be a list ... circuit_connector").
Version: 0.10.1
Date: 2026-10-13
  Optimizations:
    - Linking, splitting and removing stations in large groups is two to four times faster.
    - Marking a whole group for deconstruction, or cancelling that, no longer freezes the game for seconds: the group is changed once instead of once per station.
    - The mod no longer runs every tick when it has nothing queued.
  Changes:
    - The deconstruction planner lists each tier's stations and steel stock balancers once, instead of once per group size and direction.
  Bugfixes:
    - Loading a save after changing mods no longer switches off recipes that other mods had unlocked by script.
    - Blueprints in the blueprint library updated with "Select new contents" can be rotated and flipped like any other blueprint with stations.
    - The placement guide and group outline are removed when their player leaves the game, and the guide comes back on rejoining while holding a station.
    - Stations another mod placed without telling the game now get linked when the save is loaded after a mod change, instead of all sharing one inventory. A station copied that way no longer takes the original group's contents.
  Compatibility:
    - Station placement collides exactly like the station itself, including collision layers other mods add, so it can no longer be refused on ground where the station would fit.
Version: 0.9.1
Date: 2026-10-12
  Optimizations:
    - The green placement guide is about twice as fast near busy train stations.
  Changes:
    - Mining a station from a group keeps its contents in the group when the remaining stations have room. You only get what no longer fits.
    - Splitting a group shares items out by whole stacks, in proportion to each part's size.
    - When robots take down part of a group, its contents move into the stations that stay, as far as they fit, instead of leaving with the dismantled part.
    - A station marked for deconstruction leaves its group at once and becomes a plain chest holding what the group can't keep. Robots empty it like a vanilla chest and then remove it, returning the station last, instead of leaving a carpet of single items on the ground. Cancelling turns it back into a station.
    - Loading a save re-checks every group against the stations and balancers actually placed.
  Bugfixes:
    - Mining a station that isn't linked to others no longer deletes its contents; they go to your inventory.
    - Splitting a group that holds many different items no longer spills part of them on the ground.
    - Fixed a crash when linking stations after another mod removed a balancer without telling the game.
    - Groups stay correct when another mod destroys a station without telling the game.
    - Steel stock balancers keep their quality when placed.
    - The group outline while hovering a station now updates when the group changes under the cursor.
Version: 0.8.1
Date: 2026-10-12
  Changes:
    - Stations and balancers are kept out of the upgrade planner.
Version: 0.7.1
Date: 2026-10-11
  Changes:
    - Blueprints with stations can be pasted next to a ghost train stop.
  Bugfixes:
    - Fixed a crash when merging into a group.
Version: 0.6.1
Date: 2026-10-11
  Changes:
    - Entity descriptions.
Version: 0.5.1
Date: 2026-10-10
  Changes:
    - Items moved to the vanilla train row of the Logistics tab.
Version: 0.4.0
Date: 2026-10-09
  Major Features:
    - First release.