mineflayer 3.14.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.
@@ -21,17 +21,12 @@ const dimensionNames = {
21
21
  }
22
22
 
23
23
  function inject (bot, { version, storageBuilder }) {
24
- const nbt = require('prismarine-nbt')
25
24
  const Block = require('prismarine-block')(version)
26
25
  const Chunk = require('prismarine-chunk')(version)
27
- const ChatMessage = require('prismarine-chat')(version)
28
26
  const World = require('prismarine-world')(version)
29
- const signs = {}
30
27
  const paintingsByPos = {}
31
28
  const paintingsById = {}
32
29
 
33
- const blockEntities = new Map()
34
-
35
30
  function addPainting (painting) {
36
31
  paintingsById[painting.id] = painting
37
32
  paintingsByPos[painting.position] = painting
@@ -42,41 +37,6 @@ function inject (bot, { version, storageBuilder }) {
42
37
  delete paintingsByPos[painting.position]
43
38
  }
44
39
 
45
- function addBlockEntity (nbtData) {
46
- const blockEntity = nbt.simplify(nbtData)
47
- const pos = new Vec3(blockEntity.x, blockEntity.y, blockEntity.z).floored()
48
- // Set raw nbt of blockEntity
49
- blockEntity.raw = nbtData
50
- // Handle signs
51
- if (blockEntity.id === 'minecraft:sign' || blockEntity.id === 'Sign') {
52
- const prepareJson = (i) => {
53
- const data = blockEntity[`Text${i}`]
54
-
55
- if (data === null || data === '') return ''
56
-
57
- const json = JSON.parse(data)
58
- if (json === null || !('text' in json)) return ''
59
-
60
- json.text = json.text.replace(/^"|"$/g, '')
61
- return json
62
- }
63
-
64
- blockEntity.Text1 = new ChatMessage(prepareJson(1))
65
- blockEntity.Text2 = new ChatMessage(prepareJson(2))
66
- blockEntity.Text3 = new ChatMessage(prepareJson(3))
67
- blockEntity.Text4 = new ChatMessage(prepareJson(4))
68
-
69
- signs[pos] = [
70
- blockEntity.Text1.toString(),
71
- blockEntity.Text2.toString(),
72
- blockEntity.Text3.toString(),
73
- blockEntity.Text4.toString()
74
- ].join('\n')
75
- }
76
-
77
- blockEntities[pos] = blockEntity
78
- }
79
-
80
40
  function delColumn (chunkX, chunkZ) {
81
41
  bot.world.unloadColumn(chunkX, chunkZ)
82
42
  }
@@ -90,11 +50,7 @@ function inject (bot, { version, storageBuilder }) {
90
50
  let column = bot.world.getColumn(args.x, args.z)
91
51
  if (!column) {
92
52
  // Allocates new chunk object while taking world's custom min/max height into account
93
- if (bot.supportFeature('dimensionDataIsAvailable')) {
94
- column = new Chunk({ minY: bot.game.dimensionData.min_y, worldHeight: bot.game.dimensionData.height })
95
- } else {
96
- column = new Chunk()
97
- }
53
+ column = new Chunk({ minY: bot.game.minY, worldHeight: bot.game.height })
98
54
  }
99
55
 
100
56
  try {
@@ -102,6 +58,9 @@ function inject (bot, { version, storageBuilder }) {
102
58
  if (args.biomes !== undefined) {
103
59
  column.loadBiomes(args.biomes)
104
60
  }
61
+ if (args.skyLight !== undefined) {
62
+ column.loadParsedLight(args.skyLight, args.blockLight, args.skyLightMask, args.blockLightMask, args.emptySkyLightMask, args.emptyBlockLightMask)
63
+ }
105
64
  bot.world.setColumn(args.x, args.z, column)
106
65
  } catch (e) {
107
66
  bot.emit('error', e)
@@ -206,13 +165,17 @@ function inject (bot, { version, storageBuilder }) {
206
165
  let next = start
207
166
  while (next) {
208
167
  const column = bot.world.getColumn(next.x, next.z)
209
- if (next.y >= 0 && next.y < 16 && column && !visitedSections.has(next.toString())) {
210
- const section = column.sections[next.y]
168
+ const sectionY = next.y + Math.abs(bot.game.minY >> 4)
169
+ const totalSections = bot.game.height >> 4
170
+ if (sectionY >= 0 && sectionY < totalSections && column && !visitedSections.has(next.toString())) {
171
+ const section = column.sections[sectionY]
211
172
  if (useExtraInfo === true || isBlockInSection(section, matcher)) {
212
- const cursor = new Vec3(0, 0, 0)
213
- for (cursor.x = next.x * 16; cursor.x < next.x * 16 + 16; cursor.x++) {
214
- for (cursor.y = next.y * 16; cursor.y < next.y * 16 + 16; cursor.y++) {
215
- for (cursor.z = next.z * 16; cursor.z < next.z * 16 + 16; cursor.z++) {
173
+ const begin = new Vec3(next.x * 16, sectionY * 16 + bot.game.minY, next.z * 16)
174
+ const cursor = begin.clone()
175
+ const end = cursor.offset(16, 16, 16)
176
+ for (cursor.x = begin.x; cursor.x < end.x; cursor.x++) {
177
+ for (cursor.y = begin.y; cursor.y < end.y; cursor.y++) {
178
+ for (cursor.z = begin.z; cursor.z < end.z; cursor.z++) {
216
179
  if (fullMatcher(cursor) && cursor.distanceTo(point) <= maxDistance) blocks.push(cursor.clone())
217
180
  }
218
181
  }
@@ -249,9 +212,7 @@ function inject (bot, { version, storageBuilder }) {
249
212
  if (!block) return null
250
213
 
251
214
  if (extraInfos) {
252
- block.signText = signs[block.position]
253
215
  block.painting = paintingsByPos[block.position]
254
- block.blockEntity = blockEntities[block.position]
255
216
  }
256
217
 
257
218
  return block
@@ -288,9 +249,6 @@ function inject (bot, { version, storageBuilder }) {
288
249
  }
289
250
  if (oldBlock.type !== newBlock.type) {
290
251
  const pos = point.floored()
291
- delete blockEntities[pos]
292
- delete signs[pos]
293
-
294
252
  const painting = paintingsByPos[pos]
295
253
  if (painting) deletePainting(painting)
296
254
  }
@@ -299,11 +257,7 @@ function inject (bot, { version, storageBuilder }) {
299
257
  bot._client.on('update_light', (packet) => {
300
258
  let column = bot.world.getColumn(packet.chunkX, packet.chunkZ)
301
259
  if (!column) {
302
- if (bot.supportFeature('dimensionDataIsAvailable')) {
303
- column = new Chunk({ minY: bot.game.dimensionData.min_y, worldHeight: bot.game.dimensionData.height })
304
- } else {
305
- column = new Chunk()
306
- }
260
+ column = new Chunk({ minY: bot.game.minY, worldHeight: bot.game.height })
307
261
  bot.world.setColumn(packet.chunkX, packet.chunkZ, column)
308
262
  }
309
263
 
@@ -323,12 +277,25 @@ function inject (bot, { version, storageBuilder }) {
323
277
  biomes: packet.biomes,
324
278
  skyLightSent: bot.game.dimension === 'minecraft:overworld',
325
279
  groundUp: packet.groundUp,
326
- data: packet.chunkData
280
+ data: packet.chunkData,
281
+ trustEdges: packet.trustEdges,
282
+ skyLightMask: packet.skyLightMask,
283
+ blockLightMask: packet.blockLightMask,
284
+ emptySkyLightMask: packet.emptySkyLightMask,
285
+ emptyBlockLightMask: packet.emptyBlockLightMask,
286
+ skyLight: packet.skyLight,
287
+ blockLight: packet.blockLight
327
288
  })
328
289
 
329
290
  if (typeof packet.blockEntities !== 'undefined') {
330
- for (const nbtData of packet.blockEntities) {
331
- addBlockEntity(nbtData)
291
+ const column = bot.world.getColumn(packet.x, packet.z)
292
+ for (const blockEntity of packet.blockEntities) {
293
+ if (blockEntity.x !== undefined) { // 1.17+
294
+ column.setBlockEntity(blockEntity, blockEntity.nbtData)
295
+ } else {
296
+ const pos = new Vec3(blockEntity.value.x.value & 0xf, blockEntity.value.y.value, blockEntity.value.z.value & 0xf)
297
+ column.setBlockEntity(pos, blockEntity)
298
+ }
332
299
  }
333
300
  }
334
301
  })
@@ -422,33 +389,34 @@ function inject (bot, { version, storageBuilder }) {
422
389
  })
423
390
 
424
391
  bot._client.on('update_sign', (packet) => {
425
- const pos = new Vec3(packet.location.x, packet.location.y, packet.location.z)
426
-
427
- const prepareString = (i) => {
428
- let text = packet[`text${i}`]
429
-
430
- if (text === 'null' || text === '') {
431
- text = '""'
432
- }
392
+ const pos = new Vec3(packet.location.x & 0xf, packet.location.y, packet.location.z & 0xf)
433
393
 
434
- const json = JSON.parse(text)
435
- if (json.text) {
436
- json.text = json.text.replace(/^"|"$/g, '')
437
- }
438
-
439
- return new ChatMessage(json)
394
+ // TODO: warn if out of loaded world?
395
+ const column = bot.world.getColumn(packet.location.x >> 4, packet.location.z >> 4)
396
+ if (!column) {
397
+ return
440
398
  }
441
399
 
442
- signs[pos] = [
443
- prepareString(1),
444
- prepareString(2),
445
- prepareString(3),
446
- prepareString(4)
447
- ].join('\n')
400
+ const blockAt = column.getBlock(pos)
401
+
402
+ blockAt.signText = [packet.text1, packet.text2, packet.text3, packet.text4].map(text => {
403
+ if (text === 'null' || text === '') return ''
404
+ return JSON.parse(text)
405
+ })
406
+ column.setBlock(pos, blockAt)
448
407
  })
449
408
 
450
409
  bot._client.on('tile_entity_data', (packet) => {
451
- addBlockEntity(packet.nbtData)
410
+ if (packet.location !== undefined) {
411
+ const column = bot.world.getColumn(packet.location.x >> 4, packet.location.z >> 4)
412
+ const pos = new Vec3(packet.location.x & 0xf, packet.location.y, packet.location.z & 0xf)
413
+ column.setBlockEntity(pos, packet.nbtData)
414
+ } else {
415
+ const tag = packet.nbtData
416
+ const column = bot.world.getColumn(tag.value.x.value >> 4, tag.value.z.value >> 4)
417
+ const pos = new Vec3(tag.value.x.value & 0xf, tag.value.y.value, tag.value.z.value & 0xf)
418
+ column.setBlockEntity(pos, tag)
419
+ }
452
420
  })
453
421
 
454
422
  bot.updateSign = (block, text) => {
@@ -464,12 +432,25 @@ function inject (bot, { version, storageBuilder }) {
464
432
  }
465
433
  }
466
434
 
435
+ let signData
436
+ if (bot.supportFeature('sendStringifiedSignText')) {
437
+ signData = {
438
+ text1: lines[0] ? JSON.stringify(lines[0]) : '""',
439
+ text2: lines[1] ? JSON.stringify(lines[1]) : '""',
440
+ text3: lines[2] ? JSON.stringify(lines[2]) : '""',
441
+ text4: lines[3] ? JSON.stringify(lines[3]) : '""'
442
+ }
443
+ } else {
444
+ signData = {
445
+ text1: lines[0] ?? '',
446
+ text2: lines[1] ?? '',
447
+ text3: lines[2] ?? '',
448
+ text4: lines[3] ?? ''
449
+ }
450
+ }
467
451
  bot._client.write('update_sign', {
468
452
  location: block.position,
469
- text1: JSON.stringify(lines[0]),
470
- text2: JSON.stringify(lines[1]),
471
- text3: JSON.stringify(lines[2]),
472
- text4: JSON.stringify(lines[3])
453
+ ...signData
473
454
  })
474
455
  }
475
456
 
@@ -567,7 +548,6 @@ function inject (bot, { version, storageBuilder }) {
567
548
  bot.canSeeBlock = canSeeBlock
568
549
  bot.blockAt = blockAt
569
550
  bot._updateBlockState = updateBlockState
570
- bot._blockEntities = blockEntities
571
551
  bot.waitForChunksToLoad = callbackify(waitForChunksToLoad)
572
552
  }
573
553
 
@@ -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
 
@@ -548,11 +548,18 @@ function inject (bot, { version }) {
548
548
  }
549
549
 
550
550
  function attack (target, swing = true) {
551
- // arm animation comes before the use_entity packet
552
- if (swing) {
553
- swingArm()
551
+ // arm animation comes before the use_entity packet on 1.8
552
+ if (bot.supportFeature('armAnimationBeforeUse')) {
553
+ if (swing) {
554
+ swingArm()
555
+ }
556
+ useEntity(target, 1)
557
+ } else {
558
+ useEntity(target, 1)
559
+ if (swing) {
560
+ swingArm()
561
+ }
554
562
  }
555
- useEntity(target, 1)
556
563
  }
557
564
 
558
565
  function mount (target) {
@@ -37,7 +37,12 @@ function inject (bot, options) {
37
37
  }
38
38
 
39
39
  if (bot.supportFeature('dimensionDataIsAvailable')) {
40
- bot.game.dimensionData = nbt.simplify(packet.dimension)
40
+ const dimensionData = nbt.simplify(packet.dimension)
41
+ bot.game.minY = dimensionData.min_y
42
+ bot.game.height = dimensionData.height
43
+ } else {
44
+ bot.game.minY = 0
45
+ bot.game.height = 256
41
46
  }
42
47
  if (packet.difficulty) {
43
48
  bot.game.difficulty = difficultyNames[packet.difficulty]
@@ -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/lib/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  module.exports = {
2
- supportedVersions: ['1.8', '1.9', '1.10', '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17'],
3
- 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']
2
+ supportedVersions: ['1.8', '1.9', '1.10', '1.11', '1.12', '1.13', '1.14', '1.15', '1.16', '1.17', '1.18'],
3
+ 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.1']
4
4
  } // when updating testedVersions, make sure to update CI.yml
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mineflayer",
3
- "version": "3.14.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",
@@ -21,12 +21,12 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "minecraft-data": "^2.95.0",
24
+ "minecraft-data": "^2.109.0",
25
25
  "minecraft-protocol": "^1.26.5",
26
26
  "prismarine-biome": "^1.1.1",
27
- "prismarine-block": "^1.10.3",
27
+ "prismarine-block": "^1.13.1",
28
28
  "prismarine-chat": "^1.3.3",
29
- "prismarine-chunk": "^1.26.0",
29
+ "prismarine-chunk": "^1.29.0",
30
30
  "prismarine-entity": "^2.0.0",
31
31
  "prismarine-item": "^1.11.0",
32
32
  "prismarine-nbt": "^2.0.0",
@@ -35,7 +35,7 @@
35
35
  "prismarine-windows": "^2.4.2",
36
36
  "prismarine-world": "^3.6.0",
37
37
  "protodef": "^1.14.0",
38
- "typed-emitter": "^1.3.1",
38
+ "typed-emitter": "^1.0.0",
39
39
  "vec3": "^0.1.7"
40
40
  },
41
41
  "devDependencies": {