Metadata-Version: 2.4
Name: bedrock-protocol
Version: 0.5.0
Summary: Minecraft: Bedrock Edition network protocol
Author: GlacieTeam
Author-Email: EndstoneMC <hello@endstone.dev>
Maintainer-Email: Vincent Wu <magicdroidx@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Project-URL: Homepage, https://github.com/EndstoneMC/bedrock-protocol
Project-URL: Issues, https://github.com/EndstoneMC/bedrock-protocol/issues
Requires-Python: >=3.12
Description-Content-Type: text/markdown

<div align="center">

<h3>bedrock-protocol</h3>

<p>
  <b>The Minecraft: Bedrock Edition network protocol for C++, Python and Java</b>
</p>

[![CI](https://github.com/EndstoneMC/bedrock-protocol/actions/workflows/ci.yml/badge.svg)](https://github.com/EndstoneMC/bedrock-protocol/actions/workflows/ci.yml)
[![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)

</div>

## Python

### Install

Install the Linux or Windows wheel for Python 3.12 or newer from PyPI:

```shell
uv pip install bedrock-protocol
```

Or build it from a checkout with CMake and a C++23 compiler:

```shell
git clone https://github.com/EndstoneMC/bedrock-protocol
uv pip install ./bedrock-protocol
```

### Encode and decode

```python
import bedrock_protocol as bp

packet = bp.TextPacket()
packet.body = bp.TextPacket.MessageOnly(type=bp.TextPacketType.CHAT, message="hello")
data = bp.encode(packet)
decoded = bp.decode(bp.TextPacket, data)
assert decoded == packet
```

### Pick a protocol

```python
version = bp.ProtocolVersion.get(2193)
assert version is not None and version.name == "1.26.50"

pinned = bp.v2193.encode(packet)
picked = bp.v2193.decode(bp.TextPacket, pinned)
assert picked == packet
```

## C++

### Install

Unpack a package from the [releases](https://github.com/EndstoneMC/bedrock-protocol/releases) and point `CMAKE_PREFIX_PATH` at its folder:

```cmake
find_package(bedrock-protocol CONFIG REQUIRED)
target_link_libraries(my_target PRIVATE bedrock::protocol)
```

### Encode and decode

```cpp
#include <cassert>

#include <bedrock/protocol.hpp>

namespace bp = bedrock::protocol;

bp::TextPacket packet;
packet.body = bp::TextPacket::MessageOnly{.type = bp::TextPacketType::Chat, .message = "hello"};

std::expected<std::string, bp::EncodeError> data = bp::encode(packet);
assert(data);
std::expected<bp::TextPacket, bp::DecodeError> decoded = bp::decode<bp::TextPacket>(*data);
assert(decoded && *decoded == packet);
```

### Pick a protocol

```cpp
std::optional<bp::ProtocolVersion> version = bp::ProtocolVersion::get(2193);
assert(version && version->getName() == "1.26.50");

std::expected<std::string, bp::EncodeError> pinned = bp::v2193::encode(packet);
assert(pinned);
std::expected<bp::TextPacket, bp::DecodeError> picked = bp::v2193::decode<bp::TextPacket>(*pinned);
assert(picked && *picked == packet);
```

## Java

### Install

Add the package from Maven Central to a Gradle build:

```kotlin
dependencies {
    implementation("dev.endstone:bedrock-protocol:X.Y.Z")
}
```

Or build it from a checkout with JDK 21 and Python 3.12 or newer into the local Maven repository:

```shell
git clone https://github.com/EndstoneMC/bedrock-protocol
cd bedrock-protocol/java
./gradlew publishToMavenLocal
```

### Encode and decode

```java
import dev.endstone.protocol.Protocol;
import dev.endstone.protocol.TextPacket;
import dev.endstone.protocol.TextPacketType;

TextPacket packet =
        TextPacket.newBuilder()
                .setMessageOnly(
                        TextPacket.MessageOnly.newBuilder()
                                .setType(TextPacketType.CHAT)
                                .setMessage("hello")
                                .build())
                .build();

byte[] data = Protocol.encode(packet);
TextPacket decoded = Protocol.decode(TextPacket.class, data);
assert decoded.equals(packet);
```

### Pick a protocol

```java
import dev.endstone.protocol.ProtocolVersion;

import java.util.Optional;

Optional<ProtocolVersion> version = ProtocolVersion.get(2193);
assert version.isPresent() && version.get().getName().equals("1.26.50");

byte[] pinned = Protocol.v2193.encode(packet);
TextPacket picked = Protocol.v2193.decode(TextPacket.class, pinned);
assert picked.equals(packet);
```

## Supported Protocols

| Protocol | Releases |
| --- | --- |
| 729 | 1.21.30 to 1.21.31 |
| 748 | 1.21.40 to 1.21.44 |
| 766 | 1.21.50 to 1.21.51 |
| 776 | 1.21.60 to 1.21.62 |
| 786 | 1.21.70 to 1.21.73 |
| 800 | 1.21.80 to 1.21.84 |
| 818 | 1.21.90 to 1.21.92 |
| 819 | 1.21.93 to 1.21.95 |
| 827 | 1.21.100 to 1.21.102 |
| 844 | 1.21.111 to 1.21.114 |
| 859 | 1.21.120 to 1.21.123 |
| 860 | 1.21.124 |
| 898 | 1.21.130 to 1.21.132 |
| 924 | 1.26.0 to 1.26.3 |
| 944 | 1.26.10 to 1.26.14 |
| 975 | 1.26.20 to 1.26.23 |
| 1001 | 1.26.30 to 1.26.36 |
| 2168 | 1.26.40 to 1.26.44 |
| 2169 | 1.26.45 |
| 2193 | 1.26.50 to 1.26.52 |
| 2225 | 1.26.6x |

## Building from Source

With CMake, Ninja, Python 3.12 or newer and a C++23 compiler, from a Visual Studio developer prompt on Windows:

```shell
cmake --preset release
cmake --build --preset release
cmake --install build/Release --prefix stage
uv sync
```

## License

MIT, see [LICENSE](LICENSE).
