No description
  • JavaScript 99.6%
  • Shell 0.4%
Find a file
2025-03-18 01:01:35 +02:00
.github node 22 (#568) 2025-01-26 23:06:36 +01:00
docs Update API.md fix chat message handling (#575) 2025-02-06 13:54:38 -05:00
examples Fix example in README.md for 1.21 (#506) 2024-07-05 07:22:05 -04:00
src Quicken tests 2025-02-13 15:36:33 -05:00
test Quicken tests 2025-02-13 15:36:33 -05:00
tools Add retry to tests 2025-01-02 16:16:33 -05:00
types 1.17 support (#99) 2021-06-09 17:26:44 -04:00
.gitignore Add missing data to client login user chain (#420) 2023-06-25 14:20:50 -04:00
.gitpod setup some CI and basics (#47) 2021-03-14 00:49:17 +01:00
.gitpod.DockerFile setup some CI and basics (#47) 2021-03-14 00:49:17 +01:00
.npmignore Ignore unconnected packets, remove babel (#185) 2022-02-21 10:35:24 +01:00
.npmrc setup some CI and basics (#47) 2021-03-14 00:49:17 +01:00
HISTORY.md Release 3.43.0 (#577) 2025-02-11 22:08:50 -05:00
index.d.ts Export functions to create packet serializer and deserializer. 2025-03-18 01:01:35 +02:00
index.js Export functions to create packet serializer and deserializer. 2025-03-18 01:01:35 +02:00
LICENSE initial commit 2016-02-13 13:09:13 -05:00
package.json Release 3.43.0 (#577) 2025-02-11 22:08:50 -05:00
README.md Export functions to create packet serializer and deserializer. 2025-03-18 01:01:35 +02:00

bedrock-protocol

NPM version Build Status Try it on gitpod

Official Discord

Minecraft Bedrock Edition (aka MCPE) protocol library, supporting authentication and encryption. Help contribute.

Protocol doc

Features

  • Supports Minecraft Bedrock version 1.16.201, 1.16.210, 1.16.220, 1.17.0, 1.17.10, 1.17.30, 1.17.40, 1.18.0, 1.18.11, 1.18.30, 1.19.1, 1.19.10, 1.19.20, 1.19.21, 1.19.30, 1.19.40, 1.19.41, 1.19.50, 1.19.60, 1.19.62, 1.19.63, 1.19.70, 1.19.80, 1.20.0, 1.20.10, 1.20.30, 1.20.40, 1.20.50, 1.20.61, 1.20.71, 1.20.80, 1.21.0, 1.21.2, 1.21.21, 1.21.30, 1.21.42, 1.21.50, 1.21.60
  • Parse and serialize packets as JavaScript objects
  • Automatically respond to keep-alive packets
  • Proxy and mitm connections
  • Client
  • Server
    • Autheticate clients with Xbox Live
    • Ping status
  • Robust test coverage.
  • Easily extend with many other PrismarineJS projects, world providers, and more
  • Optimized for rapidly staying up to date with Minecraft protocol updates.

Want to contribute on something important for PrismarineJS ? go to https://github.com/PrismarineJS/mineflayer/wiki/Big-Prismarine-projects

Installation

npm install bedrock-protocol

To update bedrock-protocol (or any Node.js package) and its dependencies after a previous install, you must run npm update --depth 9999

Usage

Client example

Example to connect to a server in offline mode, and relay chat messages back:

const bedrock = require('bedrock-protocol')
const client = bedrock.createClient({
  host: 'localhost',   // optional
  port: 19132,         // optional, default 19132
  username: 'Notch',   // the username you want to join as, optional if online mode
  offline: true       // optional, default false. if true, do not login with Xbox Live. You will not be asked to sign-in if set to true.
})

client.on('text', (packet) => { // Listen for chat messages from the server and echo them back.
  if (packet.source_name != client.username) {
    client.queue('text', {
      type: 'chat', needs_translation: false, source_name: client.username, xuid: '', platform_chat_id: '', filtered_message: '',
      message: `${packet.source_name} said: ${packet.message} on ${new Date().toLocaleString()}`
    })
  }
})

Client example joining a Realm

Example to connect to a Realm that the authenticating account is owner of or has been invited to:

const bedrock = require('bedrock-protocol')
const client = bedrock.createClient({
  realms: {
    pickRealm: (realms) => realms[0] // Function which recieves an array of joined/owned Realms and must return a single Realm. Can be async
  }
})

Server example

Can't connect locally on Windows? See the faq

const bedrock = require('bedrock-protocol')
const server = bedrock.createServer({
  host: '0.0.0.0',       // optional. host to bind as.
  port: 19132,           // optional
  version: '1.17.10',   // optional. The server version, latest if not specified. 
})

server.on('connect', client => {
  client.on('join', () => { // The client has joined the server.
    const d = new Date()  // Once client is in the server, send a colorful kick message
    client.disconnect(`Good ${d.getHours() < 12 ? '§emorning§r' : '§3afternoon§r'} :)\n\nMy time is ${d.toLocaleString()} !`)
  })
})

Ping example

const { ping } = require('bedrock-protocol')
ping({ host: 'play.cubecraft.net', port: 19132 }).then(res => {
  console.log(res)
})

Serializer/Deserializer

The createSerializer and createDeserializer functions provide direct access to the packet serialization and deserialization layer of bedrock-protocol. This is particularly useful when you need to:

  • Work with packet data without establishing a full client/server connection
  • Write unit tests for your packet handling logic
  • Analyze or debug packet structures between different Minecraft versions
  • Save and replay packet sequences for testing or benchmarking

Documentation

For documentation on the protocol, and packets/fields see the protocol documentation.

Testing

npm test

Debugging

You can enable some protocol debugging output using DEBUG environment variable.

Through node.js, add process.env.DEBUG = 'minecraft-protocol' at the top of your script.

Contribute

Please read CONTRIBUTING.md and https://github.com/PrismarineJS/prismarine-contribute

History

See history