2015-04-16 16:07:18 -04:00
# minecraft protocol
2016-02-29 10:31:04 -05:00
[![NPM version ](https://img.shields.io/npm/v/minecraft-protocol.svg )](https://www.npmjs.com/package/minecraft-protocol)
2020-06-07 17:31:42 -04:00
[![Build Status ](https://github.com/PrismarineJS/node-minecraft-protocol/workflows/CI/badge.svg )](https://github.com/PrismarineJS/node-minecraft-protocol/actions?query=workflow%3A%22CI%22)
2018-11-25 10:51:30 -05:00
[![Discord ](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg )](https://discord.gg/GsEFRM8)
[![Gitter ](https://img.shields.io/badge/chat-on%20gitter-brightgreen.svg )](https://gitter.im/PrismarineJS/general)
[![Irc ](https://img.shields.io/badge/chat-on%20irc-brightgreen.svg )](https://irc.gitter.im/)
2020-05-03 06:51:34 -04:00
2019-07-21 05:48:18 -04:00
[![Try it on gitpod ](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg )](https://gitpod.io/#https://github.com/PrismarineJS/node-minecraft-protocol)
2015-03-22 22:09:38 -04:00
2013-01-01 21:02:07 -05:00
Parse and serialize minecraft packets, plus authentication and encryption.
2013-01-01 04:14:38 -05:00
2013-01-01 16:01:43 -05:00
## Features
2017-04-13 08:07:33 -04:00
* 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),
2020-03-28 12:19:48 -04:00
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)
2021-07-18 12:36:33 -04:00
, 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)
2013-01-04 23:16:48 -05:00
* Parses all packets and emits events with packet fields as JavaScript
2013-01-01 16:01:43 -05:00
objects.
* Send a packet by supplying fields as a JavaScript object.
2013-01-04 23:16:48 -05:00
* Client
- Authenticating and logging in
2015-03-06 14:54:27 -05:00
- Encryption
- Compression
2013-01-04 23:16:48 -05:00
- Both online and offline mode
- Respond to keep-alive packets.
- Ping a server for status
* Server
2015-03-06 14:54:27 -05:00
- Online/Offline mode
- Encryption
- Compression
2013-01-04 23:16:48 -05:00
- Handshake
- Keep-alive checking
- Ping status
2015-09-24 06:28:41 -04:00
* Robust test coverage.
2013-01-01 16:01:43 -05:00
* Optimized for rapidly staying up to date with Minecraft protocol updates.
2020-05-09 18:42:06 -04:00
Want to contribute on something important for PrismarineJS ? go to https://github.com/PrismarineJS/mineflayer/wiki/Big-Prismarine-projects
2019-07-21 05:48:18 -04:00
2016-02-12 08:41:47 -05:00
## Third Party Plugins
node-minecraft-protocol is pluggable.
* [minecraft-protocol-forge ](https://github.com/PrismarineJS/node-minecraft-protocol-forge ) add forge support to minecraft-protocol
2013-01-01 16:01:43 -05:00
2013-02-12 13:58:53 -05:00
## Projects Using node-minecraft-protocol
2021-08-08 08:30:09 -04:00
* [mineflayer ](https://github.com/PrismarineJS/mineflayer/ ) - Create minecraft
2013-02-12 13:58:53 -05:00
bots with a stable, high level API.
2021-08-08 08:30:09 -04:00
* [mcserve ](https://github.com/andrewrk/mcserve ) - Runs and monitors your
2013-02-12 13:58:53 -05:00
minecraft server, provides real-time web interface, allow your users to
create bots.
2021-08-08 08:30:09 -04:00
* [flying-squid ](https://github.com/PrismarineJS/flying-squid ) - Create minecraft
2015-08-30 15:34:28 -04:00
servers with a high level API, also a minecraft server by itself.
2021-08-08 08:30:09 -04:00
* [pakkit ](https://github.com/Heath123/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 ](https://github.com/wvffle/minecraft-packet-debugger ) - A tool to capture Minecraft packets in a buffer then view them in a browser
* [aresrpg ](https://github.com/aresrpg/aresrpg ) - An open-source mmorpg minecraft server
2021-08-08 08:31:10 -04:00
* and a [several thousands others ](https://github.com/PrismarineJS/node-minecraft-protocol/network/dependents?package_id=UGFja2FnZS0xODEzMDk0OQ%3D%3D )
2013-01-01 23:39:31 -05:00
## Usage
2013-01-01 04:14:38 -05:00
2013-01-03 21:42:35 -05:00
### Echo client example
2013-01-01 23:39:31 -05:00
```js
var mc = require('minecraft-protocol');
var client = mc.createClient({
2013-01-30 19:56:43 -05:00
host: "localhost", // optional
port: 25565, // optional
username: "email@example.com",
password: "12345678",
2020-12-11 15:30:48 -05:00
auth: 'mojang' // optional; by default uses mojang, if using a microsoft account, set to 'microsoft'
2013-01-01 23:39:31 -05:00
});
2014-04-11 13:40:15 -04:00
client.on('chat', function(packet) {
2013-01-03 21:42:35 -05:00
// Listen for chat messages and echo them back.
2013-07-09 02:13:17 -04:00
var jsonMsg = JSON.parse(packet.message);
2015-09-24 06:28:41 -04:00
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;
2020-05-03 06:16:30 -04:00
client.write('chat', {message: msg.text});
2013-07-09 02:13:17 -04:00
}
2013-01-01 23:39:31 -05:00
});
```
2013-01-02 01:12:42 -05:00
2013-01-30 19:56:43 -05:00
If the server is in offline mode, you may leave out the `password` option.
2021-03-20 18:28:22 -04:00
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.
2013-01-30 19:56:43 -05:00
2013-01-03 22:01:17 -05:00
### Hello World server example
```js
var mc = require('minecraft-protocol');
var server = mc.createServer({
2013-01-04 01:45:57 -05:00
'online-mode': true, // optional
encryption: true, // optional
host: '0.0.0.0', // optional
port: 25565, // optional
2020-10-06 16:46:53 -04:00
version: '1.16.3'
2013-01-03 22:01:17 -05:00
});
2020-10-06 16:46:53 -04:00
const mcData = require('minecraft-data')(server.version)
2013-01-04 01:45:57 -05:00
server.on('login', function(client) {
2020-10-06 16:46:53 -04:00
let loginPacket = mcData.loginPacket
2014-04-11 13:40:15 -04:00
client.write('login', {
2013-01-04 22:47:54 -05:00
entityId: client.id,
2020-10-06 16:46:53 -04:00
isHardcore: false,
2013-01-03 22:01:17 -05:00
gameMode: 0,
2020-06-23 10:52:18 -04:00
previousGameMode: 255,
2020-10-06 16:46:53 -04:00
worldNames: loginPacket.worldNames,
dimensionCodec: loginPacket.dimensionCodec,
dimension: loginPacket.dimension,
2020-06-23 10:52:18 -04:00
worldName: 'minecraft:overworld',
2020-05-03 17:42:00 -04:00
hashedSeed: [0, 0],
2015-09-24 06:28:41 -04:00
maxPlayers: server.maxPlayers,
2020-10-06 16:46:53 -04:00
viewDistance: 10,
2020-05-03 17:42:00 -04:00
reducedDebugInfo: false,
2020-10-06 16:46:53 -04:00
enableRespawnScreen: true,
isDebug: false,
isFlat: false
2013-01-03 22:01:17 -05:00
});
2014-04-11 13:40:15 -04:00
client.write('position', {
2013-01-03 22:01:17 -05:00
x: 0,
y: 1.62,
z: 0,
yaw: 0,
pitch: 0,
2015-09-24 06:28:41 -04:00
flags: 0x00
2013-01-03 22:01:17 -05:00
});
2015-09-24 06:28:41 -04:00
var msg = {
translate: 'chat.type.announcement',
"with": [
'Server',
'Hello, world!'
]
};
2020-06-23 10:52:18 -04:00
client.write("chat", { message: JSON.stringify(msg), position: 0, sender: '0' });
2013-01-03 22:01:17 -05:00
});
```
2013-01-05 00:55:24 -05:00
## Installation
`npm install minecraft-protocol`
2013-01-08 01:52:56 -05:00
## Documentation
2020-06-22 09:03:53 -04:00
See [doc ](API.md )
See [faq ](FAQ.md )
2013-01-08 01:52:56 -05:00
2013-01-02 01:12:42 -05:00
## Testing
* Ensure your system has the `java` executable in `PATH` .
2015-09-29 16:41:41 -04:00
* `MC_SERVER_JAR_DIR=some/path/to/store/minecraft/server/ MC_USERNAME=email@example.com MC_PASSWORD=password npm test`
2013-01-02 01:47:18 -05:00
2015-05-29 07:24:12 -04:00
## Debugging
2013-04-15 00:52:32 -04:00
2016-03-21 05:38:23 -04:00
You can enable some protocol debugging output using `DEBUG` environment variable:
2013-04-15 00:52:32 -04:00
```bash
2016-03-21 05:38:23 -04:00
DEBUG="minecraft-protocol" node [...]
2013-04-15 00:52:32 -04:00
```
2018-11-25 13:39:34 -05:00
On windows :
```
set DEBUG=minecraft-protocol
node your_script.js
```
2018-08-26 13:55:29 -04:00
## Contribute
Please read https://github.com/PrismarineJS/prismarine-contribute
2013-01-26 15:35:52 -05:00
## History
2014-10-19 11:55:27 -04:00
2015-05-29 07:24:12 -04:00
See [history ](HISTORY.md )
2017-07-13 08:22:42 -04:00
## Related
* [node-rcon ](https://github.com/pushrax/node-rcon ) can be used to access the rcon server in the minecraft server
2018-12-17 20:46:27 -05:00
* [map-colors][aresmapcolor] can be used to convert any image into a buffer of minecraft compatible colors
[aresmapcolor]: https://github.com/AresRPG/aresrpg-map-colors