Parse and serialize minecraft packets, plus authentication and encryption.
Find a file
Romain Beaumont 6b109aa4d8
Merge pull request #549 from PrismarineJS/greenkeeper/mocha-5.0.5
Update mocha to the latest version 🚀
2018-04-30 12:56:01 +02:00
doc add connect option to createClient for multiple (ping + normal) connections for the proxy examples, use the normal options for pinging in autoVersion to have that option available and fix the proxy examples accordingly 2017-07-19 18:39:25 +02:00
examples Add Minecraft Version To The Server 2017-11-09 18:32:10 +08:00
src Update auth.js 2018-04-30 21:32:43 +12:00
test remove console.log 2018-01-01 22:48:13 +01:00
.editorconfig fix the indent_size in .editorconfig 2015-05-14 22:03:43 +02:00
.gitignore add 2 examples : client_http_proxy and client_socks_proxy. fix #185 fix #436 2017-07-13 14:42:42 +02:00
.npmignore Add npmignore 2015-03-23 02:41:49 +00:00
circle.yml parallel circle ci testing of clientTest.js (#373) (#449) 2017-05-10 02:49:13 +02:00
HISTORY.md Release 1.5.1 2018-01-27 15:24:30 +01:00
package.json chore(package): update mocha to version 5.0.5 2018-03-23 05:19:15 +00:00
README.md 17w50a support 2018-01-01 21:01:23 +01:00

minecraft protocol

NPM version Build Status Join the chat at https://gitter.im/PrismarineJS/node-minecraft-protocol Greenkeeper badge

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

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.

Usage

Echo client example

var mc = require('minecraft-protocol');
var client = mc.createClient({
  host: "localhost",   // optional
  port: 25565,         // optional
  username: "email@example.com",
  password: "12345678",
});
client.on('chat', function(packet) {
  // Listen for chat messages and echo them back.
  var jsonMsg = JSON.parse(packet.message);
  if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
    var username = jsonMsg.with[0].text;
    var msg = jsonMsg.with[1];
    if(username === client.username) return;
    client.write('chat', {message: msg});
  }
});

If the server is in offline mode, you may leave out the password option.

Hello World server example

var mc = require('minecraft-protocol');
var server = mc.createServer({
  'online-mode': true,   // optional
  encryption: true,      // optional
  host: '0.0.0.0',       // optional
  port: 25565,           // optional
});
server.on('login', function(client) {
  client.write('login', {
    entityId: client.id,
    levelType: 'default',
    gameMode: 0,
    dimension: 0,
    difficulty: 2,
    maxPlayers: server.maxPlayers,
    reducedDebugInfo: false
  });
  client.write('position', {
    x: 0,
    y: 1.62,
    z: 0,
    yaw: 0,
    pitch: 0,
    flags: 0x00
  });
  var msg = {
    translate: 'chat.type.announcement',
    "with": [
      'Server',
      'Hello, world!'
    ]
  };
  client.write("chat", { message: JSON.stringify(msg), position: 0 });
});

Installation

npm install minecraft-protocol

Documentation

See doc

Testing

  • Ensure your system has the java executable in PATH.
  • MC_SERVER_JAR_DIR=some/path/to/store/minecraft/server/ MC_USERNAME=email@example.com MC_PASSWORD=password npm test

Debugging

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

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

History

See history

  • node-rcon can be used to access the rcon server in the minecraft server