Fix dedicated servers crashing on the crafting job toast packet - #220
Open
rubensworks wants to merge 2 commits into
Open
Fix dedicated servers crashing on the crafting job toast packet#220rubensworks wants to merge 2 commits into
rubensworks wants to merge 2 commits into
Conversation
CraftingJobFinishedToastPacket referred to CraftingJobToast from its actionClient method. NeoForge no longer strips @onlyin code at runtime (removed in 21.7.3-beta), so on a dedicated server the JVM verifier has to load net.minecraft.client.gui.components.toasts.Toast while linking the packet class, which fails with a NoClassDefFoundError as soon as the packet is registered in CommonProxy. All toast logic now lives in the client-only CraftingJobToastHelpers, which the packet only calls through an invokestatic with common parameter types, so nothing client-only is loaded during linking. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EBwhTHkNq8t5DCWWg497ye
The packet now resolves the ingredient component and deserializes the instance itself, and only hands typed common values to the client-only helper, instead of passing its raw serialized state along. Replaces the bytecode scan on this one packet with a test that links every packet class through a class loader that hides net.minecraft.client, which is the condition that actually breaks dedicated servers, and covers all packets rather than just this one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EBwhTHkNq8t5DCWWg497ye
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
All NeoForge server jobs on 26.1.2 and 26.2 fail in CyclopsMC/packtests#72 (failing job):
CommonProxy.java:47registersCraftingJobFinishedToastPacket, added in 1.9.0.CraftingJobFinishedToastPacket.actionClientreferred toCraftingJobToast, which implements the client-onlyToast. The method was marked@OnlyIn(Dist.CLIENT), but NeoForge stopped stripping@OnlyIncode at runtime in 21.7.3-beta, so the body survives on a dedicated server. Reading the packet'sID/CODECstatics during registration links the class, and the verifier then has to check thatCraftingJobToastis assignable toToastfor thetoasts.addToast(...)call. That loadsToast, which does not exist on a server.This is not packtests- or gametest-specific: it breaks every NeoForge dedicated server running IntegratedTerminals 1.9.0 on 26.x. MC 1.21.1 is unaffected at runtime only because NeoForge 21.1 still strips
@OnlyIn.Neighbouring packets such as
TerminalStorageIngredientCraftingOptionsPacketare fine despite importingMinecraft:Minecraft.getInstance().execute(...)needs no assignability check against a client type, so the verifier never loads one. That is exactly why this is worth a test rather than a convention.Change
Toast display moves to the client-only
CraftingJobToastHelpers. The packet keeps the common work (config check, component lookup, deserialization) and hands the helper typed common values, so the call is aninvokestaticwith only common parameter types and linking the packet loads nothing client-only. The now-pointless@OnlyInis dropped.TestPacketsLinkOnDedicatedServerlinks every class in the packet package through a class loader that hidesnet.minecraft.client, which is the condition that actually breaks dedicated servers. On the previous code it reproduces the production error exactly:It covers all packets rather than just this one, and it does not forbid the safe
Minecraft.getInstance()usages that other packets rely on.Behaviour is unchanged: the same toast, with the same grouping and quantity formatting.
Why a test and not just the fix
A dev run cannot catch this.
runGameTestServerruns against the merged client+server jar, soToastis present and the packet links fine. Only a production dedicated server has the client classes absent, which is why packtests found it and this repo's own CI did not. The test above puts that condition into the normal unit test run.Validation
./gradlew buildand./gradlew runGameTestServerpass.Upmerge
This targets
master-1.21-lts, where the feature originated, but the actual crash is onmaster-26-ltsandmaster-26. Those branches usegetToastManager(),IngredientComponent.REGISTRY.getValue, and theTagValueInput/TagValueOutputserializer API, so the upmerge needs those adjusted in the new helper.🤖 Generated with Claude Code
https://claude.ai/code/session_01EBwhTHkNq8t5DCWWg497ye