2个不稳定版本

0.2.0-alpha.1+mc.1.20.12023年8月10日
0.0.1 2022年10月30日

#33#minecraft-server

Download history 47/week @ 2024-03-11 41/week @ 2024-03-18 66/week @ 2024-03-25 110/week @ 2024-04-01 39/week @ 2024-04-08 55/week @ 2024-04-15 51/week @ 2024-04-22 41/week @ 2024-04-29 35/week @ 2024-05-06 49/week @ 2024-05-13 29/week @ 2024-05-20 60/week @ 2024-05-27 26/week @ 2024-06-03 30/week @ 2024-06-10 31/week @ 2024-06-17 53/week @ 2024-06-24

140 每月下载量
用于 13 个crate (5 直接)

MIT 许可证

620KB
13K SLoC

valence_protocol

Minecraft: Java Edition的协议库。使用它来构建客户端、服务器、代理或一些新颖的应用!

valence_protocol 主要关注定义所有Minecraft的网络数据包及其编码和解码过程。为了编码和解码数据包,请使用 PacketEncoderPacketDecoder 类型。

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);

支持的Minecraft版本

目前,valence_protocol 仅打算支持Minecraft的最新稳定版本。由于数据包定义的破坏性更改很频繁,新的Minecraft版本通常涉及主要版本号的提升。

当前的目标Minecraft版本和协议版本可以使用 MINECRAFT_VERSIONPROTOCOL_VERSION 常量来检查。

功能标志

  • encryption: 启用数据包加密支持。
  • compression: 启用数据包压缩支持。

依赖项

~19MB
~409K SLoC