node-minecraft-protocol/docs/README.md

179 lines
5.6 KiB
Markdown
Raw Normal View History

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/)
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 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),
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)
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
* 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
## 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
* [mineflayer](https://github.com/PrismarineJS/mineflayer/) - create minecraft
2013-02-12 13:58:53 -05:00
bots with a stable, high level API.
* [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.
* [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.
2020-07-05 18:48:35 -04:00
* [pakkit](https://github.com/Heath123/pakkit) To monitor your packets
* [minecraft-packet-debugger](https://github.com/wvffle/minecraft-packet-debugger) to easily debug your minecraft packets
2013-01-07 14:42:28 -05:00
## Usage
2013-01-03 21:42:35 -05:00
### Echo client example
```js
var mc = require('minecraft-protocol');
var client = mc.createClient({
host: "localhost", // optional
port: 25565, // optional
username: "email@example.com",
password: "12345678",
});
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.
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.text});
}
});
```
If the server is in offline mode, you may leave out the `password` option.
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
version: '1.16.3'
2013-01-03 22:01:17 -05:00
});
const mcData = require('minecraft-data')(server.version)
2013-01-04 01:45:57 -05:00
server.on('login', function(client) {
let loginPacket = mcData.loginPacket
2014-04-11 13:40:15 -04:00
client.write('login', {
entityId: client.id,
isHardcore: false,
2013-01-03 22:01:17 -05:00
gameMode: 0,
previousGameMode: 255,
worldNames: loginPacket.worldNames,
dimensionCodec: loginPacket.dimensionCodec,
dimension: loginPacket.dimension,
worldName: 'minecraft:overworld',
2020-05-03 17:42:00 -04:00
hashedSeed: [0, 0],
maxPlayers: server.maxPlayers,
viewDistance: 10,
2020-05-03 17:42:00 -04:00
reducedDebugInfo: false,
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,
flags: 0x00
2013-01-03 22:01:17 -05:00
});
var msg = {
translate: 'chat.type.announcement',
"with": [
'Server',
'Hello, world!'
]
};
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`
## Documentation
2020-06-22 09:03:53 -04:00
See [doc](API.md)
See [faq](FAQ.md)
## 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`
2013-01-02 01:47:18 -05:00
## Debugging
2016-03-21 05:38:23 -04:00
You can enable some protocol debugging output using `DEBUG` environment variable:
```bash
2016-03-21 05:38:23 -04:00
DEBUG="minecraft-protocol" node [...]
```
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
See [history](HISTORY.md)
## Related
* [node-rcon](https://github.com/pushrax/node-rcon) can be used to access the rcon server in the minecraft server
* [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