Skip to content

Fix writer part aspects not activating during network initialization - #1710

Open
rubensworks wants to merge 1 commit into
master-1.21-ltsfrom
claude/fix-writer-aspect-activation-1628
Open

Fix writer part aspects not activating during network initialization#1710
rubensworks wants to merge 1 commit into
master-1.21-ltsfrom
claude/fix-writer-aspect-activation-1628

Conversation

@rubensworks

Copy link
Copy Markdown
Member

Fixes a regression from ba6dd95 (1.34.1) that breaks all Integrated Tunnels parts.

The regression

That commit moved the aspect (de)activation of PartStateWriterBase#triggerAspectInfoUpdate inside the !isNetworkInitializing branch:

if (!isNetworkInitializing) {
    onVariableContentsUpdated(partType, target);

    IAspectWrite activeAspect = getActiveAspect();
    ...
    this.activeAspect = newAspect;   // only runs when NOT initializing
}

The goal was to stop beforeNetworkKill (which passes newAspect = null, isNetworkInitializing = true) from clearing the active aspect, as that null would then be persisted, which is what #1628 and #1697 were about.

But the guard also disabled the other half of the lifecycle. afterNetworkAlive activates parts through updateActivation(target, state, null), and isNetworkInitializing is derived from player == null, so it is true there as well. Since 1.34.1, the active aspect is therefore never assigned, and IAspectWrite#onActivate is never called, when a network is built. That happens on every world load and on every network rebuild (placing or breaking any cable).

Integrated Dynamics' own writers keep working because their active aspect is restored from NBT, and their aspects don't need onActivate. Add-ons do: onActivate is what registers their parts with the positioned addons network. All Integrated Tunnels importers, exporters and interfaces stop working as a result.

The reason this was not caught is that the same commit changed the placeVariableInWriter game test helper to pass helper.makeMockPlayer(...), which makes isNetworkInitializing false. Add-ons configure their parts without a player, so they take the broken path.

The fix

The two halves are separated again:

  • Aspects are activated and deactivated at most once, tracked by a non-persisted activeAspectActivated flag. Networks are killed and revived without the aspect itself changing, so this prevents both deactivating an aspect twice and skipping its reactivation.
  • The active aspect is only forgotten outside of network initialization, which is what variables is not active in item importer on world load. #1628 needed.

onVariableContentsUpdated keeps being skipped during network init, as before.

Verification

Both suites were run against the same build.

Suite Before After
Integrated Dynamics runGameTestServer 891/891 pass 892/892 pass
Integrated Tunnels runGameTestServer 62 of 146 fail 146/146 pass

The Integrated Tunnels runs used master-1.21-lts published to Maven local, with NeoForge, CyclopsCore and CommonCapabilities held constant, so the ID jar was the only difference. For reference, Integrated Tunnels also passes 146/146 against the released 1.32.0, which is from before the regression.

testCombinedAspectsWriterPersistsAfterNetworkRebuild, the regression test that ba6dd95 added for #1628, still passes.

This PR also adds testCombinedAspectsWriterActivatesWithoutPlayer, which configures a writer without a player, the path that add-ons and network initialization use. Without the fix it fails with Aspect was not activated without a player, but was null.

Branches

master-1.20-lts and master-1.19-lts are not affected: ba6dd95 is only contained in master-1.21-lts, and both older branches still have the activation outside the isNetworkInitializing guard. So this targets master-1.21-lts only, and there is nothing to up-merge.

🤖 Generated with Claude Code

https://claude.ai/code/session_01ULVbUmc3Uk3ek3d3T4sB9V


Generated by Claude Code

ba6dd95 moved the aspect (de)activation of
PartStateWriterBase#triggerAspectInfoUpdate inside the
`!isNetworkInitializing` branch, to stop beforeNetworkKill from clearing
the active aspect and persisting that null after a world restart.

That guard however also disabled the other half of the lifecycle:
afterNetworkAlive activates parts via updateActivation without a player,
which makes isNetworkInitializing true. So since then, the active aspect
was never assigned and IAspectWrite#onActivate was never called when a
network is built, which happens on every world load and on every network
rebuild.

Integrated Dynamics' own writers survive this because their active aspect
is restored from NBT, but add-ons rely on onActivate to register their
parts with the network. All Integrated Tunnels importers, exporters and
interfaces therefore stopped working (146 of its game tests failed, and
they all pass again with this change).

The two halves are now separated again:
* Aspects are activated and deactivated at most once, tracked by a
  non-persisted flag, so that killing and reviving a network doesn't
  deactivate an aspect twice or skip its reactivation.
* The active aspect is only forgotten outside of network
  initialization, which is what the original fix needed.

Also adds a game test that configures a writer without a player, which
is the path that add-ons and network initialization use.
@coveralls

coveralls commented Aug 26, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 45.547% (+0.04%) from 45.511% — claude/fix-writer-aspect-activation-1628 into master-1.21-lts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants