mineflayer 3.16.0 → 3.17.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
@@ -2,11 +2,12 @@
2
2
 
3
3
  [![NPM version](https://badge.fury.io/js/mineflayer.svg)](https://www.npmjs.com/package/mineflayer)
4
4
  [![Build Status](https://github.com/PrismarineJS/mineflayer/workflows/CI/badge.svg)](https://github.com/PrismarineJS/mineflayer/actions?query=workflow%3A%22CI%22)
5
- [![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8)
6
5
  [![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/mineflayer)
7
6
  [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/PrismarineJS/mineflayer/blob/master/docs/mineflayer.ipynb)
8
7
  [![GitHub Sponsors](https://img.shields.io/github/sponsors/PrismarineJS)](https://github.com/sponsors/PrismarineJS)
9
8
 
9
+ [![Official Discord](https://user-images.githubusercontent.com/61137113/152664460-65e41506-098b-497c-8938-8f54f7a600cc.svg)](https://discord.gg/GsEFRM8)
10
+
10
11
  | <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) |
11
12
  |-------------------------|----------------------------|----------------------------|----------------------------|----------------------------|----------------------------|
12
13
 
package/docs/README.md CHANGED
@@ -2,11 +2,12 @@
2
2
 
3
3
  [![NPM version](https://badge.fury.io/js/mineflayer.svg)](https://www.npmjs.com/package/mineflayer)
4
4
  [![Build Status](https://github.com/PrismarineJS/mineflayer/workflows/CI/badge.svg)](https://github.com/PrismarineJS/mineflayer/actions?query=workflow%3A%22CI%22)
5
- [![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8)
6
5
  [![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/mineflayer)
7
6
  [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/PrismarineJS/mineflayer/blob/master/docs/mineflayer.ipynb)
8
7
  [![GitHub Sponsors](https://img.shields.io/github/sponsors/PrismarineJS)](https://github.com/sponsors/PrismarineJS)
9
8
 
9
+ [![Official Discord](https://user-images.githubusercontent.com/61137113/152664460-65e41506-098b-497c-8938-8f54f7a600cc.svg)](https://discord.gg/GsEFRM8)
10
+
10
11
  | <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) |
11
12
  |-------------------------|----------------------------|----------------------------|----------------------------|----------------------------|----------------------------|
12
13
 
package/docs/history.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 3.17.0
2
+
3
+ * callback are now depreciated with mineflayer. Any use of them will print a warning
4
+
1
5
  ## 3.16.0
2
6
 
3
7
  * Use prismarine-chunk for block entities
package/examples/anvil.js CHANGED
@@ -63,24 +63,22 @@ bot.on('chat', async (username, message) => {
63
63
  }
64
64
  })
65
65
 
66
- function tossItem (name, amount) {
66
+ async function tossItem (name, amount) {
67
67
  amount = parseInt(amount, 10)
68
68
  const item = itemByName(name)
69
69
  if (!item) {
70
70
  bot.chat(`I have no ${name}`)
71
- } else if (amount) {
72
- bot.toss(item.type, null, amount, checkIfTossed)
73
71
  } else {
74
- bot.tossStack(item, checkIfTossed)
75
- }
76
-
77
- function checkIfTossed (err) {
78
- if (err) {
72
+ try {
73
+ if (amount) {
74
+ await bot.toss(item.type, null, amount)
75
+ bot.chat(`tossed ${amount} x ${name}`)
76
+ } else {
77
+ await bot.tossStack(item)
78
+ bot.chat(`tossed ${name}`)
79
+ }
80
+ } catch (err) {
79
81
  bot.chat(`unable to toss: ${err.message}`)
80
- } else if (amount) {
81
- bot.chat(`tossed ${amount} x ${name}`)
82
- } else {
83
- bot.chat(`tossed ${name}`)
84
82
  }
85
83
  }
86
84
  }
package/examples/chest.js CHANGED
@@ -220,38 +220,36 @@ async function watchFurnace () {
220
220
  bot.removeListener('chat', onChat)
221
221
  }
222
222
 
223
- function putInFurnace (where, name, amount) {
223
+ async function putInFurnace (where, name, amount) {
224
224
  const item = itemByName(furnace.items(), name)
225
225
  if (item) {
226
226
  const fn = {
227
227
  input: furnace.putInput,
228
228
  fuel: furnace.putFuel
229
229
  }[where]
230
- fn.call(furnace, item.type, null, amount, (err) => {
231
- if (err) {
232
- bot.chat(`unable to put ${amount} ${item.name}`)
233
- } else {
234
- bot.chat(`put ${amount} ${item.name}`)
235
- }
236
- })
230
+ try {
231
+ await fn.call(furnace, item.type, null, amount)
232
+ bot.chat(`put ${amount} ${item.name}`)
233
+ } catch (err) {
234
+ bot.chat(`unable to put ${amount} ${item.name}`)
235
+ }
237
236
  } else {
238
237
  bot.chat(`unknown item ${name}`)
239
238
  }
240
239
  }
241
240
 
242
- function takeFromFurnace (what) {
241
+ async function takeFromFurnace (what) {
243
242
  const fn = {
244
243
  input: furnace.takeInput,
245
244
  fuel: furnace.takeFuel,
246
245
  output: furnace.takeOutput
247
246
  }[what]
248
- fn.call(furnace, (err, item) => {
249
- if (err) {
250
- bot.chat(`unable to take ${item.name}`)
251
- } else {
252
- bot.chat(`took ${item.name}`)
253
- }
254
- })
247
+ try {
248
+ const item = await fn.call(furnace)
249
+ bot.chat(`took ${item.name}`)
250
+ } catch (err) {
251
+ bot.chat('unable to take')
252
+ }
255
253
  }
256
254
  }
257
255
  }
@@ -56,7 +56,7 @@ function sayItems (items = bot.inventory.items()) {
56
56
  }
57
57
  }
58
58
 
59
- function dig () {
59
+ async function dig () {
60
60
  let target
61
61
  if (bot.targetDigBlock) {
62
62
  bot.chat(`already digging ${bot.targetDigBlock.name}`)
@@ -64,19 +64,16 @@ function dig () {
64
64
  target = bot.blockAt(bot.entity.position.offset(0, -1, 0))
65
65
  if (target && bot.canDigBlock(target)) {
66
66
  bot.chat(`starting to dig ${target.name}`)
67
- bot.dig(target, onDiggingCompleted)
67
+ try {
68
+ await bot.dig(target)
69
+ bot.chat(`finished digging ${target.name}`)
70
+ } catch (err) {
71
+ console.log(err.stack)
72
+ }
68
73
  } else {
69
74
  bot.chat('cannot dig')
70
75
  }
71
76
  }
72
-
73
- function onDiggingCompleted (err) {
74
- if (err) {
75
- console.log(err.stack)
76
- return
77
- }
78
- bot.chat(`finished digging ${target.name}`)
79
- }
80
77
  }
81
78
 
82
79
  function build () {
@@ -87,28 +84,26 @@ function build () {
87
84
 
88
85
  let tryCount = 0
89
86
 
90
- function placeIfHighEnough () {
87
+ async function placeIfHighEnough () {
91
88
  if (bot.entity.position.y > jumpY) {
92
- bot.placeBlock(referenceBlock, vec3(0, 1, 0), (err) => {
93
- if (err) {
94
- tryCount++
95
- if (tryCount > 10) {
96
- bot.chat(err.message)
97
- bot.setControlState('jump', false)
98
- bot.removeListener('move', placeIfHighEnough)
99
- return
100
- }
101
- return
102
- }
89
+ try {
90
+ await bot.placeBlock(referenceBlock, vec3(0, 1, 0))
103
91
  bot.setControlState('jump', false)
104
92
  bot.removeListener('move', placeIfHighEnough)
105
93
  bot.chat('Placing a block was successful')
106
- })
94
+ } catch (err) {
95
+ tryCount++
96
+ if (tryCount > 10) {
97
+ bot.chat(err.message)
98
+ bot.setControlState('jump', false)
99
+ bot.removeListener('move', placeIfHighEnough)
100
+ }
101
+ }
107
102
  }
108
103
  }
109
104
  }
110
105
 
111
- function equipDirt () {
106
+ async function equipDirt () {
112
107
  const mcData = require('minecraft-data')(bot.version)
113
108
  let itemsByName
114
109
  if (bot.supportFeature('itemsAreNotBlocks')) {
@@ -116,13 +111,12 @@ function equipDirt () {
116
111
  } else if (bot.supportFeature('itemsAreAlsoBlocks')) {
117
112
  itemsByName = 'blocksByName'
118
113
  }
119
- bot.equip(mcData[itemsByName].dirt.id, 'hand', (err) => {
120
- if (err) {
121
- bot.chat(`unable to equip dirt: ${err.message}`)
122
- } else {
123
- bot.chat('equipped dirt')
124
- }
125
- })
114
+ try {
115
+ await bot.equip(mcData[itemsByName].dirt.id, 'hand')
116
+ bot.chat('equipped dirt')
117
+ } catch (err) {
118
+ bot.chat(`unable to equip dirt: ${err.message}`)
119
+ }
126
120
  }
127
121
 
128
122
  function itemToString (item) {
@@ -77,24 +77,22 @@ function sayItems (items = null) {
77
77
  }
78
78
  }
79
79
 
80
- function tossItem (name, amount) {
80
+ async function tossItem (name, amount) {
81
81
  amount = parseInt(amount, 10)
82
82
  const item = itemByName(name)
83
83
  if (!item) {
84
84
  bot.chat(`I have no ${name}`)
85
- } else if (amount) {
86
- bot.toss(item.type, null, amount, checkIfTossed)
87
85
  } else {
88
- bot.tossStack(item, checkIfTossed)
89
- }
90
-
91
- function checkIfTossed (err) {
92
- if (err) {
86
+ try {
87
+ if (amount) {
88
+ await bot.toss(item.type, null, amount)
89
+ bot.chat(`tossed ${amount} x ${name}`)
90
+ } else {
91
+ await bot.tossStack(item)
92
+ bot.chat(`tossed ${name}`)
93
+ }
94
+ } catch (err) {
93
95
  bot.chat(`unable to toss: ${err.message}`)
94
- } else if (amount) {
95
- bot.chat(`tossed ${amount} x ${name}`)
96
- } else {
97
- bot.chat(`tossed ${name}`)
98
96
  }
99
97
  }
100
98
  }
@@ -1,4 +1,5 @@
1
1
  const { once } = require('events')
2
+ const { printCallbackDepreciation } = require('../promise_utils')
2
3
 
3
4
  module.exports = inject
4
5
 
@@ -198,6 +199,16 @@ function callbackify (f) { // specifically for this function because cb isn't th
198
199
  return function (...args) {
199
200
  const cb = args[1]
200
201
  args.splice(1, 1)
201
- return f(...args).then(r => { if (cb) { cb(undefined, r) } return r }, err => { if (cb) { cb(err) } else throw err })
202
+ return f(...args).then(r => {
203
+ if (cb) {
204
+ printCallbackDepreciation()
205
+ cb(undefined, r)
206
+ } return r
207
+ }, err => {
208
+ if (cb) {
209
+ printCallbackDepreciation()
210
+ cb(err)
211
+ } else throw err
212
+ })
202
213
  }
203
214
  }
@@ -1,5 +1,5 @@
1
1
  const { performance } = require('perf_hooks')
2
- const { createDoneTask, createTask } = require('../promise_utils')
2
+ const { createDoneTask, createTask, printCallbackDepreciation } = require('../promise_utils')
3
3
  const BlockFaces = require('prismarine-world').iterators.BlockFace
4
4
  const { Vec3 } = require('vec3')
5
5
 
@@ -213,7 +213,17 @@ function callbackify (f) { // specifically for this function because cb could be
213
213
  else if (typeof args[1] === 'string') args[1] = args[1] === 'ignore' ? args[1] : false
214
214
  else args[1] = !!args[1] // coerce to boolean
215
215
 
216
- return f(...args).then(r => { if (cb) { cb(undefined, r) } return r }, err => { if (cb) { cb(err) } else throw err })
216
+ return f(...args).then(r => {
217
+ if (cb) {
218
+ printCallbackDepreciation()
219
+ cb(undefined, r)
220
+ } return r
221
+ }, err => {
222
+ if (cb) {
223
+ printCallbackDepreciation()
224
+ cb(err)
225
+ } else throw err
226
+ })
217
227
  }
218
228
  }
219
229
 
@@ -1,10 +1,22 @@
1
+ function printCallbackDepreciation () {
2
+ console.log('[depreciation notice] Callback are deprecated with mineflayer, use promise instead. They will be removed in version 4.0.0.')
3
+ }
4
+
1
5
  function callbackify (f) {
2
6
  return function (...args) {
3
7
  const cb = args[f.length]
4
8
  return f(...args).then(r => {
5
- if (cb) { cb(undefined, r) }
9
+ if (cb) {
10
+ printCallbackDepreciation()
11
+ cb(undefined, r)
12
+ }
6
13
  return r
7
- }, err => { if (cb) { cb(err) } else throw err })
14
+ }, err => {
15
+ if (cb) {
16
+ printCallbackDepreciation()
17
+ cb(err)
18
+ } else throw err
19
+ })
8
20
  }
9
21
  }
10
22
 
@@ -97,5 +109,6 @@ module.exports = {
97
109
  createTask,
98
110
  createDoneTask,
99
111
  onceWithCleanup,
100
- withTimeout
112
+ withTimeout,
113
+ printCallbackDepreciation
101
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mineflayer",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "create minecraft bots with a stable, high level API",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",