mineflayer 4.17.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
@@ -17,7 +17,7 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md)
17
17
 
18
18
  ## Features
19
19
 
20
- * Supports Minecraft 1.8 to 1.20.1 (1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19 and 1.20)
20
+ * Supports Minecraft 1.8 to 1.20.2 (1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19 and 1.20)
21
21
  * Entity knowledge and tracking.
22
22
  * Block knowledge. You can query the world around you. Milliseconds to find any block.
23
23
  * Physics and movement - handle all bounding boxes
@@ -35,11 +35,16 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md)
35
35
 
36
36
  ## Installation
37
37
 
38
- First install Node.js >= 14 from [nodejs.org](https://nodejs.org/) then:
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
@@ -17,7 +17,7 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md)
17
17
 
18
18
  ## Features
19
19
 
20
- * Supports Minecraft 1.8 to 1.20.1 (1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19 and 1.20)
20
+ * Supports Minecraft 1.8 to 1.20.2 (1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19 and 1.20)
21
21
  * Entity knowledge and tracking.
22
22
  * Block knowledge. You can query the world around you. Milliseconds to find any block.
23
23
  * Physics and movement - handle all bounding boxes
@@ -35,11 +35,16 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md)
35
35
 
36
36
  ## Installation
37
37
 
38
- First install Node.js >= 14 from [nodejs.org](https://nodejs.org/) then:
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)
@@ -291,7 +291,7 @@
291
291
  - [bot.getExplosionDamages(entity, position, radius, [rawDamages])](#botgetexplosiondamagesentity-position-radius-rawdamages)
292
292
  - [bot.lookAt(point, [force])](#botlookatpoint-force)
293
293
  - [bot.look(yaw, pitch, [force])](#botlookyaw-pitch-force)
294
- - [bot.updateSign(block, text)](#botupdatesignblock-text)
294
+ - [bot.updateSign(block, text, back = false)](#botupdatesignblock-text-back--false)
295
295
  - [bot.equip(item, destination)](#botequipitem-destination)
296
296
  - [bot.unequip(destination)](#botunequipdestination)
297
297
  - [bot.tossStack(item)](#bottossstackitem)
@@ -331,6 +331,7 @@
331
331
  - [bot.setCommandBlock(pos, command, [options])](#botsetcommandblockpos-command-options)
332
332
  - [bot.supportFeature(name)](#botsupportfeaturename)
333
333
  - [bot.waitForTicks(ticks)](#botwaitforticksticks)
334
+ - [bot.respawn()](#botrespawn)
334
335
  - [Lower level inventory methods](#lower-level-inventory-methods)
335
336
  - [bot.clickWindow(slot, mouseButton, mode)](#botclickwindowslot-mousebutton-mode)
336
337
  - [bot.putSelectedItemRange(start, end, window, slot)](#botputselecteditemrangestart-end-window-slot)
@@ -1648,7 +1649,7 @@ End the connection with the server.
1648
1649
 
1649
1650
  Gracefully disconnect from the server with the given reason (defaults to 'disconnect.quitting').
1650
1651
 
1651
- #### bot.tabComplete(str, [assumeCommand], [sendBlockInSight])
1652
+ #### bot.tabComplete(str, [assumeCommand], [sendBlockInSight], [timeout])
1652
1653
 
1653
1654
  This function returns a `Promise`, with `matches` as its argument upon completion.
1654
1655
 
@@ -1656,6 +1657,7 @@ Requests chat completion from the server.
1656
1657
  * `str` - String to complete.
1657
1658
  * `assumeCommand` - Field sent to server, defaults to false.
1658
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.
1659
1661
 
1660
1662
  #### bot.chat(message)
1661
1663
 
@@ -2103,6 +2105,10 @@ The list of available features can be found inside the [./lib/features.json](htt
2103
2105
 
2104
2106
  This is a promise-based function that waits for a given number of in-game ticks to pass before continuing. This is useful for quick timers that need to function with specific timing, regardless of the given physics tick speed of the bot. This is similar to the standard Javascript setTimeout function, but runs on the physics timer of the bot specifically.
2105
2107
 
2108
+ #### bot.respawn()
2109
+
2110
+ When `respawn` option is disabled, you can call this method manually to respawn.
2111
+
2106
2112
  ### Lower level inventory methods
2107
2113
 
2108
2114
  These are lower level methods for the inventory, they can be useful sometimes but prefer the inventory methods presented above if you can.
@@ -33,7 +33,7 @@ Primeira vez usando o Node.js? Você pode querer começar com o tutorial [tutori
33
33
  - Dê uma olhada em nossos [projetos atuais](https://github.com/PrismarineJS/mineflayer/wiki/Big-Prismarine-projects)
34
34
 
35
35
  ## Instalação
36
- - Primeiro, instale o Node.js >= 14 a partir do [nodejs.org](https://nodejs.org/)
36
+ - Primeiro, instale o Node.js >= 18 a partir do [nodejs.org](https://nodejs.org/)
37
37
 
38
38
  `npm install mineflayer`
39
39
 
@@ -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)
@@ -34,7 +34,7 @@ Crea bots para Minecraft con una API de JavaScript potente, estable y de alto ni
34
34
  Echa un vistazo a nuestros [proyectos actuales](https://github.com/PrismarineJS/mineflayer/wiki/Big-Prismarine-projects)
35
35
 
36
36
  ## Instalación
37
- Primero instala Node.js >= 14 desde [nodejs.org](https://nodejs.org/)
37
+ Primero instala Node.js >= 18 desde [nodejs.org](https://nodejs.org/)
38
38
 
39
39
  `npm install mineflayer`
40
40
 
@@ -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,21 @@
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
+
12
+ ## 4.18.0
13
+ * [Minecraft 1.20.2 support (#3262)](https://github.com/PrismarineJS/mineflayer/commit/2ff9919760d714be57dcb678f8ab5ecff69f5fee) (thanks @rom1504)
14
+ * [Update recommended Node.js version (#3279)](https://github.com/PrismarineJS/mineflayer/commit/5c71edf48bb2f2dfa16cddb9af5baa0c4d55cf0d) (thanks @Nyaasu66)
15
+ * [feat: bot.respawn, fix respawn with flying squid (#3206)](https://github.com/PrismarineJS/mineflayer/commit/3a6ce543b4ba8a3d0f55777670d142968af14571) (thanks @zardoy)
16
+ * [Add `maxCatchupTicks`, improve `supportFeature` typing (#3277)](https://github.com/PrismarineJS/mineflayer/commit/91108d392c4c5800204dd4674ce9247495ac98e0) (thanks @zardoy)
17
+ * [Fixed typo of "fromt" to "from" (#3273)](https://github.com/PrismarineJS/mineflayer/commit/216cab742db1cd053d9fa23bd7293b770239085b) (thanks @BorretSquared)
18
+
1
19
  ## 4.17.0
2
20
  * [Exclude browser from node version check (#3268)](https://github.com/PrismarineJS/mineflayer/commit/c466d327227796865c53bfd24e66668911be4af5) (thanks @rom1504)
3
21
  * [Fix for a possible error in lib/plugins/entities.js file (#3254)](https://github.com/PrismarineJS/mineflayer/commit/15cfeb4fa59edfcddf7a0b70a966294b24d798ed) (thanks @Mykola1453)
@@ -368,7 +368,7 @@
368
368
  "mcData = require('minecraft-data')(bot.version)\n",
369
369
  "# Create a new movements class\n",
370
370
  "movements = pathfinder.Movements(bot, mcData)\n",
371
- "# How far to be fromt the goal\n",
371
+ "# How far to be from the goal\n",
372
372
  "RANGE_GOAL = 1"
373
373
  ],
374
374
  "execution_count": null,
@@ -531,4 +531,4 @@
531
531
  ]
532
532
  }
533
533
  ]
534
- }
534
+ }
@@ -35,7 +35,7 @@
35
35
 
36
36
  ## Установка
37
37
 
38
- Сначала установите Node.js >= 14 из [nodejs.org](https://nodejs.org/), затем выполните:
38
+ Сначала установите Node.js >= 18 из [nodejs.org](https://nodejs.org/), затем выполните:
39
39
 
40
40
  `npm install mineflayer`
41
41
 
@@ -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,13 +30,14 @@
30
30
  * 各种各样的的信息接口,比如查看你的血量或是否下雨
31
31
  * 激活方块和使用物品
32
32
  * 进行聊天
33
+
33
34
  ### 路线图
34
35
 
35
36
  [点这里](https://github.com/PrismarineJS/mineflayer/wiki/Big-Prismarine-projects) 看看目前我们有哪些实用的项目
36
37
 
37
38
  ## 安装
38
39
 
39
- 首先,从 [nodejs.org](https://nodejs.org/) 安装 nodejs(版本要求 >= 14),
40
+ 首先,从 [nodejs.org](https://nodejs.org/) 安装 nodejs(版本要求 >= 18),
40
41
 
41
42
  然后在你创建的bot项目目录中,使用命令行运行:
42
43
 
@@ -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)
@@ -3,7 +3,7 @@
3
3
  "version": "0.0.0",
4
4
  "private": true,
5
5
  "dependencies": {
6
- "mineflayer-pathfinder": "^1.6.1",
6
+ "mineflayer-pathfinder": "^2.4.5",
7
7
  "mineflayer": "file:../../"
8
8
  },
9
9
  "description": "A mineflayer example"
package/index.d.ts CHANGED
@@ -10,6 +10,7 @@ import { Entity } from 'prismarine-entity'
10
10
  import { ChatMessage } from 'prismarine-chat'
11
11
  import { world } from 'prismarine-world'
12
12
  import { Registry } from 'prismarine-registry'
13
+ import { IndexedData } from 'minecraft-data'
13
14
 
14
15
  export function createBot (options: { client: Client } & Partial<BotOptions>): Bot
15
16
  export function createBot (options: BotOptions): Bot
@@ -26,6 +27,8 @@ export interface BotOptions extends ClientOptions {
26
27
  difficulty?: number
27
28
  chatLengthLimit?: number
28
29
  physicsEnabled?: boolean
30
+ /** @default 4 */
31
+ maxCatchupTicks?: number
29
32
  client?: Client
30
33
  brand?: string
31
34
  defaultChatPatterns?: boolean
@@ -64,6 +67,7 @@ export interface BotEvents {
64
67
  unmatchedMessage: (stringMsg: string, jsonMsg: ChatMessage) => Promise<void> | void
65
68
  inject_allowed: () => Promise<void> | void
66
69
  login: () => Promise<void> | void
70
+ /** When `respawn` option is disabled, you can call this method manually to respawn. */
67
71
  spawn: () => Promise<void> | void
68
72
  respawn: () => Promise<void> | void
69
73
  game: () => Promise<void> | void
@@ -190,10 +194,11 @@ export interface Bot extends TypedEmitter<BotEvents> {
190
194
  isSleeping: boolean
191
195
  scoreboards: { [name: string]: ScoreBoard }
192
196
  scoreboard: { [slot in DisplaySlot]: ScoreBoard }
197
+ teams: { [name: string]: Team }
193
198
  teamMap: { [name: string]: Team }
194
199
  controlState: ControlStateStatus
195
200
  creative: creativeMethods
196
- world: world.World
201
+ world: world.WorldSync
197
202
  _client: Client
198
203
  heldItem: Item | null
199
204
  usingHeldItem: boolean
@@ -204,7 +209,7 @@ export interface Bot extends TypedEmitter<BotEvents> {
204
209
 
205
210
  connect: (options: BotOptions) => void
206
211
 
207
- supportFeature: (feature: string) => boolean
212
+ supportFeature: IndexedData['supportFeature']
208
213
 
209
214
  end: (reason?: string) => void
210
215
 
@@ -241,7 +246,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
241
246
  tabComplete: (
242
247
  str: string,
243
248
  assumeCommand?: boolean,
244
- sendBlockInSight?: boolean
249
+ sendBlockInSight?: boolean,
250
+ timeout?: number
245
251
  ) => Promise<string[]>
246
252
 
247
253
  chat: (message: string) => void
@@ -424,6 +430,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
424
430
  acceptResourcePack: () => void
425
431
 
426
432
  denyResourcePack: () => void
433
+
434
+ respawn: () => void
427
435
  }
428
436
 
429
437
  export interface simpleClick {
@@ -773,7 +781,7 @@ export class ScoreBoard {
773
781
 
774
782
  setTitle (title: string): void;
775
783
 
776
- add (name: string, value: number, displayName: ChatMessage): ScoreBoardItem;
784
+ add(name: string, value: number): ScoreBoardItem;
777
785
 
778
786
  remove (name: string): ScoreBoardItem;
779
787
  }
@@ -785,6 +793,7 @@ export interface ScoreBoardItem {
785
793
  }
786
794
 
787
795
  export class Team {
796
+ team: string
788
797
  name: ChatMessage
789
798
  friendlyFire: number
790
799
  nameTagVisibility: string
@@ -792,8 +801,10 @@ export class Team {
792
801
  color: string
793
802
  prefix: ChatMessage
794
803
  suffix: ChatMessage
804
+ memberMap: { [name: string]: '' }
805
+ members: string[]
795
806
 
796
- constructor (packet: object);
807
+ constructor(team: string, name: string, friendlyFire: boolean, nameTagVisibility: string, collisionRule: string, formatting: number, prefix: string, suffix: string);
797
808
 
798
809
  parseMessage (value: string): ChatMessage;
799
810
 
@@ -835,6 +846,7 @@ export class BossBar {
835
846
  color: 'pink' | 'blue' | 'red' | 'green' | 'yellow' | 'purple' | 'white'
836
847
  shouldDarkenSky: boolean
837
848
  isDragonBar: boolean
849
+ createFog: boolean
838
850
  shouldCreateFog: boolean
839
851
 
840
852
  constructor (
@@ -848,23 +860,22 @@ export class BossBar {
848
860
  }
849
861
 
850
862
  export class Particle {
851
- id: number
852
- name: string
853
- position: Vec3
854
- offset: Vec3
855
- count: number
856
- movementSpeed: number
857
- longDistanceRender: boolean
858
- static fromNetwork(packet: Object): Particle
859
-
860
- constructor (
861
- id: number,
862
- position: Vec3,
863
- offset: Vec3,
864
- count?: number,
865
- movementSpeed?: number,
866
- longDistanceRender?: boolean
867
- );
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
+ );
868
879
  }
869
880
 
870
881
  export let testedVersions: string[]
@@ -268,6 +268,30 @@ function inject (bot, { version, storageBuilder, hideErrors }) {
268
268
  }
269
269
  })
270
270
 
271
+ // Chunk batches are used by the server to throttle the chunks per tick for players based on their connection speed.
272
+ let chunkBatchStartTime = 0
273
+ // The Vanilla client uses nano seconds with its weighted average starting at 2000000 converted to milliseconds that is 2
274
+ let weightedAverage = 2
275
+ // This is used for keeping track of the weight of the old average when updating it.
276
+ let oldSampleWeight = 1
277
+
278
+ bot._client.on('chunk_batch_start', (packet) => {
279
+ // Get the time the chunk batch is starting.
280
+ chunkBatchStartTime = Date.now()
281
+ })
282
+
283
+ bot._client.on('chunk_batch_finished', (packet) => {
284
+ const milliPerChunk = (Date.now() - chunkBatchStartTime) / packet.batchSize
285
+ // Prevents the MilliPerChunk from being hugely different then the average, Vanilla uses 3 as a constant here.
286
+ const clampedMilliPerChunk = Math.min(Math.max(milliPerChunk, weightedAverage / 3.0), weightedAverage * 3.0)
287
+ weightedAverage = ((weightedAverage * oldSampleWeight) + clampedMilliPerChunk) / (oldSampleWeight + 1)
288
+ // 49 is used in Vanilla client to limit it to 50 samples
289
+ oldSampleWeight = Math.min(49, oldSampleWeight + 1)
290
+ bot._client.write('chunk_batch_received', {
291
+ // Vanilla uses 7000000 as a constant here, since we are using milliseconds that is now 7. Not sure why they pick this constant to convert from nano seconds per chunk to chunks per tick.
292
+ chunksPerTick: 7 / weightedAverage
293
+ })
294
+ })
271
295
  bot._client.on('map_chunk', (packet) => {
272
296
  addColumn({
273
297
  x: packet.x,
@@ -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')
@@ -26,7 +26,7 @@ const entityStatusEvents = {
26
26
  }
27
27
 
28
28
  function inject (bot) {
29
- const { mobs, entitiesArray } = bot.registry
29
+ const { mobs } = bot.registry
30
30
  const Entity = require('prismarine-entity')(bot.version)
31
31
  const Item = require('prismarine-item')(bot.version)
32
32
  const ChatMessage = require('prismarine-chat')(bot.registry)
@@ -129,33 +129,6 @@ function inject (bot) {
129
129
  if (eventName) bot.emit(eventName, entity)
130
130
  })
131
131
 
132
- bot._client.on('named_entity_spawn', (packet) => {
133
- // in case player_info packet was not sent before named_entity_spawn : ignore named_entity_spawn (see #213)
134
- if (packet.playerUUID in bot.uuidToUsername) {
135
- // spawn named entity
136
- const entity = fetchEntity(packet.entityId)
137
- entity.type = 'player'
138
- entity.name = 'player'
139
- entity.username = bot.uuidToUsername[packet.playerUUID]
140
- entity.uuid = packet.playerUUID
141
- entity.dataBlobs = packet.data
142
- if (bot.supportFeature('fixedPointPosition')) {
143
- entity.position.set(packet.x / 32, packet.y / 32, packet.z / 32)
144
- } else if (bot.supportFeature('doublePosition')) {
145
- entity.position.set(packet.x, packet.y, packet.z)
146
- }
147
- entity.yaw = conv.fromNotchianYawByte(packet.yaw)
148
- entity.pitch = conv.fromNotchianPitchByte(packet.pitch)
149
- entity.height = NAMED_ENTITY_HEIGHT
150
- entity.width = NAMED_ENTITY_WIDTH
151
- entity.metadata = parseMetadata(packet.metadata, entity.metadata)
152
- if (bot.players[entity.username] !== undefined && !bot.players[entity.username].entity) {
153
- bot.players[entity.username].entity = entity
154
- }
155
- bot.emit('entitySpawn', entity)
156
- }
157
- })
158
-
159
132
  bot.on('entityCrouch', (entity) => {
160
133
  entity.height = CROUCH_HEIGHT
161
134
  })
@@ -171,10 +144,11 @@ function inject (bot) {
171
144
  bot.emit('playerCollect', collector, collected)
172
145
  })
173
146
 
147
+ // What is internalId?
148
+ const entityDataByInternalId = Object.fromEntries(bot.registry.entitiesArray.map((e) => [e.internalId, e]))
149
+
174
150
  function setEntityData (entity, type, entityData) {
175
- if (entityData === undefined) {
176
- entityData = entitiesArray.find(entity => entity.internalId === type)
177
- }
151
+ entityData ??= entityDataByInternalId[type]
178
152
  if (entityData) {
179
153
  entity.type = entityData.type || 'object'
180
154
  entity.displayName = entityData.displayName
@@ -193,24 +167,57 @@ function inject (bot) {
193
167
  }
194
168
  }
195
169
 
196
- // spawn object/vehicle on versions < 1.19, on versions > 1.19 handles all non-player entities
197
- bot._client.on('spawn_entity', (packet) => {
198
- const entity = fetchEntity(packet.entityId)
199
- const entityData = bot.registry.entities[packet.type]
200
- setEntityData(entity, packet.type, entityData)
201
-
170
+ function updateEntityPos (entity, pos) {
202
171
  if (bot.supportFeature('fixedPointPosition')) {
203
- entity.position.set(packet.x / 32, packet.y / 32, packet.z / 32)
172
+ entity.position.set(pos.x / 32, pos.y / 32, pos.z / 32)
204
173
  } else if (bot.supportFeature('doublePosition')) {
205
- entity.position.set(packet.x, packet.y, packet.z)
206
- } else if (bot.supportFeature('consolidatedEntitySpawnPacket')) {
207
- entity.headPitch = conv.fromNotchianPitchByte(packet.headPitch)
174
+ entity.position.set(pos.x, pos.y, pos.z)
208
175
  }
176
+ entity.yaw = conv.fromNotchianYawByte(pos.yaw)
177
+ entity.pitch = conv.fromNotchianPitchByte(pos.pitch)
178
+ }
209
179
 
210
- entity.uuid = packet.objectUUID
211
- entity.yaw = conv.fromNotchianYawByte(packet.yaw)
212
- entity.pitch = conv.fromNotchianPitchByte(packet.pitch)
213
- entity.objectData = packet.objectData
180
+ function addNewPlayer (entityId, uuid, pos) {
181
+ const entity = fetchEntity(entityId)
182
+ entity.type = 'player'
183
+ entity.name = 'player'
184
+ entity.username = bot.uuidToUsername[uuid]
185
+ entity.uuid = uuid
186
+ updateEntityPos(entity, pos)
187
+ entity.height = NAMED_ENTITY_HEIGHT
188
+ entity.width = NAMED_ENTITY_WIDTH
189
+ if (bot.players[entity.username] !== undefined && !bot.players[entity.username].entity) {
190
+ bot.players[entity.username].entity = entity
191
+ }
192
+ return entity
193
+ }
194
+
195
+ function addNewNonPlayer (entityId, uuid, entityType, pos) {
196
+ const entity = fetchEntity(entityId)
197
+ const entityData = bot.registry.entities[entityType]
198
+ setEntityData(entity, entityType, entityData)
199
+ updateEntityPos(entity, pos)
200
+ return entity
201
+ }
202
+
203
+ bot._client.on('named_entity_spawn', (packet) => {
204
+ // in case player_info packet was not sent before named_entity_spawn : ignore named_entity_spawn (see #213)
205
+ if (packet.playerUUID in bot.uuidToUsername) {
206
+ // spawn named entity
207
+ const entity = addNewPlayer(packet.entityId, packet.playerUUID, packet, packet.metadata)
208
+ entity.dataBlobs = packet.data // this field doesn't appear to be listed on any version
209
+ entity.metadata = parseMetadata(packet.metadata, entity.metadata) // 1.8
210
+ bot.emit('entitySpawn', entity)
211
+ }
212
+ })
213
+
214
+ // spawn object/vehicle on versions < 1.19, on versions > 1.19 handles all non-player entities
215
+ // on versions >= 1.20.2, this also handles player entities
216
+ bot._client.on('spawn_entity', (packet) => {
217
+ const entityData = entityDataByInternalId[packet.type]
218
+ const entity = entityData?.type === 'player'
219
+ ? addNewPlayer(packet.entityId, packet.objectUUID, packet)
220
+ : addNewNonPlayer(packet.entityId, packet.objectUUID, packet.type, packet)
214
221
  bot.emit('entitySpawn', entity)
215
222
  })
216
223
 
@@ -71,6 +71,11 @@ function inject (bot, options) {
71
71
  const brandChannel = getBrandCustomChannelName()
72
72
  bot._client.registerChannel(brandChannel, ['string', []])
73
73
 
74
+ // 1.20.2
75
+ bot._client.on('registry_data', (packet) => {
76
+ bot.registry.loadDimensionCodec(packet.codec)
77
+ })
78
+
74
79
  bot._client.on('login', (packet) => {
75
80
  handleRespawnPacketData(packet)
76
81
 
@@ -25,10 +25,17 @@ function inject (bot, options) {
25
25
  bot.emit('death')
26
26
  }
27
27
  if (!options.respawn) return
28
- bot._client.write('client_command', { payload: 0 })
28
+ bot.respawn()
29
29
  } else if (bot.health > 0 && !bot.isAlive) {
30
30
  bot.isAlive = true
31
31
  bot.emit('spawn')
32
32
  }
33
33
  })
34
+
35
+ const respawn = () => {
36
+ if (bot.isAlive) return
37
+ bot._client.write('client_command', bot.supportFeature('respawnIsPayload') ? { payload: 0 } : { actionId: 0 })
38
+ }
39
+
40
+ bot.respawn = respawn
34
41
  }
package/lib/version.js CHANGED
@@ -1,6 +1,8 @@
1
- const testedVersions = ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20.1']
1
+ const testedVersions = ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.5', '1.17.1', '1.18.2', '1.19', '1.19.2', '1.19.3', '1.19.4', '1.20.1', '1.20.2']
2
2
  module.exports = {
3
+
3
4
  testedVersions,
4
5
  latestSupportedVersion: testedVersions[testedVersions.length - 1],
5
6
  oldestSupportedVersion: testedVersions[0]
7
+
6
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mineflayer",
3
- "version": "4.17.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",
@@ -17,11 +17,11 @@
17
17
  "url": "git://github.com/PrismarineJS/mineflayer.git"
18
18
  },
19
19
  "engines": {
20
- "node": ">=14"
20
+ "node": ">=18"
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "minecraft-data": "^3.44.0",
24
+ "minecraft-data": "^3.56.0",
25
25
  "minecraft-protocol": "^1.44.0",
26
26
  "prismarine-biome": "^1.1.1",
27
27
  "prismarine-block": "^1.17.0",