mineflayer 3.18.0 → 4.2.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.
Files changed (43) hide show
  1. package/.github/workflows/ci.yml +1 -1
  2. package/README.md +1 -1
  3. package/docs/README.md +1 -1
  4. package/docs/api.md +38 -9
  5. package/docs/es/README_ES.md +6 -6
  6. package/docs/history.md +20 -0
  7. package/docs/ru/README_RU.md +1 -2
  8. package/docs/tutorial.md +27 -78
  9. package/examples/inventory.js +1 -1
  10. package/index.d.ts +8 -4
  11. package/lib/bossbar.js +1 -1
  12. package/lib/loader.js +4 -4
  13. package/lib/plugins/anvil.js +4 -4
  14. package/lib/plugins/bed.js +3 -5
  15. package/lib/plugins/block_actions.js +2 -2
  16. package/lib/plugins/blocks.js +2 -2
  17. package/lib/plugins/book.js +8 -10
  18. package/lib/plugins/chat.js +3 -22
  19. package/lib/plugins/chest.js +5 -6
  20. package/lib/plugins/craft.js +3 -4
  21. package/lib/plugins/creative.js +15 -13
  22. package/lib/plugins/digging.js +2 -25
  23. package/lib/plugins/enchantment_table.js +5 -6
  24. package/lib/plugins/entities.js +9 -9
  25. package/lib/plugins/fishing.js +4 -6
  26. package/lib/plugins/furnace.js +6 -7
  27. package/lib/plugins/game.js +4 -1
  28. package/lib/plugins/generic_place.js +2 -2
  29. package/lib/plugins/inventory.js +23 -25
  30. package/lib/plugins/physics.js +6 -8
  31. package/lib/plugins/place_block.js +2 -2
  32. package/lib/plugins/place_entity.js +2 -2
  33. package/lib/plugins/settings.js +25 -5
  34. package/lib/plugins/simple_inventory.js +4 -5
  35. package/lib/plugins/tablist.js +1 -1
  36. package/lib/plugins/villager.js +5 -6
  37. package/lib/promise_utils.js +1 -25
  38. package/lib/scoreboard.js +1 -1
  39. package/lib/team.js +2 -2
  40. package/lib/version.js +1 -1
  41. package/package.json +4 -3
  42. package/lib/features.json +0 -337
  43. package/lib/supportFeature.js +0 -27
@@ -28,7 +28,7 @@ jobs:
28
28
  - javaVersion: 16
29
29
  mcVersion: '1.17.1'
30
30
  - javaVersion: 17
31
- mcVersion: '1.18.1'
31
+ mcVersion: '1.18.2'
32
32
  fail-fast: false
33
33
 
