Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

bedrock-protocol-kodamc

PrismarineJS35MIT3.26.0TypeScript support: included

Minecraft Bedrock Edition protocol library

minecraft, bedrock, pocket-edition, protocol

readme

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
  • 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

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: '',
      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)
})

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

changelog

3.26.0

  • 1.19.70 support (@CreeperG16)
  • types: add some type hints (#354) @hvlxh

3.25.0

  • 1.19.63 support (@stevarino)
  • Add close packet in server player API doc (#347) @hvlxh

3.24.0

  • 1.19.62 support (@CreeperG16)

3.23.0

  • 1.19.60 support (@CreeperG16)
  • added onMsaCode, profilesFolder to ClientOptions (@jarco-dev)

3.22.0

  • 1.19.50 support (@WillQizza)

3.21.0

  • 1.19.40 support (#314)
  • types: Fix missing field in ServerAdvertisement (#313) (@minerj101)

3.20.1

  • Fix buffer length calculation in ServerAdvertisement (#292) (thanks @KurtThiemann)
  • Handle Relay serialization errors by kicking (#290)

3.20.0

  • Preliminary 1.19.30 support, improve error handling and server pong data (#284)

3.19.0

  • Add option for port redirection, fix Realm handling (#282)
  • Add Port Redirect Functionality (#278) @stevarino
  • Add Get-AppxPackage command to FAQ.md (#276) @stevarino
  • Remove viewer example

3.18.0

  • 1.19.21 support (#266)

3.17.0

  • relay: Add multi-user login support (#258)
  • Add fields from 1.19.20 to login chain data (#259) @CleSucre
  • Fix nbt encoding size on single null tag NBT (#264)
  • test: Add -u flag unzipping vanilla server (#262)

3.16.0

  • 1.19.20 support (#251)
  • Add new raknet library option (raknet-node) (#211) @b23r0

3.15.0

  • 1.19.10 support
  • Remove Realm fetch when joining via invite (#228) @LucienHH
  • Add Realm support to Relay (#226) @ATXLtheAxolotl

3.14.0

  • 1.19 support
  • Better handle ping timeout, update documentation (#218) @stevarino

3.13.0

  • Update API documentation
  • Emit generic 'packet' event for server clients (#205) @ATXLtheAxolotl
  • Add XUID field for client offline mode client chain (#203)

3.12.0

  • 1.18.30 support

3.11.1

  • Bump minecraft-data version

3.11.0

  • Implement Realm joining (#193) @LucienHH
  • Refactor client connection sequence (#189) @extremeheat
  • Add profilesFolder to Relay (#192) @CreeperG16
  • Emit error from relay when server can't be pinged (#191)
  • Pass relay onMsaCode to client (#190) @Heath123
  • Mark raknet-native as required dependency (#188)
  • Ignore unconnected packets, remove babel (#185)

3.10.0

  • Support 1.18.11 (#179) @extremeheat
  • Switch to sync zlib with 512k chunks, adjustable compression level (#174) @extremeheat

3.9.0

  • Proxy fixes, logging and doc updates #169

3.8.0

  • 1.18.0 support

3.7.0

  • 1.17.40 support

3.6.0

  • 1.17.30 support
  • minecraft-data used for protocol data

3.5.1

  • Fix 1.17.10 npc packet serialization (#119)

3.5.0

  • Add 1.17.10 support #109
  • You can switch to the JS implementation of raknet by setting useNativeRaknet: false in options.

3.4.0

  • Initial 1.17 support #99
  • update connect version based on ping response & fix typings (u9g) #101
  • fix: ping types. (JammSpread) #100

3.3.0

  • Protocol updates for 1.16, with some minor breaking changes to protocol fields #95
  • Fix npm install issues

3.2.1

  • Add authTitle option to Relay proxy #92
  • Protocol, type definition fixes

3.2.0

  • Fix empty chunks on proxy spawn #89
  • Send skin data to server #88
  • Support xbox title + live.com auth #86
  • Protocol updates and fixes
  • Fix third party servers, optional client encryption #83

3.1.0

  • Add support for 1.16
  • New docs and examples
  • Ping support
  • Add microsoft authentication
  • Codebase refactor

2.4.0

  • Update to version 1.12.0
  • Add option to provide protocol.json

2.2.3

  • fix the use item packet

2.2.2

  • fix the block update packet, for real this time

2.1.1

  • fix the block update packet

2.1.0

  • normalize names of packet fields
  • update to version 0.14.2

2.0.1

  • player list is now an array
  • reconnecting has been fixed

2.0.0

  • lot of raknet update that fix bugs
  • the server example is working
  • fix packets
  • breaking : remove mcpe_ prefix in packet names
  • encapsulated packet now emit actual errors

1.1.0

  • raknet is integrated, packet parsing is working
  • client login sequence is working
  • server login sequence is almost there

1.0.0

  • first version, protocol definition is there but nothing really works