Giter Site home page Giter Site logo

justjavac / bedrock-protocol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from prismarinejs/bedrock-protocol

1.0 2.0 0.0 840 KB

Minecraft Bedrock protocol library, with authentication and encryption

Home Page: https://minecraft-data.prismarine.js.org/?v=bedrock_1.17.10&d=protocol

License: MIT License

JavaScript 99.82% Dockerfile 0.18%

bedrock-protocol's Introduction

bedrock-protocol

NPM version Build Status Discord Try it on gitpod

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
  • 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.
  // Optional for some servers which verify the title ID:
  // authTitle: bedrock.title.MinecraftNintendoSwitch
})

client.on('text', (packet) => { // Listen for chat messages and echo them back.
  if (packet.source_name != client.options.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()}`
    })
  }
})

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 proto.yml and types.yml files.

See API documentation

See faq

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

bedrock-protocol's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar extremeheat avatar filiphsps avatar jammspread avatar kaffinpx avatar kashalls avatar rom1504 avatar snyk-bot avatar u9g avatar

Stargazers

 avatar

Watchers

 avatar  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.