mineflayer 4.18.0 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -37,9 +37,14 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md)
37
37
 
38
38
  First install Node.js >= 18 from [nodejs.org](https://nodejs.org/) then:
39
39
 
40
- `npm install mineflayer`
40
+ ```bash
41
+ npm install mineflayer
42
+ ```
41
43
 
42
- To update mineflayer (or any Node.js) package and its dependencies, use `npm update --depth 9999`
44
+ To update mineflayer (or any Node.js) package and its dependencies, use
45
+ ```bash
46
+ npm update --depth 9999
47
+ ```
43
48
 
44
49
  ## Documentation
45
50
 
@@ -80,11 +85,11 @@ const mineflayer = require('mineflayer')
80
85
 
81
86
  const bot = mineflayer.createBot({
82
87
  host: 'localhost', // minecraft server ip
83
- username: 'Bot', // username or email, switch if you want to change accounts
88
+ username: 'Bot', // username to join as if auth is `offline`, else a unique identifier for this account. Switch if you want to change accounts
84
89
  auth: 'microsoft' // for offline mode servers, you can set this to 'offline'
85
- // port: 25565, // only set if you need a port that isn't 25565
86
- // version: false, // only set if you need a specific version or snapshot (ie: "1.8.9" or "1.16.5"), otherwise it's set automatically
87
- // password: '12345678' // set if you want to use password-based auth (may be unreliable). If specified, the `username` must be an email
90
+ // port: 25565, // set if you need a port that isn't 25565
91
+ // version: false, // only set if you need a specific version or snapshot (ie: "1.8.9" or "1.16.5"), otherwise it's set automatically
92
+ // password: '12345678' // set if you want to use password-based auth (may be unreliable). If specified, the `username` must be an email
88
93
  })
89
94
 
90
95
  bot.on('chat', (username, message) => {
@@ -98,9 +103,10 @@ bot.on('error', console.log)
98
103
  ```
99
104
 
100
105
  If `auth` is set to `microsoft`, you will be prompted to login to microsoft.com with a code in your browser. After signing in on your browser,
101
- the bot will automatically obtain and cache authentication tokens in the local file system so you don't have to sign-in again.
102
- To switch the account, update the supplied `username`. By default, cached tokens will be stored in your user's .minecraft folder.
103
- For more information on these options and others, see node-minecraft-protocol's [API doc](https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/docs/API.md#mccreateclientoptions).
106
+ the bot will automatically obtain and cache authentication tokens (under your specified username) so you don't have to sign-in again.
107
+
108
+ To switch the account, update the supplied `username`. By default, cached tokens will be stored in your user's .minecraft folder, or if `profilesFolder` is specified, they'll instead be stored there.
109
+ For more information on bot options see node-minecraft-protocol's [API doc](https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/docs/API.md#mccreateclientoptions).
104
110
 
105
111
  #### Connecting to a Realm
106
112
 
@@ -248,17 +254,36 @@ The most updated and useful are :
248
254
 
249
255
  ### Testing everything
250
256
 
251
- Simply run: `npm test`
257
+ Simply run:
258
+
259
+ ```bash
260
+ npm test
261
+ ```
252
262
 
253
263
  ### Testing specific version
254
- Run `npm run mocha_test -- -g <version>`, where `<version>` is a minecraft version like `1.12`, `1.15.2`...
264
+ Run
265
+
266
+ ```bash
267
+ npm run mocha_test -- -g <version>
268
+ ```
269
+
270
+ where `<version>` is a minecraft version like `1.12`, `1.15.2`...
255
271
 
256
272
  ### Testing specific test
257
- Run `npm run mocha_test -- -g <test_name>`, where `<test_name>` is a name of the test like `bed`, `useChests`, `rayTrace`...
273
+ Run
274
+
275
+ ```bash
276
+ npm run mocha_test -- -g <test_name>
277
+ ```
278
+
279
+ where `<test_name>` is a name of the test like `bed`, `useChests`, `rayTrace`...
258
280
 
259
281
  ### Example
260
282
 
261
- `npm run mocha_test -- -g "1.18.1.*BlockFinder"` to run the block finder test for 1.18.1
283
+ ```bash
284
+ npm run mocha_test -- -g "1.18.1.*BlockFinder"
285
+ ```
286
+ to run the block finder test for 1.18.1
262
287
 
263
288
  ## License
264
289
 
package/docs/README.md CHANGED
@@ -37,9 +37,14 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md)
37
37
 
38
38
  First install Node.js >= 18 from [nodejs.org](https://nodejs.org/) then:
39
39
 
40
- `npm install mineflayer`
40
+ ```bash
41
+ npm install mineflayer
42
+ ```
41
43
 
42
- To update mineflayer (or any Node.js) package and its dependencies, use `npm update --depth 9999`
44
+ To update mineflayer (or any Node.js) package and its dependencies, use
45
+ ```bash
46
+ npm update --depth 9999
47
+ ```
43
48
 
44
49
  ## Documentation
45
50
 
@@ -80,11 +85,11 @@ const mineflayer = require('mineflayer')
80
85
 
81
86
  const bot = mineflayer.createBot({
82
87
  host: 'localhost', // minecraft server ip
83
- username: 'Bot', // username or email, switch if you want to change accounts
88
+ username: 'Bot', // username to join as if auth is `offline`, else a unique identifier for this account. Switch if you want to change accounts
84
89
  auth: 'microsoft' // for offline mode servers, you can set this to 'offline'
85
- // port: 25565, // only set if you need a port that isn't 25565
86
- // version: false, // only set if you need a specific version or snapshot (ie: "1.8.9" or "1.16.5"), otherwise it's set automatically
87
- // password: '12345678' // set if you want to use password-based auth (may be unreliable). If specified, the `username` must be an email
90
+ // port: 25565, // set if you need a port that isn't 25565
91
+ // version: false, // only set if you need a specific version or snapshot (ie: "1.8.9" or "1.16.5"), otherwise it's set automatically
92
+ // password: '12345678' // set if you want to use password-based auth (may be unreliable). If specified, the `username` must be an email
88
93
  })
89
94
 
90
95
  bot.on('chat', (username, message) => {
@@ -98,9 +103,10 @@ bot.on('error', console.log)
98
103
  ```
99
104
 
100
105
  If `auth` is set to `microsoft`, you will be prompted to login to microsoft.com with a code in your browser. After signing in on your browser,
101
- the bot will automatically obtain and cache authentication tokens in the local file system so you don't have to sign-in again.
102
- To switch the account, update the supplied `username`. By default, cached tokens will be stored in your user's .minecraft folder.
103
- For more information on these options and others, see node-minecraft-protocol's [API doc](https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/docs/API.md#mccreateclientoptions).
106
+ the bot will automatically obtain and cache authentication tokens (under your specified username) so you don't have to sign-in again.
107
+
108
+ To switch the account, update the supplied `username`. By default, cached tokens will be stored in your user's .minecraft folder, or if `profilesFolder` is specified, they'll instead be stored there.
109
+ For more information on bot options see node-minecraft-protocol's [API doc](https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/docs/API.md#mccreateclientoptions).
104
110
 
105
111
  #### Connecting to a Realm
106
112
 
@@ -248,17 +254,36 @@ The most updated and useful are :
248
254
 
249
255
  ### Testing everything
250
256
 
251
- Simply run: `npm test`
257
+ Simply run:
258
+
259
+ ```bash
260
+ npm test
261
+ ```
252
262
 
253
263
  ### Testing specific version
254
- Run `npm run mocha_test -- -g <version>`, where `<version>` is a minecraft version like `1.12`, `1.15.2`...
264
+ Run
265
+
266
+ ```bash
267
+ npm run mocha_test -- -g <version>
268
+ ```
269
+
270
+ where `<version>` is a minecraft version like `1.12`, `1.15.2`...
255
271
 
256
272
  ### Testing specific test
257
- Run `npm run mocha_test -- -g <test_name>`, where `<test_name>` is a name of the test like `bed`, `useChests`, `rayTrace`...
273
+ Run
274
+
275
+ ```bash
276
+ npm run mocha_test -- -g <test_name>
277
+ ```
278
+
279
+ where `<test_name>` is a name of the test like `bed`, `useChests`, `rayTrace`...
258
280
 
259
281
  ### Example
260
282
 
261
- `npm run mocha_test -- -g "1.18.1.*BlockFinder"` to run the block finder test for 1.18.1
283
+ ```bash
284
+ npm run mocha_test -- -g "1.18.1.*BlockFinder"
285
+ ```
286
+ to run the block finder test for 1.18.1
262
287
 
263
288
  ## License
264
289
 
package/docs/api.md CHANGED
@@ -225,7 +225,7 @@
225
225
  - ["blockBreakProgressEnd" (block, entity)](#blockbreakprogressend-block-entity)
226
226
  - ["diggingCompleted" (block)](#diggingcompleted-block)
227
227
  - ["diggingAborted" (block)](#diggingaborted-block)
228
- - ["usedfirework"](#usedfirework)
228
+ - ["usedFirework" (fireworkEntityId)](#usedfirework-fireworkentityid)
229
229
  - ["move"](#move)
230
230
  - ["forcedMove"](#forcedmove)
231
231
  - ["mount"](#mount)
@@ -270,7 +270,7 @@
270
270
  - [Methods](#methods)
271
271
  - [bot.end(reason)](#botendreason)
272
272
  - [bot.quit(reason)](#botquitreason)
273
- - [bot.tabComplete(str, [assumeCommand], [sendBlockInSight])](#bottabcompletestr-assumecommand-sendblockinsight)
273
+ - [bot.tabComplete(str, [assumeCommand], [sendBlockInSight], [timeout])](#bottabcompletestr-assumecommand-sendblockinsight-timeout)
274
274
  - [bot.chat(message)](#botchatmessage)
275
275
  - [bot.whisper(username, message)](#botwhisperusername-message)
276
276
  - [bot.chatAddPattern(pattern, chatType, description)](#botchataddpatternpattern-chattype-description)
@@ -1649,7 +1649,7 @@ End the connection with the server.
1649
1649
 
1650
1650
  Gracefully disconnect from the server with the given reason (defaults to 'disconnect.quitting').
1651
1651
 
1652
- #### bot.tabComplete(str, [assumeCommand], [sendBlockInSight])
1652
+ #### bot.tabComplete(str, [assumeCommand], [sendBlockInSight], [timeout])
1653
1653
 
1654
1654
  This function returns a `Promise`, with `matches` as its argument upon completion.
1655
1655
 
@@ -1657,6 +1657,7 @@ Requests chat completion from the server.
1657
1657
  * `str` - String to complete.
1658
1658
  * `assumeCommand` - Field sent to server, defaults to false.
1659
1659
  * `sendBlockInSight` - Field sent to server, defaults to true. Set this option to false if you want more performance.
1660
+ * `timeout` - Timeout in milliseconds, after which the function will return an ampty array, defaults to 5000.
1660
1661
 
1661
1662
  #### bot.chat(message)
1662
1663
 
@@ -213,16 +213,33 @@ Mas também dê uma olhada em:
213
213
 
214
214
  ### Executar Todos os Testes
215
215
 
216
- Basta executar: `npm test`
216
+ Basta executar:
217
+
218
+ ```bash
219
+ npm test
220
+ ```
217
221
 
218
222
  ### Executar Testes para uma Versão Específica do Minecraft
219
- Execute `npm test -- -g <versão>`, onde `<versão>` é uma versão do Minecraft, como `1.12`, `1.15.2`...
223
+
224
+ Execute
225
+
226
+ ```bash
227
+ npm test -- -g <versão>
228
+ ```
229
+
230
+ onde `<versão>` é uma versão do Minecraft, como `1.12`, `1.15.2`...
220
231
 
221
232
  ### Executar um Teste Específico
222
- Execute `npm test -- -g <nome_do_teste>`, onde `<nome_do_teste>` é o nome do teste que você deseja executar, como `bed`, `useChests`, `rayTrace`...
233
+
234
+ Execute
235
+ ```bash
236
+ npm test -- -g <nome_do_teste>
237
+ ```
238
+
239
+ onde `<nome_do_teste>` é o nome do teste que você deseja executar, como `bed`, `useChests`, `rayTrace`...
223
240
 
224
241
  ## Licença
225
242
 
226
- [MIT](LICENSE)
243
+ [MIT](../../LICENSE)
227
244
 
228
245
  Esta documentação não é oficialmente mantida. Para ver as últimas atualizações, consulte a documentação original: [unstable_api](../README.md)
@@ -213,17 +213,33 @@ Pero también echa un vistazo a:
213
213
 
214
214
  ### Ejecuta todas las pruebas
215
215
 
216
- Simplemente ejecuta: `npm test`
216
+ Simplemente ejecuta:
217
+
218
+ ```bash
219
+ npm test
220
+ ```
217
221
 
218
222
  ### Ejecuta pruebas para una versión específica de Minecraft
219
- Ejecuta `npm test -- -g <version>`, donde `<version>` es una versión de minecraft como `1.12`, `1.15.2`...
223
+
224
+ Ejecuta
225
+ ```bash
226
+ npm test -- -g <version>
227
+ ```
228
+
229
+ donde `<version>` es una versión de minecraft como `1.12`, `1.15.2`...
220
230
 
221
231
  ### Ejecuta una prueba específica
222
- Ejecuta `npm test -- -g <test_name>`, donde `<test_name>` es el nombre de la prueba que quieres ejecutar como `bed`, `useChests`, `rayTrace`...
232
+
233
+ Ejecuta
234
+ ```bash
235
+ npm test -- -g <test_name>
236
+ ```
237
+
238
+ donde `<test_name>` es el nombre de la prueba que quieres ejecutar como `bed`, `useChests`, `rayTrace`...
223
239
 
224
240
  ## Licencia
225
241
 
226
- [MIT](LICENSE)
242
+ [MIT](../../LICENSE)
227
243
 
228
244
 
229
245
  Esta documentación no está mantenida oficialmente, si quiere ver las últimas novedades, por favor dirijase a la documentación original: [unstable_api](../README.md)
@@ -221,14 +221,32 @@ Laissez un coup d'oeil à ses projets :
221
221
 
222
222
  ### Tout tester
223
223
 
224
- Exécuter seulement : `npm test`
224
+ Exécuter seulement :
225
+
226
+ ```bash
227
+ npm test
228
+ ```
225
229
 
226
230
  ### Tester une version spécifique
227
- Exécutez `npm test -g <version>`, où `<version>` est une version de Minecraft comme `1.12`, `1.15.2`...
231
+
232
+ Exécutez
233
+
234
+ ```bash
235
+ npm test -g <version>
236
+ ```
237
+
238
+ où `<version>` est une version de Minecraft comme `1.12`, `1.15.2`...
228
239
 
229
240
  ### Tester un test spécifique
230
- Executer `npm test -g <test_name>`, où `<test_name>` est le nom d'un teste comme `lit`, `utiliseCoffre`, `rayTrace`...
241
+
242
+ Executer
243
+
244
+ ```bash
245
+ npm test -g <test_name>
246
+ ```
247
+
248
+ où `<test_name>` est le nom d'un teste comme `lit`, `utiliseCoffre`, `rayTrace`...
231
249
 
232
250
  ## Licence
233
251
 
234
- [MIT](LICENCE)
252
+ [MIT](../../LICENSE)
package/docs/history.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 4.19.0
2
+ * [Clarify readme createBot username handling (#3300)](https://github.com/PrismarineJS/mineflayer/commit/7a2680bc07f53d16626679537ea1f07aae180549) (thanks @extremeheat)
3
+ * [fix world typing (#3302)](https://github.com/PrismarineJS/mineflayer/commit/5dc36d6cdeaf4be72ea023827d45b9d78e575f66) (thanks @GenerelSchwerz)
4
+ * [modified the README.md files for other languages and fixed a linking issue at those files. (#3297)](https://github.com/PrismarineJS/mineflayer/commit/cc98f1307e3ab48477d2a9ff29da4447f42b30bc) (thanks @Axwaizee)
5
+ * [formatted docs/README.md for easy copy (#3295)](https://github.com/PrismarineJS/mineflayer/commit/468c8aa9d382a7872ec991c3b834b98cbe495e8d) (thanks @Axwaizee)
6
+ * [Added missing bot.teams definition (#3294)](https://github.com/PrismarineJS/mineflayer/commit/fb8ee7aa619bd38cc97d5dbd870bb11455d51d39) (thanks @Ynfuien)
7
+ * [Timeout for bot.tabComplete() (#3293)](https://github.com/PrismarineJS/mineflayer/commit/4231a169d579d08ac7b9ec0694e18b1f6ac837ea) (thanks @Ynfuien)
8
+ * [:label: Update types to be updated with what's in JavaScript (#3287)](https://github.com/PrismarineJS/mineflayer/commit/210785e86c031f7e3323d7d2ffe5152d2d4a5eb6) (thanks @fantomitechno)
9
+ * [Fixed some typo (#3290)](https://github.com/PrismarineJS/mineflayer/commit/ba53a953d03a6edb34aa5bf38bccde58e65d816d) (thanks @SilianZ)
10
+ * [Updated digging code to account for raycasted tall grass checks (#3285)](https://github.com/PrismarineJS/mineflayer/commit/bd0fb5c4d3b665f264009f62f9288828f3018cea) (thanks @GenerelSchwerz)
11
+
1
12
  ## 4.18.0
2
13
  * [Minecraft 1.20.2 support (#3262)](https://github.com/PrismarineJS/mineflayer/commit/2ff9919760d714be57dcb678f8ab5ecff69f5fee) (thanks @rom1504)
3
14
  * [Update recommended Node.js version (#3279)](https://github.com/PrismarineJS/mineflayer/commit/5c71edf48bb2f2dfa16cddb9af5baa0c4d55cf0d) (thanks @Nyaasu66)
@@ -219,17 +219,38 @@ Mineflayer поддерживает сторонние плагины. Любо
219
219
 
220
220
  ### Тестирование всего
221
221
 
222
- Просто запустите: `npm test`
222
+ Просто запустите:
223
+
224
+ ```bash
225
+ npm test
226
+ ```
223
227
 
224
228
  ### Тестирование определённой версии
225
- Запустите `npm run mocha_test -- -g <version>`, где `<version>` означает версию, таких как `1.12`, `1.15.2`...
229
+ Запустите
230
+
231
+ ```bash
232
+ npm run mocha_test -- -g <version>
233
+ ```
234
+
235
+ где `<version>` означает версию, таких как `1.12`, `1.15.2`...
226
236
 
227
237
  ### Тестирование определённой функции
228
- Запустите `npm run mocha_test -- -g <test_name>`, где `<test_name>` означает название проверки, таких как `bed`, `useChests`, `rayTrace`...
238
+
239
+ Запустите
240
+
241
+ ```bash
242
+ npm run mocha_test -- -g <test_name>
243
+ ```
244
+
245
+ где `<test_name>` означает название проверки, таких как `bed`, `useChests`, `rayTrace`...
229
246
 
230
247
  ### Пример
231
248
 
232
- `npm run mocha_test -- -g "1.18.1.*BlockFinder"` запустит тест BlockFinder на версии 1.18.1
249
+ ```bash
250
+ npm run mocha_test -- -g "1.18.1.*BlockFinder"
251
+ ```
252
+
253
+ запустит тест BlockFinder на версии 1.18.1
233
254
 
234
255
  ## Лицензия
235
256
 
@@ -218,13 +218,28 @@ En çok güncellenen ve en kullanışlı olan bazıları:
218
218
 
219
219
  ### Her şeyi test etme
220
220
 
221
- Basitçe `npm test` komutunu çalıştırın
221
+ Basitçe
222
+ ```bash
223
+ npm test
224
+ ```
225
+
226
+ komutunu çalıştırın
222
227
 
223
228
  ### Özel bir sürümü test etme
224
- `npm test -- -g <version>` komutunu çalıştırın, `<version>` bir Minecraft sürümü olmalı (`1.12`, `1.15.2` gibi).
229
+
230
+ ```bash
231
+ npm test -- -g <version>
232
+ ```
233
+
234
+ komutunu çalıştırın, `<version>` bir Minecraft sürümü olmalı (`1.12`, `1.15.2` gibi).
225
235
 
226
236
  ### Özel bir şeyi test etme
227
- `npm test -- -g <test_name>` komutunu çalıştırın, `<test_name>` kısmının olduğu bölüm bir test adı olmalı (`bed`, `useChests`, `rayTrace` gibi).
237
+
238
+ ```bash
239
+ npm test -- -g <test_name>
240
+ ```
241
+
242
+ komutunu çalıştırın, `<test_name>` kısmının olduğu bölüm bir test adı olmalı (`bed`, `useChests`, `rayTrace` gibi).
228
243
 
229
244
  ## Lisans
230
- [MIT](LICENSE)
245
+ [MIT](../../LICENSE)
@@ -88,6 +88,6 @@ docs/api.md 的内容是用doctoc制作的。更新该文件后,应运行 `doc
88
88
 
89
89
  没有doctoc命令使用下面的命令安装
90
90
 
91
- ```
91
+ ```bash
92
92
  npm install -g doctoc
93
93
  ```
@@ -13,9 +13,9 @@
13
13
  | <sub>EN</sub> [English](../README.md) | <sub>RU</sub> [русский](../ru/README_RU.md) | <sub>ES</sub> [Español](../es/README_ES.md) | <sub>FR</sub> [Français](../fr/README_FR.md) | <sub>TR</sub> [Türkçe](../tr/README_TR.md) | <sub>ZH</sub> [中文](../zh/README_ZH_CN.md) | <sub>BR</sub> [Portuguese](../br/README_BR.md) |
14
14
  |-------------------------|----------------------------|----------------------------|----------------------------|----------------------------|----------------------------|----------------------------|
15
15
 
16
- 使用强大、稳定、高级的JavaScript [API](../api.md) 来开发Minecraft机器人,同时支持 Python。
16
+ 使用强大、稳定、高级的 JavaScript [API](../api.md) 来开发 Minecraft 机器人,同时支持 Python。
17
17
 
18
- 第一次使用 node.js ?你可以先看看 [使用教程](../tutorial.md) 。了解过 Python?这里有一些 [Python实例](https://github.com/PrismarineJS/mineflayer/tree/master/examples/python),同时你也可以 [在谷歌Colab中运行Mineflayer](https://colab.research.google.com/github/PrismarineJS/mineflayer/blob/master/docs/mineflayer.ipynb) 来体验一下。
18
+ 第一次使用 node.js ?你可以先看看 [使用教程](../tutorial.md) 。了解过 Python?这里有一些 [Python 实例](https://github.com/PrismarineJS/mineflayer/tree/master/examples/python),同时你也可以[在谷歌 Colab 中运行 Mineflayer](https://colab.research.google.com/github/PrismarineJS/mineflayer/blob/master/docs/mineflayer.ipynb) 来体验一下。
19
19
 
20
20
  ## 特点
21
21
 
@@ -30,6 +30,7 @@
30
30
  * 各种各样的的信息接口,比如查看你的血量或是否下雨
31
31
  * 激活方块和使用物品
32
32
  * 进行聊天
33
+
33
34
  ### 路线图
34
35
 
35
36
  [点这里](https://github.com/PrismarineJS/mineflayer/wiki/Big-Prismarine-projects) 看看目前我们有哪些实用的项目
@@ -80,11 +81,11 @@
80
81
  const mineflayer = require('mineflayer')
81
82
 
82
83
  const bot = mineflayer.createBot({
83
- host: 'localhost', // minecraft 服务器的 ip地址
84
+ host: 'localhost', // minecraft 服务器的 IP 地址
84
85
  username: 'email@example.com', // minecraft 用户名
85
86
  password: '12345678' // minecraft 密码, 如果你玩的是不需要正版验证的服务器,请注释掉。
86
- // port: 25565, // 默认使用25565,如果你的服务器端口不是这个请取消注释并填写。
87
- // version: false, // 如果需要指定使用一个版本或快照时,请取消注释并手动填写(如:"1.8.9 " 或 "1.16.5"),否则会自动设置。
87
+ // port: 25565, // 默认使用 25565,如果你的服务器端口不是这个请取消注释并填写。
88
+ // version: false, // 如果需要指定使用一个版本或快照时,请取消注释并手动填写(如:"1.8.9" 或 "1.16.5"),否则会自动设置。
88
89
  // auth: 'mojang' // 如果需要使用微软账号登录时,请取消注释,然后将值设置为 'microsoft',否则会自动设置为 'mojang'。
89
90
  })
90
91
 
@@ -93,15 +94,15 @@ bot.on('chat', (username, message) => {
93
94
  bot.chat(message)
94
95
  })
95
96
 
96
- // 记录错误和被踢出服务器的原因:
97
+ // 记录错误和被踢出服务器的原因:
97
98
  bot.on('kicked', console.log)
98
99
  bot.on('error', console.log)
99
100
  ```
100
101
 
101
- ### 看看你的bot在做什么
102
+ ### 看看你的 bot 在做什么
102
103
 
103
- 感谢 [prismarin-viewer](https://github.com/PrismarineJS/prismarine-viewer)项目,它可以在浏览器窗口显示你的机器人正在做什么。
104
- 只需要运行 `npm install prismarine-viewer` 并将其添加到你的bot代码中。
104
+ 感谢 [prismarine-viewer](https://github.com/PrismarineJS/prismarine-viewer)项目,它可以在浏览器窗口显示你的机器人正在做什么。
105
+ 只需要运行 `npm install prismarine-viewer` 并将其添加到你的 bot 代码中。
105
106
 
106
107
  ```js
107
108
  const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
@@ -118,13 +119,13 @@ bot.once('spawn', () => {
118
119
 
119
120
  | 例子 | 描述 |
120
121
  |---|---|
121
- |[viewer](https://github.com/PrismarineJS/mineflayer/tree/master/examples/viewer) | 在浏览器中显示bot的视角 |
122
- |[pathfinder](https://github.com/PrismarineJS/mineflayer/tree/master/examples/pathfinder) | 让你的bot自动前往任何地点 |
122
+ |[viewer](https://github.com/PrismarineJS/mineflayer/tree/master/examples/viewer) | 在浏览器中显示 bot 的视角 |
123
+ |[pathfinder](https://github.com/PrismarineJS/mineflayer/tree/master/examples/pathfinder) | 让你的 bot 自动前往任何地点 |
123
124
  |[chest](https://github.com/PrismarineJS/mineflayer/blob/master/examples/chest.js) | 使用箱子、熔炉、酿造台、附魔台 |
124
125
  |[digger](https://github.com/PrismarineJS/mineflayer/blob/master/examples/digger.js) | 学习如何创建一个能够挖掘方块的简单bot |
125
126
  |[discord](https://github.com/PrismarineJS/mineflayer/blob/master/examples/discord.js) | 将 discord bot 与 mineflayer bot 进行消息互通 |
126
127
  |[jumper](https://github.com/PrismarineJS/mineflayer/blob/master/examples/jumper.js) | 学习如何移动、跳跃、骑乘载具、攻击附近的实体 |
127
- |[ansi](https://github.com/PrismarineJS/mineflayer/blob/master/examples/ansi.js) | 使用全彩色在命令行中显示bot的聊天记录 |
128
+ |[ansi](https://github.com/PrismarineJS/mineflayer/blob/master/examples/ansi.js) | 使用全彩色在命令行中显示 bot 的聊天记录 |
128
129
  |[guard](https://github.com/PrismarineJS/mineflayer/blob/master/examples/guard.js) | 让bot守卫一个指定的区域,不让附近的生物进入。 |
129
130
  |[multiple-from-file](https://github.com/PrismarineJS/mineflayer/blob/master/examples/multiple_from_file.js) | 创建一个包含账户信息的文本文件,让它们全部同时登录 |
130
131
 
@@ -132,15 +133,15 @@ bot.once('spawn', () => {
132
133
 
133
134
  ### 模块
134
135
 
135
- 很多活跃的开发都发生在 mineflayer 所使用的小型npm包内
136
+ 很多活跃的开发都发生在 mineflayer 所使用的小型 npm 包内
136
137
 
137
- #### The Node Way&trade;
138
+ #### The Node Way & trade;
138
139
 
139
140
  > "当你很好的编写了一个应用程序,此时它的价值仅限于这些特定的需求。你要知道,真正好的、可重复使用的优秀组件都会升华到github和npm上,在那里,每个人都可以合作来推进公共事业。" — [《 how I write modules 》 - substack](https://gist.github.com/substack/5075355)
140
141
 
141
142
  #### 子模块
142
143
 
143
- 这些是 构成Mineflayer 的主要模块:
144
+ 这些是 构成 mineflayer 的主要模块:
144
145
 
145
146
  | 模块 | 描述 |
146
147
  |---|---|
@@ -177,7 +178,7 @@ node your_script.js
177
178
 
178
179
  ## 第三方插件
179
180
 
180
- Mineflayer 支持插件;任何人都可以创建一个插件,在 Mineflayer 之上添加更高级别的 API。
181
+ mineflayer 支持插件;任何人都可以创建一个插件,在 mineflayer 之上添加更高级别的 API。
181
182
 
182
183
  最新和最有用的有:
183
184
 
@@ -206,9 +207,9 @@ Mineflayer 支持插件;任何人都可以创建一个插件,在 Mineflayer
206
207
  * [Bloodhound](https://github.com/Nixes/mineflayer-bloodhound) - 确定谁和什么对另一个实体的损害负责
207
208
  * [tps](https://github.com/SiebeDW/mineflayer-tps) - 获取当前的 tps(已处理的 tps)
208
209
  * [panorama](https://github.com/IceTank/mineflayer-panorama) - 拍摄您的世界的全景图像
209
- * [player-death-event](https://github.com/tuanzisama/mineflayer-death-event) - 在Mineflayer里监听玩家死亡事件
210
+ * [player-death-event](https://github.com/tuanzisama/mineflayer-death-event) - 在 Mineflayer 里监听玩家死亡事件
210
211
 
211
- ## 正在使用 Mineflayer 的项目
212
+ ## 正在使用 mineflayer 的项目
212
213
 
213
214
  * [rom1504/rbot](https://github.com/rom1504/rbot)
214
215
  * [YouTube - 建造旋转楼梯](https://www.youtube.com/watch?v=UM1ZV5200S0)
@@ -227,20 +228,39 @@ Mineflayer 支持插件;任何人都可以创建一个插件,在 Mineflayer
227
228
 
228
229
  ### 完整测试
229
230
 
230
- 运行:`npm test`
231
+ 运行
232
+ ```bash
233
+ npm test
234
+ ````
231
235
 
232
236
  ### 测试指定版本
233
237
 
234
- 运行 `npm mocha_test -- -g <version>`, 其中 `<version>` 表示 minecraft 版本号 如 `1.12`, `1.15.2`...
238
+ 运行
239
+
240
+ ```bash
241
+ npm mocha_test -- -g <version>
242
+ ```
243
+
244
+ 其中 `<version>` 表示 minecraft 版本号 如 `1.12`, `1.15.2`...
235
245
 
236
246
  ### 测试指定测试脚本
237
247
 
238
- 运行 `npm mocha_test -- -g <test_name>`,其中 `<test_name>` 是测试名称,例如 `bed`, `useChests`, `rayTrace`...
248
+ 运行
249
+
250
+ ```bash
251
+ npm mocha_test -- -g <test_name>
252
+ ```
253
+
254
+ 其中 `<test_name>` 是测试名称,例如 `bed`, `useChests`, `rayTrace`...
239
255
 
240
256
  ### 示例
241
257
 
242
- `npm run mocha_test -- -g "1.18.1.*BlockFinder"` 进行1.18.1寻路测试
258
+ ```bash
259
+ npm run mocha_test -- -g "1.18.1.*BlockFinder"
260
+ ```
261
+
262
+ 进行 1.18.1 寻路测试
243
263
 
244
264
  ## 许可证
245
265
 
246
- [MIT](../LICENSE)
266
+ [MIT](../../LICENSE)
package/index.d.ts CHANGED
@@ -194,10 +194,11 @@ export interface Bot extends TypedEmitter<BotEvents> {
194
194
  isSleeping: boolean
195
195
  scoreboards: { [name: string]: ScoreBoard }
196
196
  scoreboard: { [slot in DisplaySlot]: ScoreBoard }
197
+ teams: { [name: string]: Team }
197
198
  teamMap: { [name: string]: Team }
198
199
  controlState: ControlStateStatus
199
200
  creative: creativeMethods
200
- world: world.World
201
+ world: world.WorldSync
201
202
  _client: Client
202
203
  heldItem: Item | null
203
204
  usingHeldItem: boolean
@@ -245,7 +246,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
245
246
  tabComplete: (
246
247
  str: string,
247
248
  assumeCommand?: boolean,
248
- sendBlockInSight?: boolean
249
+ sendBlockInSight?: boolean,
250
+ timeout?: number
249
251
  ) => Promise<string[]>
250
252
 
251
253
  chat: (message: string) => void
@@ -779,7 +781,7 @@ export class ScoreBoard {
779
781
 
780
782
  setTitle (title: string): void;
781
783
 
782
- add (name: string, value: number, displayName: ChatMessage): ScoreBoardItem;
784
+ add(name: string, value: number): ScoreBoardItem;
783
785
 
784
786
  remove (name: string): ScoreBoardItem;
785
787
  }
@@ -791,6 +793,7 @@ export interface ScoreBoardItem {
791
793
  }
792
794
 
793
795
  export class Team {
796
+ team: string
794
797
  name: ChatMessage
795
798
  friendlyFire: number
796
799
  nameTagVisibility: string
@@ -798,8 +801,10 @@ export class Team {
798
801
  color: string
799
802
  prefix: ChatMessage
800
803
  suffix: ChatMessage
804
+ memberMap: { [name: string]: '' }
805
+ members: string[]
801
806
 
802
- constructor (packet: object);
807
+ constructor(team: string, name: string, friendlyFire: boolean, nameTagVisibility: string, collisionRule: string, formatting: number, prefix: string, suffix: string);
803
808
 
804
809
  parseMessage (value: string): ChatMessage;
805
810
 
@@ -841,6 +846,7 @@ export class BossBar {
841
846
  color: 'pink' | 'blue' | 'red' | 'green' | 'yellow' | 'purple' | 'white'
842
847
  shouldDarkenSky: boolean
843
848
  isDragonBar: boolean
849
+ createFog: boolean
844
850
  shouldCreateFog: boolean
845
851
 
846
852
  constructor (
@@ -854,23 +860,22 @@ export class BossBar {
854
860
  }
855
861
 
856
862
  export class Particle {
857
- id: number
858
- name: string
859
- position: Vec3
860
- offset: Vec3
861
- count: number
862
- movementSpeed: number
863
- longDistanceRender: boolean
864
- static fromNetwork(packet: Object): Particle
865
-
866
- constructor (
867
- id: number,
868
- position: Vec3,
869
- offset: Vec3,
870
- count?: number,
871
- movementSpeed?: number,
872
- longDistanceRender?: boolean
873
- );
863
+ id: number
864
+ position: Vec3
865
+ offset: Vec3
866
+ count: number
867
+ movementSpeed: number
868
+ longDistanceRender: boolean
869
+ static fromNetwork(packet: Object): Particle
870
+
871
+ constructor(
872
+ id: number,
873
+ position: Vec3,
874
+ offset: Vec3,
875
+ count?: number,
876
+ movementSpeed?: number,
877
+ longDistanceRender?: boolean
878
+ );
874
879
  }
875
880
 
876
881
  export let testedVersions: string[]
@@ -1,4 +1,4 @@
1
- const { once } = require('events')
1
+ const { onceWithCleanup } = require('../promise_utils')
2
2
 
3
3
  const USERNAME_REGEX = '(?:\\(.{1,15}\\)|\\[.{1,15}\\]|.){0,5}?(\\w+)'
4
4
  const LEGACY_VANILLA_CHAT_REGEX = new RegExp(`^${USERNAME_REGEX}\\s?[>:\\-»\\]\\)~]+\\s(.*)$`)
@@ -165,7 +165,7 @@ function inject (bot, options) {
165
165
  })
166
166
  }
167
167
 
168
- async function tabComplete (text, assumeCommand = false, sendBlockInSight = true) {
168
+ async function tabComplete (text, assumeCommand = false, sendBlockInSight = true, timeout = 5000) {
169
169
  let position
170
170
 
171
171
  if (sendBlockInSight) {
@@ -182,7 +182,7 @@ function inject (bot, options) {
182
182
  lookedAtBlock: position
183
183
  })
184
184
 
185
- const [packet] = await once(bot._client, 'tab_complete')
185
+ const [packet] = await onceWithCleanup(bot._client, 'tab_complete', { timeout })
186
186
  return packet.matches
187
187
  }
188
188
 
@@ -54,6 +54,7 @@ function inject (bot) {
54
54
  z: Math.sign(Math.abs(dz) > 0.5 ? dz : 0)
55
55
  }
56
56
  const validFaces = []
57
+ const closerBlocks = []
57
58
  for (const i in visibleFaces) {
58
59
  if (!visibleFaces[i]) continue // skip as this face is not visible
59
60
  // target position on the target block face. -> 0.5 + (current face) * 0.5
@@ -65,13 +66,19 @@ function inject (bot) {
65
66
  const startPos = bot.entity.position.offset(0, bot.entity.height, 0)
66
67
  const rayBlock = bot.world.raycast(startPos, targetPos.clone().subtract(startPos).normalize(), 5)
67
68
  if (rayBlock) {
69
+ if (startPos.distanceTo(rayBlock.intersect) < startPos.distanceTo(targetPos)) {
70
+ // Block is closer then the raycasted block
71
+ closerBlocks.push(rayBlock)
72
+ // continue since if distance is ever less, then we did not intersect the block we wanted,
73
+ // meaning that the position of the intersected block is not what we want.
74
+ continue
75
+ }
68
76
  const rayPos = rayBlock.position
69
77
  if (
70
78
  rayPos.x === block.position.x &&
71
79
  rayPos.y === block.position.y &&
72
80
  rayPos.z === block.position.z
73
81
  ) {
74
- // console.info(rayBlock)
75
82
  validFaces.push({
76
83
  face: rayBlock.face,
77
84
  targetPos: rayBlock.intersect
@@ -95,6 +102,11 @@ function inject (bot) {
95
102
  }
96
103
  await bot.lookAt(closest.targetPos, forceLook)
97
104
  diggingFace = closest.face
105
+ } else if (closerBlocks.length === 0 && block.shapes.length === 0) {
106
+ // no other blocks were detected and the block has no shapes.
107
+ // The block in question is replaceable (like tall grass) so we can just dig it
108
+ // TODO: do AABB + ray intercept check to this position for diggingFace.
109
+ await bot.lookAt(block.position.offset(0.5, 0.5, 0.5), forceLook)
98
110
  } else {
99
111
  // Block is obstructed return error?
100
112
  throw new Error('Block not in view')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mineflayer",
3
- "version": "4.18.0",
3
+ "version": "4.19.0",
4
4
  "description": "create minecraft bots with a stable, high level API",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",