Network (rnet)

Sending

Build packets from scratch and the ready-made helpers for common ones.

Building packets

rnet.new(name, ...)

Builds a new outgoing packet from a name and constructor arguments, and returns a packet object. Nothing is sent until you call p:send().

An argument can be a nested object built with a table that has a _new field holding the class name, followed by that object's own arguments.

rnet.ctors(name)

Returns the list of constructors that exist for a packet name, so you can see which arguments rnet.new expects.

rnet.send(name, ...)

Builds a packet, sends it, frees it, and returns whether it was sent.

rnet.send("chat_command", "say hello")

rnet.receive(name, ...)

Builds a packet and injects it as if the server had sent it.

rnet.try(variants)

Tries several {name, arg1, arg2, ...} entries in order and returns the first packet that builds. If none do, returns nil and the last error. Useful because constructors can differ between game versions.

Ready-made helpers

Each helper tries the packet constructors that are known to work and returns true if the packet was sent.

rnet.say(text)

Sends an unsigned chat message through the real chat packet. Falls back to mc.chat if that fails.

rnet.command(cmd)

Sends a command. A leading / is removed. Falls back to mc.chat("/" .. cmd).

rnet.move(x, y, z, onGround = true)

Sends a position update.

rnet.rotate(yaw, pitch, onGround = true)

Sends a rotation update.

rnet.onGround(v = true)

Sends an on-ground-only update.

rnet.swing(hand = "MAIN_HAND")

Sends an arm swing.

rnet.heldSlot(i)

Sends a hotbar slot change.

rnet.say("hello")
rnet.command("/spawn")
rnet.swing()

Packets sent this way go straight to the server. The client does not update its own state to match, so the two can disagree.