TFMG Electricity Performance Patch

Fixes the per-tick electrical network rebuild loop and the quadratic network update in Create: The Factory Must Grow.
mzg | TFMG Electricity Performance...
Create a server, get 25% off your first monthaffiliate logo
Create Server
affiliate banner image

What this is

An unofficial performance and crash patch for Create: The Factory Must Grow (TFMG) 1.2.0 on NeoForge 21.1.x / Minecraft 1.21.1.

Mixins only. TFMG itself is not modified or redistributed — no content, recipes, registries or worldgen are touched. Install it next to TFMG, remove it any time; nothing is written to your world.

The performance problem

If you have an electric motor on your grid, TFMG recalculates that entire electrical network 20 times per second, forever — even when nothing changes. And a single recalculation is written in a way that costs O(n²) in the size of the grid, so doubling your wiring quadruples the cost of every tick.

That combination is why long power lines and electric motors tank TPS and FPS.

What it fixes

1. Infinite network update loop on the electric motor. ElectricalNetwork.updateNetwork() notifies every member via onNetworkChanged(..). ElectricMotorBlockEntity answers that notification with updateNextTick(), which makes tickElectricity() call updateNetwork() again next tick, which notifies the motor again — forever.

Every other consumer guards its reaction with a change check:

if (voltage != getData().getVoltage() || powerUsage != getPowerUsage())

The motor is the only one that reacts unconditionally. It is now held to the same guard, so an unchanging grid asks for nothing while a real change still propagates. delayedUpdate, notifyUpdate() and updateGeneratedRotation() behave exactly as before.

1.0.0 and 1.1.0 removed this call outright rather than guarding it, which could leave a transformer with no output on a grid where the motor was the only repeated source of change. Fixed in 1.2.0 — update if you are on an earlier version.

2. Quadratic cost of a single network update. The last loop of updateNetwork() calls getCableCurrent(member) once per cable, and that method sums the current over all members — the same value every time, since it ignores its argument. It is now computed once per update and reused. Nothing in that loop changes voltages or resistances, so the reused value is identical to what the original code would produce. O(n²) → O(n).

This matters even more with transformers and switches on the grid, because getCurrent() calls resistance(), and VoltageAlteringBlockEntity.resistance() is itself O(n) — the original update degrades towards O(n³).

3. Empty accumulator: a second per-tick rebuild loop. AccumulatorBlockEntity.tick() calls updateNextTick() on every tick while the bank is empty, which is a completely normal state. Throttled to once per 20 ticks — the network still learns the bank ran dry, at most a second later.

4. Large switch rebuilding the whole graph on an overloaded grid. LargeSwitchBlockEntity.lazyTick() calls onPlaced() while notEnoughPower is set, which re-runs checkForLoops() and onConnected() — a recursive flood over the entire grid through getBlockEntity() lookups. Throttled to one attempt per 10 lazy ticks (~5 s).

The crash it fixes

Looking at a steel tank through Engineer's Goggles and breaking a block of it takes the client down:

NullPointerException: Cannot invoke "SteelTankBlockEntity.getBlockPos()" because
the return value of "SteelTankBlockEntity.getControllerBE()" is null
  at SteelTankBlockEntity.addToGoggleTooltip(SteelTankBlockEntity.java:423)
  at GoggleOverlayRenderer.renderOverlay(GoggleOverlayRenderer.java:111)

getControllerBE() returns null for the frames between a block of a multiblock being broken and connectivity being recomputed, and the tooltip dereferences it without a check. It runs on the render thread, so the NPE is fatal. TFMG guards against exactly this in FireboxBlockEntity, VatBlockEntity and BlastStoveBlockEntity, all of which open their tooltip with if (getControllerBE() == null) return false; the steel tank is missing that line.

5. The guard is restored on the steel tank, and on the two other tooltips with the identical defect: the distillation controller (tank.getControllerBE().activeHeat, which falls back to the tank's own value) and the regular engine (getControllerBE().addToGoggleTooltip(..) on a non-controller block).

Install

Drop the jar into mods/ alongside TFMG.

Needed on both the server and the clients. The client builds electrical networks too and runs the same loop, so without the patch client-side you keep the FPS drop. displayTest = "IGNORE_ALL_VERSION" is set, so it can be installed on one side only without a mod-list mismatch.

If you update TFMG

The mixin config uses "defaultRequire": 1, so if a target method changes in a future TFMG version the game will fail to start with a clear Mixin error instead of silently doing nothing and bringing the lag back. If that happens, remove this patch.

Notes

Not affiliated with the TFMG author. Findings are from decompiling tfmg-1.2.0.jar; the intent is that these fixes end up upstream, at which point this patch becomes unnecessary.

The TFMG Electricity Performance Patch Team

profile avatar
Owner
  • 10
    Projects
  • 5.0K
    Downloads

More from mzgView all

  • Ghost Names project image

    Ghost Names

    Player name tags disappear from the world. Right-click someone and their name fades in for ten seconds, then fades away. Tab list untouched, client side only.

    • 465
    • September 7, 2026
  • Gear Vanish project image

    Gear Vanish

    Turn your armor into cosmetics: hide it, or keep only the trim glowing on bare skin. Synced to everyone, with rules that bring gear back when it matters.

    • 596
    • September 7, 2026
  • Window Resize Fix (Iris & Distant Horizons) project image

    Window Resize Fix (Iris & Distant Horizons)

    Fixes Distant Horizons breaking after a window resize with Iris, and the world's depth buffer not following a replaced render target.

    • 957
    • September 3, 2026
  • Technologia.create project image

    Technologia.create

    A NeoForge 1.21.1 Create-focused modpack blending factory automation, cannons, aeronautics, trains, and liquid fuel with cozy farming, cooking, and decoration mods for an industrial-meets-rustic survival experience.

    • 166
    • August 14, 2026
  • Ghost Names project image

    Ghost Names

    Player name tags disappear from the world. Right-click someone and their name fades in for ten seconds, then fades away. Tab list untouched, client side only.

    • 465
    • September 7, 2026
  • Gear Vanish project image

    Gear Vanish

    Turn your armor into cosmetics: hide it, or keep only the trim glowing on bare skin. Synced to everyone, with rules that bring gear back when it matters.

    • 596
    • September 7, 2026
  • Window Resize Fix (Iris & Distant Horizons) project image

    Window Resize Fix (Iris & Distant Horizons)

    Fixes Distant Horizons breaking after a window resize with Iris, and the world's depth buffer not following a replaced render target.

    • 957
    • September 3, 2026
  • Technologia.create project image

    Technologia.create

    A NeoForge 1.21.1 Create-focused modpack blending factory automation, cannons, aeronautics, trains, and liquid fuel with cozy farming, cooking, and decoration mods for an industrial-meets-rustic survival experience.

    • 166
    • August 14, 2026