Skip to content

Conversation

@mineLdiver
Copy link
Member

This pull request aims to address a few issues with the current identifiable packet system in StationAPI.

Specifically:

  1. Packet size. Each packet writes its string identifier in full instead of using a more compact ID.
  2. Awkward API. Current API tries to mimic the vanilla packets system, awkwardly so, and not taking enough advantage of the systems StationAPI provides within itself.
  3. Name conflicts. IdentifiablePacket interface adds the getId() 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 method getRawId(), but breaks with mappings such as Nostalgia which use getId() instead of getRawId(), 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 PacketType class and StationAPI's registries.

Since packets are short-lived objects, they can't be managed by a registry, thus the PacketType class 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 ManagedPacket and return its packet type in the getType() 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 PacketTypeRegistry before 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 blocking flag 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 MessagePacket are fine, however, mods that use IdentifiablePacket will have to switch to ManagedPacket.

@mineLdiver mineLdiver added this to the 2.0-alpha.3 milestone Jul 16, 2024
@mineLdiver mineLdiver added the enhancement New feature or request label Jul 16, 2024
@mineLdiver mineLdiver self-assigned this Jul 16, 2024
# Conflicts:
#	station-networking-v0/src/main/java/net/modificationstation/stationapi/mixin/network/ConnectionMixin.java
#	station-networking-v0/src/main/java/net/modificationstation/stationapi/mixin/network/PacketMixin.java
@mineLdiver mineLdiver merged commit d719b2a into 2.0-alpha.3 Nov 2, 2024
mineLdiver added a commit that referenced this pull request Nov 30, 2024
* First version of tool items update

* Mining levels graph

* Fix a bad mixin declaration in lifecycle events

* Add RegistriesFrozenEvent

* Yeet deprecated code

* *actually* remove deprecated stuff

* Dependency debloat (#126)

* Partial dependency debloat (doesn't yet compile)

* Partial dependency debloat part 2 (still doesn't compile)

* Finished debloating

* Use `Pair#of` instead of `Pair#new`

* Remove dependency declarations

* Move client-side entity registries to client.registry package.

* Packet types (#123)

* Implemented packet types (registry sync is broken).

* Introduced blocking packets. Fixed packet types registry sync.

* Re-enabled GCAPI and HMI

* Use WrapOperation instead of Redirect in network

* Tools API (#133)

* Simpler and more flexible

* More tools API documentation

* Organized `TestContext#failed` into levels of BFS

* Allow tool levels to be equivalent to their immediate siblings

* Moved tools system implementation into mixins for easier override by custom tools. Now infinite loops during graph search are detected and logged with relevant information.

* Replaced item stack effectiveness and strength events with player ones to allow for null item stack checks

* Propagated more context to tool item effectiveness and strength tests

* Added a method for instantiating numeric tool levels

* Documentation for the resultProvider fields of tool events.

* Change version

---------

Co-authored-by: calmilamsy <bumbill00@gmail.com>
@mineLdiver mineLdiver deleted the packet-types branch December 1, 2024 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant