Coder Social home page Coder Social logo

minecraft-protocol's Introduction

minecraft-protocol

A library crate empowering everyone to build Minecraft clients and servers.

This crate is capable of handling the parsing and creation of Minecraft packets. It contains a complete implementation of the latest Minecraft protocol, including the NBT data format. This crate also embeds exhaustive lists of blocks and entities, along with their properties.

The work relies on and contributes to a community reverse engineering effort. I have tested the whole crate on real-world Minecraft servers and successfully made a miner bot.

Usage

This crate is low-level since you will have to manage the network and learn about how the protocol works. There are WIP helper functions for reading and writing packets over a TcpStream. There is currently no support for encryption and compression.

You can serialize and deserialize any struct of this library like this:

// Serialize
let packet = ClientboundPacket::UpdateHealth {
    health: 20.0,
    food: VarInt(10),
    food_saturation: 2.0,
};
let serialized_packet: Vec<u8> = packet.serialize_minecraft_packet().unwrap();

// Deserialize
let raw_packet = [68, 160, 129, 2, 0, 0, 0, 2, 5, 0, 6, 18, 0, 4, 7, 0, 15, 13, 10, 14, 0, 0, 12, 1, 0, 13, 10, 0, 8, 2, 66, 32, 0, 0, 9, 1, 0, 11, 1, 0, 10, 7, 0, 1, 1, 172, 2, 3, 7, 0, 7, 0, 0, 5, 7, 0, 16, 7, 0, 17, 7, 0, 255];
let parsed_packet = ClientboundPacket::deserialize_minecraft_packet(&raw_packet).unwrap();

Internal design

This crate uses procedural macros to generate most of the parsing of composed structs. These macros are defined in this crate. Note that this is the only dependency.

As you can see, specifying new types is child's play:

#[derive(MinecraftPacketPart)]
struct Entity {
    entity_id: VarInt,
    x: f64,
    y: f64,
    z: f64,
}

This library consists of a bunch of structs (like this one) nested in each other. See Mubelotix/minecraft-protocol-derive for more information.

State the Minecraft + Rust ecosystem

There are many library crates for Minecraft, but they are often incomplete and outdated. This crate aims to be complete and easy to maintain. Thanks to the use of macros and build scripts, there is little parsing to implement by hand.

However, there is currently no high-level Minecraft client or server library. It would be amazing to have a batteries-included Minecraft client framework. It could handle packets, environment state, and provide easy-to-use functions. That would allow client and bot creators to focus on the logic. Minecraft isn't that complex, but there is a surprisingly large amount of content to understand in the protocol. Despite the quality of the wiki, it may still be a pain point for beginners. Thus, feel free to pursue the efforts on Minecraft in Rust as it will be highly appreciated.

minecraft-protocol's People

Contributors

mubelotix avatar c0repwn3r avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.