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.
This pull request aims to address a few issues with the current identifiable packet system in StationAPI.
Specifically:
IdentifiablePacketinterface adds thegetId()method, which works fine with biny mappings, since it takes on the modern approach of naming numeric IDs "raw" IDs, thus naming the vanilla ID methodgetRawId(), but breaks with mappings such as Nostalgia which usegetId()instead ofgetRawId(), making the mappings unusable with StationAPI.Following changes were implemented:
Concise API
Instead of trying to mimic the vanilla packet system, this pull request implements its own system centered around
PacketTypeclass and StationAPI's registries.Since packets are short-lived objects, they can't be managed by a registry, thus the
PacketTypeclass is created to hold the packet's properties and factory method. This is way more intuitive compared to the current implementation, which has these values scattered all over the system across multiple collections.All the packet class has to do itself is implement
ManagedPacketand return its packet type in thegetType()method, which doesn't conflict with Nostalgia mappings.However, additionally, each packet can also define its type in a static field, giving better encapsulation of the packet's properties and factory method (default constructor can be made private).
Raw IDs
Every packet type requires that it's added to the
PacketTypeRegistrybefore the game finishes initialization. This behavior enables us to take advantage of the registry's raw IDs and remapping capabilities to greatly reduce packet size.This is achieved by reserving raw ID 0 to the client registry remap packet and with the fact that it's the first custom packet sent between client and server.
However, since packet reading is async, the read thread must be blocked until the remapping is finished. This is achieved with the introduction of the
blockingflag in packet types, which forces the read thread to wait until the blocking packet is finished applying.However, the public API backwards compatibility does break with this new system. Mods that use
MessagePacketare fine, however, mods that useIdentifiablePacketwill have to switch toManagedPacket.