Expand description
§chunkedge_protocol
A protocol library for Minecraft: Java Edition. Use this to build clients, servers, proxies, or something novel!
chunkedge_protocol is primarily concerned with defining all of Minecraft’s network packets and the process for encoding and decoding them. To encode and decode packets, use the PacketEncoder and PacketDecoder types.
use chunkedge_protocol::{PacketEncoder, PacketDecoder, Difficulty};
use chunkedge_protocol::packets::play::ChangeDifficultyS2c;
let mut encoder = PacketEncoder::new();
let packet = ChangeDifficultyS2c {
difficulty: Difficulty::Peaceful,
locked: true,
};
// Encode our packet struct.
encoder.append_packet(&packet);
// Take our encoded packet(s) out of the encoder.
let bytes = encoder.take();
let mut decoder = PacketDecoder::new();
// Put it in the decoder.
decoder.queue_bytes(bytes);
// Get the next packet "frame" from the decoder and use that to decode the body of the packet.
// Packet frames can be thought of as type-erased packet structs.
let frame = decoder.try_next_packet().unwrap().unwrap();
let decoded_packet = frame.decode::<ChangeDifficultyS2c>().unwrap();
// Check that our original packet struct is the same as the one we just decoded.
assert_eq!(&packet, &decoded_packet);§Supported Minecraft Versions
Currently, chunkedge_protocol only intends to support the most recent stable version of Minecraft. New Minecraft versions often entail a major version bump, since breaking changes to packet definitions are frequent.
The currently targeted Minecraft version and protocol version can be checked using the MINECRAFT_VERSION and PROTOCOL_VERSION constants.
§Feature Flags
encryption: Enables support for packet encryption.compression: Enables support for packet compression.
Modules§
- anyhow
- github crates-io docs-rs
- block_
pos - bytes
- Provides abstractions for working with bytes.
- chunk_
pos - chunk_
section_ pos - decode
- encode
- game_
mode - movement_
flags - packet_
id - Contains constants for every vanilla packet ID.
- packets
- All of Minecraft’s network packets.
- profile
- sound
- status_
effects
Macros§
- ident
- Creates a new
Identat compile time from a string literal. A compile error is raised if the string is not a valid resource identifier.
Structs§
- Biome
Pos - Block
Pos - Represents an absolute block position in world space.
- Block
State - Represents the state of a block. This does not include block entity data such as the text on a sign, the design on a banner, or the content of a spawner.
- Byte
Angle - Represents an angle in steps of 1/256 of a full turn.
- Chunk
Pos - The X and Z position of a chunk.
- Chunk
Section Pos - Compression
Threshold - How large a packet should be before it is compressed by the packet encoder.
- Fixed
Array - A fixed-size array encoded and decoded with a
VarIntlength prefix. - Fixed
BitSet - A fixed-size bit set encoded as a byte array.
- Global
Pos - Ident
- A wrapper around a string type
Swhich guarantees the wrapped string is a valid resource identifier. - Item
Stack - A stack of items in an inventory.
- Json
Text - Will always be serialized as JSON instead of NBT for backwards compatibility. See https://minecraft.wiki/w/Java_Edition_protocol/Packets#Disconnect_(login)
- Packet
Decoder - Packet
Encoder - Registry
Id - Text
- Represents formatted text in Minecraft’s JSON text format.
- Text
Component - VarInt
- An
i32encoded with variable length. - VarLong
- An
i64encoded with variable length. - Variable
BitSet - A dynamically-sized bit set encoded as a prefixed array of 64-bit words.
- Velocity
- Quantized entity velocity.
Enums§
- Block
Kind - An enumeration of all block kinds.
- Difficulty
- Direction
- Game
Mode - Hand
- IDSet
- Represents a set of IDs in a certain registry, either directly (enumerated IDs) or indirectly (tag name).
- IdOr
- Item
Kind - Represents an item from the game
- Packet
Side - The side a packet is intended for.
- Packet
State - The state in which a packet is used.
- Particle
- Sound
- Represents a sound from the game
- VarInt
Decode Error
Constants§
- MAX_
PACKET_ SIZE - The maximum number of bytes in a single Minecraft packet.
- MINECRAFT_
VERSION - The stringified name of the Minecraft version this library currently targets.
- PROTOCOL_
VERSION - The Minecraft protocol version this library currently targets.
Traits§
- Into
Text Component - Packet
- Types considered to be Minecraft packets.
- Write
Packet - Types that can have packets written to them.