2 unstable releases

0.2.0-alpha.1+mc.1.20.1 Aug 10, 2023
0.0.1 Oct 30, 2022

#29 in #minecraft-server

Download history 25/week @ 2024-01-06 17/week @ 2024-01-13 15/week @ 2024-01-20 6/week @ 2024-01-27 7/week @ 2024-02-03 19/week @ 2024-02-10 43/week @ 2024-02-17 59/week @ 2024-02-24 30/week @ 2024-03-02 49/week @ 2024-03-09 49/week @ 2024-03-16 57/week @ 2024-03-23 105/week @ 2024-03-30 45/week @ 2024-04-06 57/week @ 2024-04-13 49/week @ 2024-04-20

262 downloads per month
Used in 13 crates (5 directly)

MIT license

620KB
13K SLoC

valence_protocol

A protocol library for Minecraft: Java Edition. Use this to build clients, servers, proxies, or something novel!

valence_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 valence_protocol::{PacketEncoder, PacketDecoder, Difficulty};
use valence_protocol::packets::play::DifficultyS2c;

let mut encoder = PacketEncoder::new();

let packet = DifficultyS2c {
    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::<DifficultyS2c>().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, valence_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.

Dependencies

~19MB
~412K SLoC