Belt Balancer (Unofficial 2.1 Fix)

by kfsone

Adds Balancer Parts that can be put together to balance all adjacent belt lanes. Unofficial Factorio 2.1 build with a script-state rebuild, so it can replace Belt Balancer 2 / Belt Balancer 3 in an existing save (placed balancers keep working). Original mod by knoxfighter, archiehalliwell and IThundxr (Belt Balancer 2), later updated by NightPablo (Belt Balancer 3); 2.1 fix and state rebuild by kfsone. MIT licensed.

Content
7 days ago
2.1
34
Logistics

Changelog

Version: 2.1.0
Date: 24.10.2026
  Changes:
    - Renamed to belt-balancer-Unofficial-2-1Fix ("Belt Balancer (Unofficial 2.1 Fix)") so it can be published next to the originals. Based on belt-balancer-3 1.0.2 (which is based on belt-balancer-2 2.0.9). Prototype, recipe, technology and item names are unchanged, so existing saves keep their balancer-parts and research.
    - State rebuild: the script state (balancers, parts, belts, lanes, tick schedule) lives in the mod's private 'storage', which is empty when this mod replaces belt-balancer-2 or belt-balancer-3 in an existing save. On load the mod now re-registers every balancer-part and every belt, underground belt, splitter, loader and linked belt next to one, on every surface (including space platforms), by replaying its own build logic. Big saves are rebuilt a few parts per tick, so there is no freeze. Nothing is done on a new map or when everything is already registered.
    - Items that were held in a balancer's internal buffer (at most two per output lane) when the old mod was removed cannot be recovered.
    - belt-balancer-statistics no longer needs a player (it works from the server console and writes to the log). New remote interface 'belt-balancer-unofficial' (statistics, fingerprint, rebuild, rebuild_pending).
    - Added incompatibility with belt-balancer-3 (identical prototype names).
  Thanks:
    - knoxfighter, archiehalliwell, IThundxr (Belt Balancer 2) and NightPablo (Belt Balancer 3).
Version: 1.0.2
Date: 24.10.2026
  Changes:
    - Migrated to Factorio 2.1 (factorio_version and base dependency raised to 2.1).
    - 2.1 API: replaced the removed LuaEntity::neighbours with LuaEntity::underground_belt_neighbour when rotating underground belts.
    - Fixed the "other end" direction of a rotated underground belt: it now uses the 16-direction enum (180 degrees = +8 modulo 16) instead of the old 8-direction maths.
    - Loaders: every loader is now detected by prototype type (loader / loader-1x1) instead of by name, so any loader mod works, not only Loaders Modernized.
    - Removed the unused on_post_entity_died handler (that event has no 'entity' field) and the dead 'created_entity' fallback.
    - Entity handlers now use a type lookup table and an if/elseif chain instead of several string.find calls per event.
    - Memory leak: removing a balancer part never cleaned its belts and lanes from 'storage' (the code checked 'belt.valid' on a plain table). It now checks 'belt.entity.valid'.
    - Fixed a scoping bug where 'found_lane' was always nil when a splitter was removed from a balancer's input side.
    - Fixed belt_functions.check_track using an undefined variable, which could leave 'next_belt_check' pointing at a deleted belt (crash in on_tick).
    - Fixed a possible crash in the nth_tick handler when its event list no longer exists.
    - test.lua (about 2000 lines) is only loaded when running with debug and creative-mod, which saves memory in normal games.
    - Removed a debug print of the whole technology table at startup.
    - Fixed the typo 'wieght' in the balancer-part item prototype (now 'weight'; the intended 25 kg is applied).
  Thanks:
    - 6oundwave, for presenting the solution to make the mod compatible with several loader mods.

Version: 1.0.1
Date: 18.11.2025
  Changes:
    - 'durability' bug discovered thanks to cartwer.
    - Fixed thanks to Maximagor.

Version: 1.0.0
Date: 01.11.2025
  Changes:
    - Fixing bugs by version 2
    - Now can place belt balancer into plataform space