No description
Find a file
2025-08-27 03:43:18 +01:00
.github/workflows Rework io for variable length number reading 2024-09-02 13:56:18 +01:00
.vscode Sans-IO correct implementation behaviour 2024-03-05 19:29:42 +00:00
src Add ID check, since that's important. 2024-09-04 21:58:05 +01:00
tests Packet reading was still broken, oops again, made names more consistent (read/writeVarNum -> read/writeVar 2024-09-03 20:26:15 +01:00
.gitignore Rework library slightly, add docs, add workflow. 2023-10-02 23:14:27 +01:00
modernnet.nimble Add package.skull.toml 2025-08-27 03:43:18 +01:00
package.skull.toml Add package.skull.toml 2025-08-27 03:43:18 +01:00
README.md Update README.md 2024-03-17 22:13:29 +00:00

ModernNet

ModernNet is a barebones library to interact with the Minecraft Java Edition protocol!

To support IO, I've taken the Sans-I/O approach, separating the protocol from the IO, it can easily be implemented in any library with this code:

# Set up the buffer
var buffer = newBuffer()

buffer.writeVarNum[:int32](0x27)
buffer.writeVarNum[:int32](8)
buffer.writeNum[:int64](23142)

buffer.pos = 0

# Commence tests~
var b: seq[byte] # Pretend this is a buffered socket

var res = readRawPacket(b)

while not res.isOk:
  b.add buffer.readNum[:byte]()
  res = readRawPacket(b)

assert res.ok.packet.id == 0x27
assert res.ok.packet.buf.readVarNum[:int32]() == 8
assert res.ok.packet.buf.readNum[:int64]() == 23142
assert res.ok.bytesRead == 10 # The ID, length and the data in the buffer

Useful Notes

An empty packet with size 0 needs to be handled by the user currently, if packetLength <= 0: return is enough to usually detect if a socket has closed.

To-Dos

  • Work on better documentation, with more examples.

  • Implement MC auth for the library.

    • This isn't a must, but it would improve the QoL of developers who use this library.
  • Wrap all packets and relating data for each MC version (and sharing the types/code when possible).

    • Not a requirement but would be nice: Create an API to parse a packet from a socket/buffer without any other manual code.
    • https://github.com/PrismarineJS/minecraft-data would likely be a very good starting point for automating generation of the packet wrappers.
  • Add more tests for verifying everything is working correctly.

    • A W.I.P server is being made with this library so that more tests can be added.

Completed Goals

  • Rewrite code to avoid streams (unnecessary overhead).
    • Look at src/modernnet/buffer.nim for this functionality.

Unplanned/Scrapped

  • Allow for the full API of encoding and decoding to be used even on sockets.
    • I've decided that doing everything via Buffers is much better as it allows for us to handle errors more gracefully.