34
34
  steps:
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, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 and 1.18.
20
+ * Supports Minecraft 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 and 1.18.
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
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, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 and 1.18.
20
+ * Supports Minecraft 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 and 1.18.
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
package/docs/api.md CHANGED
@@ -20,8 +20,8 @@
20
20
  - [Biome](#biome)
21
21
  - [Item](#item)
22
22
  - [windows.Window (base class)](#windowswindow-base-class)
23
- - [window.deposit(itemType, metadata, count)](#windowdeposititemtype-metadata-count)
24
- - [window.withdraw(itemType, metadata, count)](#windowwithdrawitemtype-metadata-count)
23
+ - [window.deposit(itemType, metadata, count, nbt)](#windowdeposititemtype-metadata-count-nbt)
24
+ - [window.withdraw(itemType, metadata, count, nbt)](#windowwithdrawitemtype-metadata-count-nbt)
25
25
  - [window.close()](#windowclose)
26
26
  - [Recipe](#recipe)
27
27
  - [mineflayer.Container](#mineflayercontainer)
@@ -78,6 +78,7 @@
78
78
  - [Bot](#bot)
79
79
  - [mineflayer.createBot(options)](#mineflayercreatebotoptions)
80
80
  - [Properties](#properties)
81
+ - [bot.registry](#botregistry)
81
82
  - [bot.world](#botworld)
82
83
  - [world "blockUpdate" (oldBlock, newBlock)](#world-blockupdate-oldblock-newblock)
83
84
  - [world "blockUpdate:(x, y, z)" (oldBlock, newBlock)](#world-blockupdatex-y-z-oldblock-newblock)
@@ -94,6 +95,8 @@
94
95
  - [bot.game.hardcore](#botgamehardcore)
95
96
  - [bot.game.maxPlayers](#botgamemaxplayers)
96
97
  - [bot.game.serverBrand](#botgameserverbrand)
98
+ - [bot.game.minY](#botgameminy)
99
+ - [bot.game.height](#botgameheight)
97
100
  - [bot.physicsEnabled](#botphysicsenabled)
98
101
  - [bot.player](#botplayer)
99
102
  - [bot.players](#botplayers)
@@ -113,6 +116,8 @@
113
116
  - [bot.settings.skinParts.showLeftPants - boolean](#botsettingsskinpartsshowleftpants---boolean)
114
117
  - [bot.settings.skinParts.showRightPants - boolean](#botsettingsskinpartsshowrightpants---boolean)
115
118
  - [bot.settings.skinParts.showHat - boolean](#botsettingsskinpartsshowhat---boolean)
119
+ - [bot.settings.enableTextFiltering - boolean](#botsettingsenabletextfiltering---boolean)
120
+ - [bot.settings.enableServerListing - boolean](#botsettingsenableserverlisting---boolean)
116
121
  - [bot.experience.level](#botexperiencelevel)
117
122
  - [bot.experience.points](#botexperiencepoints)
118
123
  - [bot.experience.progress](#botexperienceprogress)
@@ -418,21 +423,23 @@ See [prismarine-item](https://github.com/PrismarineJS/prismarine-item)
418
423
 
419
424
  See [prismarine-windows](https://github.com/PrismarineJS/prismarine-windows)
420
425
 
421
- #### window.deposit(itemType, metadata, count)
426
+ #### window.deposit(itemType, metadata, count, nbt)
422
427
 
423
428
  This function returns a `Promise`, with `void` as its argument when done depositing.
424
429
 
425
430
  * `itemType` - numerical item id
426
431
  * `metadata` - numerical value. `null` means match anything.
427
432
  * `count` - how many to deposit. `null` is an alias to 1.
433
+ * `nbt` - match nbt data. `null` is do not match nbt.
428
434
 
429
- #### window.withdraw(itemType, metadata, count)
435
+ #### window.withdraw(itemType, metadata, count, nbt)
430
436
 
431
- This function returns a `Promise`, with `void` as its argument when done withdrawing.
437
+ This function returns a `Promise`, with `void` as its argument when done withdrawing. Throws and error if the bot has no free room in its inventory.
432
438
 
433
439
  * `itemType` - numerical item id
434
440
  * `metadata` - numerical value. `null` means match anything.
435
441
  * `count` - how many to withdraw. `null` is an alias to 1.
442
+ * `nbt` - match nbt data. `null` is do not match nbt.
436
443
 
437
444
  #### window.close()
438
445
 
@@ -745,11 +752,17 @@ Create and return an instance of the class bot.
745
752
  * [viewDistance](#bot.settings.viewDistance)
746
753
  * [difficulty](#bot.settings.difficulty)
747
754
  * [skinParts](#bot.settings.skinParts)
755
+ * [enableTextFiltering](#bot.settings.enableTextFiltering)
756
+ * [enableServerListing](#bot.settings.enableServerListing)
748
757
  * chatLengthLimit : the maximum amount of characters that can be sent in a single message. If this is not set, it will be 100 in < 1.11 and 256 in >= 1.11.
749
758
  * defaultChatPatterns: defaults to true, set to false to not add the patterns such as chat and whisper
750
759
 
751
760
  ### Properties
752
761
 
762
+ #### bot.registry
763
+
764
+ Instance of minecraft-data used by the bot. Pass this to constructors that expect an instance of minecraft-data, such as prismarine-block.
765
+
753
766
  #### bot.world
754
767
 
755
768
  A sync representation of the world. Check the doc at http://github.com/PrismarineJS/prismarine-world
@@ -881,6 +894,7 @@ Default true, whether or not you receive color codes in chats from the server.
881
894
 
882
895
  #### bot.settings.viewDistance
883
896
 
897
+ Can be a string listed below or a postive number.
884
898
  Choices:
885
899
  * `far` (default)
886
900
  * `normal`
@@ -911,7 +925,10 @@ If you have a cape you can turn it off by setting this to false.
911
925
 
912
926
  ##### bot.settings.skinParts.showHat - boolean
913
927
 
914
-
928
+ #### bot.settings.enableTextFiltering - boolean
929
+ Unused, defaults to false in Notchian (Vanilla) client.
930
+ #### bot.settings.enableServerListing - boolean
931
+ This setting is sent to the server to determine whether the player should show up in server listings
915
932
  #### bot.experience.level
916
933
 
917
934
  #### bot.experience.points
@@ -1847,13 +1864,13 @@ use shears.
1847
1864
  Attack a player or a mob.
1848
1865
 
1849
1866
  * `entity` is a type of entity. To get a specific entity use [bot.nearestEntity()](#botnearestentitymatch--entity---return-true-) or [bot.entities](#botentities).
1850
- * `swing` Default `true`. If false the bot does not swing is arm when attacking.
1867
+ * `swing` Default to `true`. If false the bot does not swing its arm when attacking.
1851
1868
 
1852
1869
  #### bot.swingArm([hand], showHand)
1853
1870
 
1854
1871
  Play an arm swing animation.
1855
1872
 
1856
- * `hand` can take `left` or `right` which is arm that is animated. Default: `right`
1873
+ * `hand` can take `left` or `right` which is the arm that is animated. Default: `right`
1857
1874
  * `showHand` is a boolean whether to add the hand to the packet, Default: `true`
1858
1875
 
1859
1876
  #### bot.mount(entity)
@@ -2039,7 +2056,7 @@ but it is assumed and often required that the bot be in creative mode for these
2039
2056
 
2040
2057
  #### bot.creative.setInventorySlot(slot, item)
2041
2058
 
2042
- This function returns a `Promise`, with `void` as its argument when gets fired when the servers sets the slot.
2059
+ This function returns a `Promise`, with `void` as its argument when gets fired when the server sets the slot.
2043
2060
 
2044
2061
  Gives the bot the specified item in the specified inventory slot.
2045
2062
 
@@ -2049,6 +2066,18 @@ Gives the bot the specified item in the specified inventory slot.
2049
2066
 
2050
2067
  If this method changes anything, you can be notified via `bot.inventory.on("updateSlot")`.
2051
2068
 
2069
+ #### bot.creative.clearSlot(slot)
2070
+
2071
+ This function returns a `Promise`, with `void` as its argument when gets fired when the server clears the slot.
2072
+
2073
+ Makes the sets the item in the slot given to null.
2074
+
2075
+ * `slot` is in inventory window coordinates (where 36 is the first quickbar slot, etc.).
2076
+
2077
+ #### bot.creative.clearInventory()
2078
+
2079
+ This function returns a `Promise`, with `void` as its argument when gets fired when the server clears the slot.
2080
+
2052
2081
  #### bot.creative.flyTo(destination)
2053
2082
 
2054
2083
  This function returns a `Promise`, with `void` as its argument when the bot arrives at the destination.
@@ -17,7 +17,7 @@ Crea bots para Minecraft con una API de JavaScript potente, estable y de alto ni
17
17
 
18
18
  ## Características
19
19
 
20
- * Soporta Minecraft 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15 y 1.16.
20
+ * Soporta Minecraft 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 y 1.18.
21
21
  * Rastreo e información de entidades.
22
22
  * Información sobre bloques. Puedes solicitar información de todo lo que te rodea. Encuentra bloques en milisegundos
23
23
  * Físicas y movimientos básicos - maneja todos los cuadros de colisión
@@ -34,6 +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
38
 
38
39
  `npm install mineflayer`
39
40
 
@@ -66,10 +67,9 @@ Si quieres aprender más, puedes mirar [aquí, ](https://www.youtube.com/playlis
66
67
 
67
68
  **Empezando**
68
69
 
69
- Sin especificar una versión, la versión del servidor se detectará automáticamente, puedes configurar una versión específica utilizando la opción de versión.
70
- Por ejemplo `version:" 1.8 "`.
70
+ Si no se especifica una versión, la versión del servidor se detectará automáticamente. Si no se especifica ningún tipo de autenticación, se utilizará el login de Mojang automáticamente.
71
71
 
72
- ### Ejemplo
72
+ ### Ejemplo: echo
73
73
  ```js
74
74
  const mineflayer = require('mineflayer')
75
75
 
@@ -92,7 +92,7 @@ bot.on('kicked', (reason, loggedIn) => console.log(reason, loggedIn))
92
92
  bot.on('error', err => console.log(err))
93
93
  ```
94
94
 
95
- ### Mira lo que tu bot hace
95
+ ### Mira lo que hace tu bot
96
96
 
97
97
  Gracias al proyecto [prismarine-viewer](https://github.com/PrismarineJS/prismarine-viewer), puedes ver en una pestaña del navegador qué está haciendo tu bot.
98
98
  Solo tienes que ejecutar `npm install prismarine-viewer` y añadir lo siguiente a tu bot:
@@ -124,7 +124,7 @@ Más ejemplos en la carpeta de [ejemplos](https://github.com/PrismarineJS/minefl
124
124
 
125
125
  ### Módulos
126
126
 
127
- La mayoría del desarrollo se esta produciendo dentro de pequeños módulos npm que son usados por mineflayer
127
+ La mayoría del desarrollo se está produciendo dentro de pequeños módulos npm que son usados por mineflayer
128
128
 
129
129
  #### The Node Way&trade;
130
130
 
package/docs/history.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## 4.2.0
2
+
3
+ * add missing extraInfos argument to Bot.blockAt function (@dumbasPL)
4
+ * Emit window close event AFTER updating the inventory (@imharvol)
5
+ * Move supportFeature to mcdata (@U9G)
6
+ * Update lib/ and test/ to use prismarine-registry (@extremeheat)
7
+ * only open chests with openContainer (@U9G)
8
+ * Add bot.creative.clearSlot and bot.creative.clearInventory (@U9G)
9
+ * remove transaction warning
10
+
11
+ ## 4.1.0
12
+
13
+ * 1.18.2 support
14
+ * Add nbt option to withdraw and deposit
15
+
16
+ ## 4.0.0
17
+
18
+ * useEntity maintains sneak state
19
+ * BREAKING: remove all callbacks in favor of promises
20
+
1
21
  ## 3.18.0
2
22
 
3
23
  * remove callbacks from types and docs
@@ -18,7 +18,7 @@
18
18
 
19
19
  ## Возможности
20
20
 
21
- * Поддержка 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15 и 1.16.
21
+ * Поддержка 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17 и 1.18
22
22
  * Поддержка энтити и их отслеживание
23
23
  * Вы можете полностью взаимодействовать с миром. Миллисекунды на поиск любого блока
24
24
  * Физика и управление
@@ -46,7 +46,6 @@
46
46
  | -------------------------------------------------------------------------- | ------------------------------------- |
47
47
  | [Обучение](tutorial.md) | Знакомство с Node.js и Mineflayer |
48
48
  | [FAQ](FAQ_RU.md) | Появился вопрос? Найдите ответ здесь. |
49
- | [API](api_ru.md) | Методы API |
50
49
  | [Нестабильное API](unstable_api_ru.md) | Нестабильные методы API |
51
50
  | [Обновления](history.md) | Список изменений в обновлениях |
52
51
  | [Примеры](https://github.com/PrismarineJS/mineflayer/tree/master/examples) | Примеры использования Mineflayer |
package/docs/tutorial.md CHANGED
@@ -17,7 +17,7 @@
17
17
  - [Logging in](#logging-in)
18
18
  - [Passing along functions](#passing-along-functions)
19
19
  - [Listening for an event](#listening-for-an-event)
20
- - [Callbacks](#callbacks)
20
+ - [Promises](#promises)
21
21
  - [Correct and incorrect approach](#correct-and-incorrect-approach)
22
22
  - [Advanced](#advanced)
23
23
  - [Asynchronousy](#asynchronousy)
@@ -430,18 +430,18 @@ To remove specific listener you can use `bot.removeListener()` method.
430
430
 
431
431
  Not only bot object, [`Chest`](http://mineflayer.prismarine.js.org/#/api?id=mineflayerchest), [`Furnace`](http://mineflayer.prismarine.js.org/#/api?id=mineflayerfurnace), [`Dispenser`](http://mineflayer.prismarine.js.org/#/api?id=mineflayerdispenser), [`EnchantmentTable`](http://mineflayer.prismarine.js.org/#/api?id=mineflayerenchantmenttable), [`Villager`](http://mineflayer.prismarine.js.org/#/api?id=mineflayervillager) object also have their own events!
432
432
 
433
- ### Callbacks
434
- A [callback](https://en.wikipedia.org/wiki/Callback_(computer_programming)) is a function that you can give to another function, that is expected to be *called back*, generally when that function ends.
435
- In Mineflayer, callbacks are often used to handle errors.
433
+ ### Promises
434
+ A [promise](https://nodejs.dev/learn/understanding-javascript-promises) is a function that you can use the `await` variable to wait on until it's job is complete. (you can omit the await to not wait for results)
436
435
 
437
436
  ```js
438
- bot.consume((error) => {
439
- if (error) { // This checks if an error occurred.
440
- console.log(error)
441
- } else {
437
+ async function consume (bot) {
438
+ try {
439
+ await bot.consume()
442
440
  console.log('Finished consuming')
441
+ } catch (err) {
442
+ console.log(error)
443
443
  }
444
- })
444
+ }
445
445
  ```
446
446
 
447
447
  The above code will try to consume what the bot is currently holding.
@@ -456,91 +456,40 @@ Below is an example of a bot that will craft oak logs into oak planks and then i
456
456
  Incorect approach ❌:
457
457
 
458
458
  ```js
459
- const plankRecipe = bot.recipesFor(5)[0] // Get the first recipe for item id 5, which is oak planks.
460
- bot.craft(plankRecipe, 1) // ❌ start crafting oak planks.
459
+ function craft (bot) {
460
+ const mcData = require('minecraft-data')(bot.version)
461
+ const plankRecipe = bot.recipesFor(mcData.itemsByName.oak_planks.id ?? mcData.itemsByName.planks.id)[0] // Get the first recipe for oak planks
462
+ bot.craft(plankRecipe, 1) // ❌ start crafting oak planks.
461
463
 
462
- const stickRecipe = bot.recipesFor(280)[0] // Get the first recipe for item id 5, which is sticks.
463
- bot.craft(stickRecipe, 1) // ❌ start crafting sticks.
464
+ const stickRecipe = bot.recipesFor(mcData.itemsByName.sticks.id)[0] // Get the first recipe for sticks
465
+ bot.craft(stickRecipe, 1) // ❌ start crafting sticks.
466
+ }
464
467
  ```
465
468
 
466
- Correct approach with callbacks ✔️:
469
+ Correct approach with promises ✔️:
467
470
 
468
471
  ```js
469
- const plankRecipe = bot.recipesFor(5)[0]
470
-
471
- bot.craft(plankRecipe, 1, null, (error) => {
472
- // After bot.craft(plankRecipe, ...) is finished, this callback is called and we continue. ✔️
473
- if (error) { // Check if an error happened.
474
- console.log(error)
475
- } else {
476
- const stickRecipe = bot.recipesFor(280)[0]
477
-
478
- bot.craft(stickRecipe, 1, null, (error) => {
479
- // After bot.craft(stickRecipe, ...) is finished, this callback is called and we continue. ✔️
480
- if (error) { // Check if an error happened.
481
- console.log(error)
482
- } else {
483
- bot.chat('Crafting Sticks finished')
484
- }
485
- })
486
- }
487
- })
472
+ async function craft (bot) {
473
+ const mcData = require('minecraft-data')(bot.version)
474
+ const plankRecipe = bot.recipesFor(mcData.itemsByName.oak_planks.id ?? mcData.itemsByName.planks.id)[0]
475
+ await bot.craft(plankRecipe, 1, null)
476
+ const stickRecipe = bot.recipesFor(mcData.itemsByName.sticks.id)[0]
477
+ await bot.craft(stickRecipe, 1, null)
478
+ bot.chat('Crafting Sticks finished')
479
+ }
488
480
  ```
489
481
 
490
482
  The reason the incorrect approach is wrong is because when `bot.craft()` is called, the code will continue below while the bot is crafting.
491
483
  By the time the code reaches the second `bot.craft()`, the first probably hasn't finished yet, which means the wanted resource is not available yet.
492
- Using callbacks can fix this because they will only be called after the `bot.craft()` is finished.
484
+ Using promises can fix this because they will only be called after the `bot.craft()` is finished.
493
485
 
494
- More on the [bot.craft()](https://mineflayer.prismarine.js.org/#/api?id=botcraftrecipe-count-craftingtable-callback) method.
486
+ More on the [bot.craft()](https://github.com/PrismarineJS/mineflayer/blob/master/docs/api.md#botcraftrecipe-count-craftingtable) method.
495
487
 
496
488
  ## Advanced
497
489
 
498
490
  The following concepts aren't necessary to create a Mineflayer bot, but they can be useful to understand and create more advanced bots.
499
491
  We assume you have understood the [Basics](#basics) tutorial.
500
492
 
501
- ### Asynchronousy
502
- In Javascript, asynchronousy is an important concept.
503
- By default, Javascript will run everything line by line, and only go to the next line if the current line is done. This is called blocking.
504
- However, sometimes you have to do something that takes a relatively long time, and you don't want your whole program to block and wait for it to finish.
505
-
506
- Interacting with the filesystem is often done using asynchronousy, because reading and writing large files can take a long time.
507
-
508
- ```js
509
- const myPromise = new Promise((resolve, reject) => {
510
- setTimeout(() => {
511
- resolve('Success!') // Yay! Everything went well!
512
- }, 1000)
513
- })
514
-
515
- myPromise.then((successMessage) => {
516
- console.log(successMessage)
517
- })
518
-
519
- myPromise.catch((error) => {
520
- console.log(error)
521
- })
522
- ```
523
-
524
- The above codes uses what is called a Promise. A promise promises it will eventually complete.
525
- The function given you a promise always has 2 parameters, a `resolve` function and a `reject` function.
526
- If the promise is successful, it will call the `resolve` function, otherwise it will call the `reject` function.
527
- The above code uses a `setTimeout`, which calls the given function after the set amount of milliseconds, 1000 in this case.
528
- You can then tell the promise what it should do when it succeeds with `.then(function)` or when it fails with `.catch(function)`
529
-
530
- The `.then` and `.catch` function can also be chained together with the promise to simplify the code.
531
-
532
- ```js
533
- const myPromise = new Promise((resolve, reject) => {
534
- setTimeout(() => {
535
- resolve('Success!') // Yay! Everything went well!
536
- }, 1000)
537
- }).then((successMessage) => {
538
- console.log(successMessage)
539
- }).catch((error) => {
540
- console.log(error)
541
- })
542
- ```
543
-
544
493
  ### Loop over an object
545
494
 
546
495
  The `for of` loop described in the [loops](#loops) chapter can also be used to loop over an object.
@@ -129,7 +129,7 @@ async function craftItem (name, amount) {
129
129
  amount = parseInt(amount, 10)
130
130
  const mcData = require('minecraft-data')(bot.version)
131
131
 
132
- const item = mcData.findItemOrBlockByName(name)
132
+ const item = mcData.itemsByName[name]
133
133
  const craftingTableID = mcData.blocksByName.crafting_table.id
134
134
 
135
135
  const craftingTable = bot.findBlock({
package/index.d.ts CHANGED
@@ -197,7 +197,7 @@ export interface Bot extends TypedEmitter<BotEvents> {
197
197
 
198
198
  end: (reason?: string) => void
199
199
 
200
- blockAt: (point: Vec3) => Block | null
200
+ blockAt: (point: Vec3, extraInfos?: boolean) => Block | null
201
201
 
202
202
  blockInSight: (maxSteps: number, vectorLength: number) => Block | null
203
203
 
@@ -294,7 +294,7 @@ export interface Bot extends TypedEmitter<BotEvents> {
294
294
 
295
295
  digTime: (block: Block) => number
296
296
 
297
- placeBlock: (referenceBlock: Block, faceVector: Vec3, cb?: () => void) => Promise<void>
297
+ placeBlock: (referenceBlock: Block, faceVector: Vec3) => Promise<void>
298
298
 
299
299
  placeEntity: (referenceBlock: Block, faceVector: Vec3) => Promise<Entity>
300
300
 
@@ -328,8 +328,8 @@ export interface Bot extends TypedEmitter<BotEvents> {
328
328
 
329
329
  craft: (
330
330
  recipe: Recipe,
331
- count: number | null,
332
- craftingTable: Block
331
+ count?: number,
332
+ craftingTable?: Block
333
333
  ) => Promise<void>
334
334
 
335
335
  writeBook: (
@@ -571,6 +571,10 @@ export interface creativeMethods {
571
571
  item: Item | null
572
572
  ) => Promise<void>
573
573
 
574
+ clearSlot: (slot: number) => Promise<void>
575
+
576
+ clearInventory: () => Promise<void>
577
+
574
578
  flyTo: (destination: Vec3) => Promise<void>
575
579
 
576
580
  startFlying: () => void
package/lib/bossbar.js CHANGED
@@ -5,7 +5,7 @@ const divisions = [0, 6, 10, 12, 20]
5
5
  module.exports = loader
6
6
 
7
7
  function loader (mcVersion) {
8
- ChatMessage = require('prismarine-chat')(mcVersion)
8
+ ChatMessage = require('prismarine-chat')(mcVersion) // TODO: update for prismarine-registry
9
9
  return BossBar
10
10
  }
11
11
 
package/lib/loader.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const mc = require('minecraft-protocol')
2
2
  const { EventEmitter } = require('events')
3
3
  const pluginLoader = require('./plugin_loader')
4
- const supportFeature = require('./supportFeature')
5
4
  const plugins = {
6
5
  bed: require('./plugins/bed'),
7
6
  title: require('./plugins/title'),
@@ -56,7 +55,7 @@ module.exports = {
56
55
  BossBar: require('./bossbar'),
57
56
  supportedVersions,
58
57
  testedVersions,
59
- supportFeature
58
+ supportFeature: (feature, version) => require('minecraft-data')(version).supportFeature(feature)
60
59
  }
61
60
 
62
61
  function createBot (options = {}) {
@@ -105,7 +104,8 @@ function createBot (options = {}) {
105
104
  if (!bot._client.wait_connect) next()
106
105
  else bot._client.once('connect_allowed', next)
107
106
  function next () {
108
- const version = require('minecraft-data')(bot._client.version).version
107
+ bot.registry = require('prismarine-registry')(bot._client.version)
108
+ const version = bot.registry.version
109
109
  if (supportedVersions.indexOf(version.majorVersion) === -1) {
110
110
  throw new Error(`Version ${version.minecraftVersion} is not supported.`)
111
111
  }
@@ -120,7 +120,7 @@ function createBot (options = {}) {
120
120
  bot.majorVersion = version.majorVersion
121
121
  bot.version = version.minecraftVersion
122
122
  options.version = version.minecraftVersion
123
- bot.supportFeature = feature => supportFeature(feature, version.minecraftVersion)
123
+ bot.supportFeature = bot.registry.supportFeature
124
124
  bot.emit('inject_allowed')
125
125
  }
126
126
  return bot
@@ -1,5 +1,5 @@
1
1
  const assert = require('assert')
2
- const { callbackify, sleep } = require('../promise_utils')
2
+ const { sleep } = require('../promise_utils')
3
3
  const { once } = require('events')
4
4
 
5
5
  module.exports = inject
@@ -105,11 +105,11 @@ function inject (bot) {
105
105
  await bot.transfer(options)
106
106
  }
107
107
 
108
- anvil.combine = callbackify(combine)
109
- anvil.rename = callbackify(rename)
108
+ anvil.combine = combine
109
+ anvil.rename = rename
110
110
 
111
111
  return anvil
112
112
  }
113
113
 
114
- bot.openAnvil = callbackify(openAnvil)
114
+ bot.openAnvil = openAnvil
115
115
  }
@@ -1,5 +1,4 @@
1
1
  const { Vec3 } = require('vec3')
2
- const { callbackify } = require('../promise_utils')
3
2
 
4
3
  module.exports = inject
5
4
 
@@ -7,7 +6,6 @@ const CARDINAL_DIRECTIONS = ['south', 'west', 'north', 'east']
7
6
 
8
7
  function inject (bot) {
9
8
  bot.isSleeping = false
10
- const mcData = require('minecraft-data')(bot.version)
11
9
 
12
10
  const beds = new Set(['white_bed', 'orange_bed', 'magenta_bed', 'light_blue_bed', 'yellow_bed', 'lime_bed', 'pink_bed', 'gray_bed',
13
11
  'light_gray_bed', 'cyan_bed', 'purple_bed', 'blue_bed', 'brown_bed', 'green_bed', 'red_bed', 'black_bed', 'bed'])
@@ -25,7 +23,7 @@ function inject (bot) {
25
23
  }
26
24
 
27
25
  if (bot.supportFeature('blockStateId')) {
28
- const state = bedBlock.stateId - mcData.blocksByStateId[bedBlock.stateId].minStateId
26
+ const state = bedBlock.stateId - bot.registry.blocksByStateId[bedBlock.stateId].minStateId
29
27
  const bitMetadata = state.toString(2).padStart(4, '0') // FACING (first 2 bits), PART (3rd bit), OCCUPIED (4th bit)
30
28
  metadata.part = bitMetadata[3] === '0'
31
29
  metadata.occupied = bitMetadata[2] === '0'
@@ -174,7 +172,7 @@ function inject (bot) {
174
172
  })
175
173
 
176
174
  bot.parseBedMetadata = parseBedMetadata
177
- bot.wake = callbackify(wake)
178
- bot.sleep = callbackify(sleep)
175
+ bot.wake = wake
176
+ bot.sleep = sleep
179
177
  bot.isABed = isABed
180
178
  }
@@ -16,8 +16,8 @@ const FACING_MAP = {
16
16
  east: { north: 'right', south: 'left' }
17
17
  }
18
18
 
19
- function inject (bot, { version }) {
20
- const { instruments, blocks } = require('minecraft-data')(version)
19
+ function inject (bot) {
20
+ const { instruments, blocks } = bot.registry
21
21
 
22
22
  // Stores how many players have currently open a container at a certain position
23
23
  const openCountByPos = {}
@@ -1,7 +1,7 @@
1
1
  const { Vec3 } = require('vec3')
2
2
  const assert = require('assert')
3
3
  const Painting = require('../painting')
4
- const { onceWithCleanup, callbackify } = require('../promise_utils')
4
+ const { onceWithCleanup } = require('../promise_utils')
5
5
 
6
6
  const { OctahedronIterator } = require('prismarine-world').iterators
7
7
 
@@ -548,7 +548,7 @@ function inject (bot, { version, storageBuilder }) {
548
548
  bot.canSeeBlock = canSeeBlock
549
549
  bot.blockAt = blockAt
550
550
  bot._updateBlockState = updateBlockState
551
- bot.waitForChunksToLoad = callbackify(waitForChunksToLoad)
551
+ bot.waitForChunksToLoad = waitForChunksToLoad
552
552
  }
553
553
 
554
554
  function onesInShort (n) {
@@ -1,12 +1,10 @@
1
1
  const assert = require('assert')
2
2
  const { once } = require('events')
3
- const { callbackify } = require('../promise_utils')
4
3
 
5
4
  module.exports = inject
6
5
 
7
- function inject (bot, { version }) {
8
- const mcData = require('minecraft-data')(version)
9
- const Item = require('prismarine-item')(version)
6
+ function inject (bot) {
7
+ const Item = require('prismarine-item')(bot.version)
10
8
 
11
9
  let editBook
12
10
  if (bot.supportFeature('editBookIsPluginChannel')) {
@@ -29,7 +27,7 @@ function inject (bot, { version }) {
29
27
  async function write (slot, pages, author, title, signing) {
30
28
  assert.ok(slot >= 0 && slot <= 44, 'slot out of inventory range')
31
29
  const book = bot.inventory.slots[slot]
32
- assert.ok(book && book.type === mcData.itemsByName.writable_book.id, `no book found in slot ${slot}`)
30
+ assert.ok(book && book.type === bot.registry.itemsByName.writable_book.id, `no book found in slot ${slot}`)
33
31
  const quickBarSlot = bot.quickBarSlot
34
32
  const moveToQuickBar = slot < 36
35
33
 
@@ -61,7 +59,7 @@ function inject (bot, { version }) {
61
59
  }
62
60
  if (signing) {
63
61
  if (bot.supportFeature('clientUpdateBookIdWhenSign')) {
64
- book.type = mcData.itemsByName.written_book.id
62
+ book.type = bot.registry.itemsByName.written_book.id
65
63
  }
66
64
  book.nbt.value.author = {
67
65
  type: 'string',
@@ -83,11 +81,11 @@ function inject (bot, { version }) {
83
81
  return book
84
82
  }
85
83
 
86
- bot.writeBook = callbackify(async (slot, pages) => {
84
+ bot.writeBook = async (slot, pages) => {
87
85
  await write(slot, pages, null, null, false)
88
- })
86
+ }
89
87
 
90
- bot.signBook = callbackify(async (slot, pages, author, title) => {
88
+ bot.signBook = async (slot, pages, author, title) => {
91
89
  await write(slot, pages, author, title, true)
92
- })
90
+ }
93
91
  }