Repository navigation
Fix WorldStorage crashing on clients connected to a server - #264
Merged
Merged
Conversation
WorldStorage.Access#get() assumed a server was always running, so calling it on a client connected to a dedicated server threw an NPE. This happens when other mods assemble crafting recipes client-side, such as AE2's pattern encoding terminal assembling Integrated Dynamics' omni-directional connector recipe, which disconnected the client. When no server is running, a transient non-persisted instance is now returned instead. Closes CyclopsMC/IntegratedDynamics#1793 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UeSuG81BxHPwYueMgjzZz3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UeSuG81BxHPwYueMgjzZz3
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
Reported in CyclopsMC/IntegratedDynamics#1793: on a dedicated server, putting the Omni-Directional Connector recipe into an AE2 pattern encoding terminal disconnects the client with "Network Protocol Error". Because the grid contents persist, the client is kicked again every time it reopens the terminal.
AE2 calls
recipe.assemble()on the client to show the output. ID's omni connector recipe uses aRecipeCraftingShapedCustomOutputoutput transformer that callsIntegratedDynamics.globalCounters.get().WorldStorage.Access#get()assumesServerLifecycleHooks.getCurrentServer()is non-null, which is not the case on a client connected to a remote server:Singleplayer is not affected, since the integrated server is present. Only the 26.x branches have this bug: on
master-1.20-ltsandmaster-1.21-lts,GlobalCountersis a plain object that does not look up the server when accessed. So this targetsmaster-26-lts.Change
When no server is running,
WorldStorage.Access#get()now returns a lazily created transient instance (from theSavedDataTypefactory with a null level) instead of throwing. It is not persisted nor synced. For the omni connector, this only affects the client-side preview: the group id there is a throwaway, and the real id is still generated server-side when crafting. ID'sLabelsWorldStorage.Accessalready keeps its own client instance by overridingget(), so it is unaffected.Behaviour while a server is running (dedicated or integrated) is unchanged.
Limitations:
WorldStoragewhose factory dereferences the level would still throw on a remote client, as before. None of the ones I found (GlobalCounters, ID's labels) do.ItemEntangledChalicealso callsglobalCounters.get(). I did not check whether that path can run client-side.Testing
Setup: dedicated dev server (NeoForge 26.1.2.126, ID 1.37.1, AE2 26.1.13-beta) with a dev client driven by clientdevbridge.
omnidirectional_group=2).groupId:4. ID network diagnostics show two separate networks before the second connector is placed, and one network (4 cables, both readers, both connectors) after. Right-clicking a placed connector reports "Group: 4"../gradlew buildand./gradlew runGameTestServer: pass.Note: the group shown in the client-side preview, the encoded pattern's output, and the actual crafted item all differ (2, 2 and 4 here), because each
assemble()call generates a new id. That is how ID's recipe works (it also happens in singleplayer) and is not changed by this PR.Closes CyclopsMC/IntegratedDynamics#1793
🤖 Generated with Claude Code
https://claude.ai/code/session_01UeSuG81BxHPwYueMgjzZz3