GithubHelp home page GithubHelp logo

vincss / node-minecraft-protocol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from prismarinejs/node-minecraft-protocol

0.0 0.0 0.0 1.78 MB

Parse and serialize minecraft packets, plus authentication and encryption.

Home Page: https://prismarinejs.github.io/node-minecraft-protocol/

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%

node-minecraft-protocol's Introduction

minecraft protocol

NPM version Build Status Discord Gitter Irc

Try it on gitpod

Parse and serialize minecraft packets, plus authentication and encryption.

Features

  • Supports Minecraft PC version 1.7.10, 1.8.8, 1.9 (15w40b, 1.9, 1.9.1-pre2, 1.9.2, 1.9.4), 1.10 (16w20a, 1.10-pre1, 1.10, 1.10.1, 1.10.2), 1.11 (16w35a, 1.11, 1.11.2), 1.12 (17w15a, 17w18b, 1.12-pre4, 1.12, 1.12.1, 1.12.2), and 1.13 (17w50a, 1.13, 1.13.1, 1.13.2-pre1, 1.13.2-pre2, 1.13.2), 1.14 (1.14, 1.14.1, 1.14.3, 1.14.4) , 1.15 (1.15, 1.15.1, 1.15.2) and 1.16 (20w13b, 20w14a, 1.16-rc1, 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4), 1.17 (21w07a, 1.17, 1.17.1), 1.18 (1.18, 1.18.1 and 1.18.2), 1.19 (1.19, 1.19.1, 1.19.2, 1.19.3, 1.19.4), 1.20 (1.20, 1.20.1)
  • Parses all packets and emits events with packet fields as JavaScript objects.
  • Send a packet by supplying fields as a JavaScript object.
  • Client
    • Authenticating and logging in
    • Encryption
    • Compression
    • Both online and offline mode
    • Respond to keep-alive packets.
    • Ping a server for status
  • Server
    • Online/Offline mode
    • Encryption
    • Compression
    • Handshake
    • Keep-alive checking
    • Ping status
  • Robust test coverage.
  • 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

Third Party Plugins

node-minecraft-protocol is pluggable.

Projects Using node-minecraft-protocol

  • mineflayer - Create minecraft bots with a stable, high level API.
  • mcserve - Runs and monitors your minecraft server, provides real-time web interface, allow your users to create bots.
  • flying-squid - Create minecraft servers with a high level API, also a minecraft server by itself.
  • pakkit - A GUI tool to monitor Minecraft packets in real time, allowing you to view their data and interactively edit and resend them.
  • minecraft-packet-debugger - A tool to capture Minecraft packets in a buffer then view them in a browser.
  • aresrpg - An open-source mmorpg minecraft server.
  • SteveProxy - Proxy for Minecraft with the ability to change the gameplay using plugins.
  • and several thousands others

Installation

npm install minecraft-protocol

Documentation

Usage

Echo client example

const mc = require('minecraft-protocol');
const client = mc.createClient({
  host: "localhost",   // optional
  port: 25565,         // optional
  username: "[email protected]",
  password: "12345678",
  auth: 'microsoft' // optional; by default uses offline mode, if using a microsoft account, set to 'microsoft'
});

client.on('chat', function(packet) {
  // Listen for chat messages and echo them back.
  const jsonMsg = JSON.parse(packet.message);
  
  if (jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
    const username = jsonMsg.with[0].text;
    const msg = jsonMsg.with[1];

    if (username === client.username) return;

    client.write('chat', {message: msg.text});
  }
});

If the server is in offline mode, you may leave out the password option and switch auth to offline. You can also leave out password when using a Microsoft account. If provided, password based auth will be attempted first which may fail. Note: if using a Microsoft account, your account age must be >= 18 years old.

Client example joining a Realm

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

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

Hello World server example

const mc = require('minecraft-protocol');
const server = mc.createServer({
  'online-mode': true,   // optional
  encryption: true,      // optional
  host: '0.0.0.0',       // optional
  port: 25565,           // optional
  version: '1.16.3'
});
const mcData = require('minecraft-data')(server.version)

server.on('login', function(client) {
  const loginPacket = mcData.loginPacket

  client.write('login', {
    entityId: client.id,
    isHardcore: false,
    gameMode: 0,
    previousGameMode: 255,
    worldNames: loginPacket.worldNames,
    dimensionCodec: loginPacket.dimensionCodec,
    dimension: loginPacket.dimension,
    worldName: 'minecraft:overworld',
    hashedSeed: [0, 0],
    maxPlayers: server.maxPlayers,
    viewDistance: 10,
    reducedDebugInfo: false,
    enableRespawnScreen: true,
    isDebug: false,
    isFlat: false
  });

  client.write('position', {
    x: 0,
    y: 255,
    z: 0,
    yaw: 0,
    pitch: 0,
    flags: 0x00
  });

  const msg = {
    translate: 'chat.type.announcement',
    "with": [
      'Server',
      'Hello, world!'
    ]
  };
  
  client.write("chat", { message: JSON.stringify(msg), position: 0, sender: '0' });
});

Testing

  • Ensure your system has the java executable in PATH.
  • MC_SERVER_JAR_DIR=some/path/to/store/minecraft/server/ [email protected] MC_PASSWORD=password npm test

Debugging

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

DEBUG="minecraft-protocol" node [...]

On Windows:

set DEBUG=minecraft-protocol
node your_script.js

Contribute

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

History

See history

Related

  • node-rcon can be used to access the rcon server in the minecraft server
  • map-colors can be used to convert any image into a buffer of minecraft compatible colors

node-minecraft-protocol's People

Contributors

andrewrk avatar bangbang93 avatar bored-engineer avatar dcbartlett avatar deathcap avatar dependabot-preview[bot] avatar dependabot[bot] avatar extremeheat avatar frej4189 avatar greenkeeper[bot] avatar greenkeeperio-bot avatar groobledierne avatar heath123 avatar icetank avatar kashalls avatar lluiscab avatar mappum avatar matthi4s avatar oscartbeaumont avatar plexigras avatar richarddorian avatar rob9315 avatar roblabla avatar rom1504 avatar shaybox avatar u9g avatar vimes1984 avatar wtfaremyinitials avatar wvffle avatar zuazo 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.