OrnitheMC / ornithe-standard-libraries

Apache License 2.0
8 stars 5 forks source link

add Networking API #10

Closed SpaceWalkerRS closed 1 year ago

SpaceWalkerRS commented 1 year ago

Adds a Networking module and an implementation for (13w41a)-(1.13-pre2), with the following features:

Networking API

Sending and receiving data is done through the ClientPlayNetworking and ServerPlayNetworking classes. Mods can register network listeners through the registerListener and registerListenerAsync methods, allowing them to receive data through specific channels. Sending data is done through the send methods.

Upon login, the client will initiate a "handshake" with the server, in which it will let the server know which channels the client has listeners for. The server will then reciprocate by telling the client which channels the server has listeners for. This information is then used to close channels for which there are no listeners. This is to avoid packet and log spam when one side has a mod installed but the other does not.

SpaceWalkerRS commented 1 year ago

We had some discussion before about whether the Networking API should send/receive data in NBT format. I decided against this for now and use the PacketByteBuf in order to keep the implementation as "raw" as possible. This still leaves the option open for mods utilize NBT for their networking, but encourages serializing to/from the PacketByteBufdirectly, which is probably preferable if you're sending larger amounts of data.

SpaceWalkerRS commented 1 year ago

looks good, seems to be lacking some documentation overall though, but it looks alright to me

Good point. I'll go ahead and write some before merging this in.