Open
Conversation
modmuss50
reviewed
Jan 25, 2026
...orking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/context/PacketContext.java
Show resolved
Hide resolved
...orking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/context/PacketContext.java
Outdated
Show resolved
Hide resolved
...king-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/context/PacketContextImpl.java
Outdated
Show resolved
Hide resolved
...king-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/context/PacketContextImpl.java
Outdated
Show resolved
Hide resolved
modmuss50
reviewed
Feb 5, 2026
Member
modmuss50
left a comment
There was a problem hiding this comment.
Looking good, just a few nit picks.
...orking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/context/PacketContext.java
Outdated
Show resolved
Hide resolved
Comment on lines
89
to
91
| @Nullable | ||
| static PacketContext get() { | ||
| return PacketContextImpl.VALUE.get(); |
Member
There was a problem hiding this comment.
ScopedValue.get() throws if its not bound, in what case will this return null?
Member
Author
There was a problem hiding this comment.
Oh oops, will probably fix that then
...orking-api-v1/src/main/java/net/fabricmc/fabric/api/networking/v1/context/PacketContext.java
Outdated
Show resolved
Hide resolved
Comment on lines
+31
to
+32
| * This class allow to easily pass context between multiple packet listeners and packet serialization. | ||
| * All connections get their own unique context object. |
Member
There was a problem hiding this comment.
Nit: A simple code example or something to show how to use it may be useful.
Comment on lines
70
to
75
| * Stores the value. | ||
| * | ||
| * @param key unique key under which value is stored | ||
| * @param value value to store | ||
| */ | ||
| <T> void set(Key<T> key, T value); |
Member
There was a problem hiding this comment.
Does not document that T can be nullable, to remove.
| import net.fabricmc.fabric.test.networking.NetworkingTestmods; | ||
|
|
||
| public class PacketContextTest implements ModInitializer { | ||
| public static final Logger LOGGER = LoggerFactory.getLogger(PacketContextTest.class); |
Member
There was a problem hiding this comment.
Mega nit pick: loggers should be private.
Member
|
You could likely quite easily write a unit test to cover the basic get+set logic of this. Ill leave that up to you. |
modmuss50
approved these changes
Feb 7, 2026
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.
Packet Context is a simple way to store and access values between networking stages (login, configuration, play) and between handler/config sync/whatever and packet serialization (for example changing the vanilla packet format depending on client having XYZ).
PacketContext can be sourced from Connection and *PacketListernerImpl classes for usage outside of serialization and with PacketContext.get() (or orElseThrow()) inside.
Values can be then simply retriever with a getValue(Key) method or stored with setValue(Key, T) (or updateValues for changing multiple at the same time).
There are also provided method to run something with PacketContext.get() set up outside of vanilla packet serialization for handling the edge cases where it is needed.
The idea for this api is based from https://github.com/NucleoidMC/packet-tweaker, which is used by few mods/libraries for this feature. In case of Fabric API itself it will be useful for handling of vanilla compatibility in case of extended (stream) codec formats.
This pr is fully functional. Only things left to consider is what/if fabric should provide some contexts by default.