Host calls
Packets and plugin channels
Sending raw packets and plugin-channel messages, and decoding and encoding packet bodies.
Generated by tools/gen_api_docs.py; do not edit by hand. See host calls
for how a call is made and how values are encoded. Each example shows the shape of a Wasm
request with its required fields; the values in it are illustrative.
| Call | What it does |
|---|---|
send_payload | Sends a message on a plugin channel. |
send_packet | Sends one player a packet, as the game would have: packet names it as its hook point does (play.clientbound.set_title_text, packet. optional) and body is its bytes -- from packet_encode, or written by hand. |
packet_decode | A packet's body as its named fields (a map), for a packet this server has a schema for: ProtocolLib's PacketContainer. |
packet_encode | The other way: named fields, every one given, as the packet's bytes. |
packet_schemas | Every packet packet_decode and packet_encode know, each with its fields and their kinds: {"play.clientbound.set_health": [["health", "float"], ...]}. |
send_payload
fn send_payload(player: PlayerId, channel: &str, data: &[u8]) -> bool
Sends a message on a plugin channel.
Returns whether it went. false means the player has gone or the message was longer
than the protocol's 32767 bytes -- and the second is not a slow message, it is a
disconnect, which is why it is refused rather than split.
Wasm request
| Field | Type | Required |
|---|---|---|
player | player id (integer) | yes |
payload | list of byte values 0..=255 | yes |
channel | string | yes |
Reply: {"ok": ...} holding the Rust return value bool, encoded as in conventions.
{"call": "send_payload", "player": 7, "payload": [1, 2, 3], "channel": "example:channel"}
send_packet
fn send_packet(player: PlayerId, packet: &str, body: &[u8]) -> Result<bool, String>
Sends one player a packet, as the game would have: packet names it as its hook point
does (play.clientbound.set_title_text, packet. optional) and body is its bytes --
from packet_encode, or written by hand. Play-state, clientbound packets only,
and never one that changes the connection's state (start_configuration, login).
False if the player is not connected. ProtocolLib's sendServerPacket.
Wasm request
| Field | Type | Required |
|---|---|---|
player | player id (integer) | yes |
body | packet body bytes, lower-case hex; empty when missing | no |
packet | string | yes |
Reply: {"ok": ...} holding the Rust return value Result<bool, String>, encoded as in conventions. An Err arrives as {"error": "..."}.
{"call": "send_packet", "player": 7, "packet": "play.clientbound.block_update"}
packet_decode
fn packet_decode(packet: &str, body: &[u8]) -> Result<crate::Data, String>
A packet's body as its named fields (a map), for a packet this server has a schema for:
ProtocolLib's PacketContainer. See packet_schemas.
Wasm request
| Field | Type | Required |
|---|---|---|
body | packet body bytes, lower-case hex; empty when missing | no |
packet | string | yes |
Reply: {"ok": ...} holding the Rust return value Result<crate::Data, String>, encoded as in conventions. An Err arrives as {"error": "..."}.
{"call": "packet_decode", "packet": "play.clientbound.block_update"}
packet_encode
fn packet_encode(packet: &str, fields: &crate::Data) -> Result<Vec<u8>, String>
The other way: named fields, every one given, as the packet's bytes.
Wasm request
| Field | Type | Required |
|---|---|---|
packet | string | yes |
fields | JSON value, read into the Rust parameter fields: &crate::Data; see the doc comment | yes |
Shape and limits, as the router words its errors: "fields should be an object".
Reply: {"ok": ...} holding the Rust return value Result<Vec<u8>, String>, encoded as in conventions. An Err arrives as {"error": "..."}.
{"call": "packet_encode", "packet": "play.clientbound.block_update", "fields": {"at": [0, 64, 0], "state": "minecraft:glass"}}
packet_schemas
fn packet_schemas() -> crate::Data
Every packet packet_decode and packet_encode know, each with its
fields and their kinds: {"play.clientbound.set_health": [["health", "float"], ...]}.
Wasm request
No fields besides call.
Reply: {"ok": ...} holding the Rust return value crate::Data, encoded as in conventions.
{"call": "packet_schemas"}
From docs/api/reference/host-calls/packets.md in the RustMC repository at bbd81209ad.