mineflayer 3.15.0 → 3.16.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
@@ -16,7 +16,7 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md)
16
16
 
17
17
  ## Features
18
18
 
19
- * 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.
19
+ * 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
20
  * Entity knowledge and tracking.
21
21
  * Block knowledge. You can query the world around you. Milliseconds to find any block.
22
22
  * Physics and movement - handle all bounding boxes
package/docs/FAQ.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  This Frequently Asked Question document is meant to help people for the most common things.
4
4
 
5
+ ### I get an error when trying to login with a microsoft account.
6
+
7
+ Make sure the email you entered into the username option in createBot can be used to login to `minecraft.net` using the 'Login with Microsoft' button.
8
+ Make sure you have the option `auth: 'microsoft'` in your createBot options.
9
+
10
+ When you get an error that says something about invalid credentials or 'Does this account own Minecraft?' try removing the password field in the `createBot` options and try again.
11
+
5
12
  ### How to hide errors ?
6
13
 
7
14
  Use `hideErrors: true` in createBot options
@@ -119,7 +126,7 @@ Note that the order in which plugins are loaded is dynamic, so you should never
119
126
 
120
127
  ### How can I use a socks5 proxy?
121
128
 
122
- In the options object for `mineflayer.createBot(options)`, remove your `host` option from the options object, have the following variables declared `PROXY_IP, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWORD, MC_SERVER_IP, MC_SERVER_PORT` and add this to your options object:
129
+ In the options object for `mineflayer.createBot(options)`, remove your `host` option from the options object, have the following variables declared `PROXY_IP, PROXY_PORT, PROXY_USERNAME, PROXY_PASSWORD, MC_SERVER_ADDRESS, MC_SERVER_PORT` and add this to your options object:
123
130
  ```js
124
131
  connect: (client) => {
125
132
  socks.createConnection({
@@ -132,7 +139,7 @@ connect: (client) => {
132
139
  },
133
140
  command: 'connect',
134
141
  destination: {
135
- host: MC_SERVER_IP,
142
+ host: MC_SERVER_ADDRESS,
136
143
  port: MC_SERVER_PORT
137
144
  }
138
145
  }, (err, info) => {
@@ -146,6 +153,7 @@ connect: (client) => {
146
153
  }
147
154
  ```
148
155
  `socks` is declared with `const socks = require('socks').SocksClient` and uses [this](https://www.npmjs.com/package/socks) package.
156
+ Some servers might reject the connection. If that happens try adding `fakeHost: MC_SERVER_ADDRESS` to your createBot options.
149
157
 
150
158
  # Common Errors
151
159
 
package/docs/README.md CHANGED
@@ -16,7 +16,7 @@ First time using Node.js? You may want to start with the [tutorial](tutorial.md)
16
16
 
17
17
  ## Features
18
18
 
19
- * 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.
19
+ * 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
20
  * Entity knowledge and tracking.
21
21
  * Block knowledge. You can query the world around you. Milliseconds to find any block.
22
22
  * Physics and movement - handle all bounding boxes
package/docs/history.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 3.16.0
2
+
3
+ * Use prismarine-chunk for block entities
4
+
1
5
  ## 3.15.0
2
6
 
3
7
  * Supports 1.18
@@ -10,27 +10,26 @@
10
10
  [![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/mineflayer)
11
11
  [![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)
12
12
 
13
- | <sub>EN</sub> [英语](../README.md) | <sub>RU</sub> [俄语](../ru/README_RU.md) | <sub>ES</sub> [西班牙语](../es/README_ES.md) | <sub>FR</sub> [法语](../fr/README_FR.md) | <sub>TR</sub> [土耳其语](../tr/README_TR.md) | <sub>ZH</sub> [中文](README_ZH_CN.md) |
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) |
14
14
  |-------------------------|----------------------------|----------------------------|----------------------------|----------------------------|----------------------------|
15
15
 
16
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
 
22
- * 支持版本:Minecraft 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15 1.16 1.17
23
- * 实体感知与追踪
24
- * 方块感知,你可以在几毫秒内查找到bot周围的任何方块
25
- * 物理和运动引擎 - 支持所有的碰撞箱
26
- * 攻击实体,使用运载工具
27
- * 背包管理
28
- * 使用工作台、箱子、酿造台、附魔台
29
- * 挖掘和建造
30
- * 各种各样的的信息接口,比如查看bot的血量和是否下雨
31
- * 激活方块和使用物品
32
- * 输入输出聊天信息
33
-
22
+ * 支持版本:Minecraft 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15 1.16 1.17,1.18
23
+ * 实体感知与追踪
24
+ * 方块感知,你可以在几毫秒内查找到bot周围的任何方块
25
+ * 物理和运动引擎 - 支持所有的碰撞箱
26
+ * 攻击实体,使用交通工具
27
+ * 背包管理
28
+ * 使用工作台、箱子、酿造台、附魔台
29
+ * 挖掘和建造
30
+ * 各种各样的的信息接口,比如查看你的血量或是否下雨
31
+ * 激活方块和使用物品
32
+ * 进行聊天
34
33
  ### 路线图
35
34
 
36
35
  [点这里](https://github.com/PrismarineJS/mineflayer/wiki/Big-Prismarine-projects) 看看目前我们有哪些实用的项目
@@ -178,7 +177,7 @@ node your_script.js
178
177
 
179
178
  ## 第三方插件
180
179
 
181
- Mineflayer 是可插拔的;任何人都可以创建一个插件,在 Mineflayer 之上添加更高级别的 API。
180
+ Mineflayer 支持插件;任何人都可以创建一个插件,在 Mineflayer 之上添加更高级别的 API。
182
181
 
183
182
  最新和最有用的有:
184
183
 
@@ -191,8 +190,12 @@ Mineflayer 是可插拔的;任何人都可以创建一个插件,在 Mineflay
191
190
  * [Dashboard](https://github.com/wvffle/mineflayer-dashboard) - mineflayer bot 的前端仪表板
192
191
  * [PVP](https://github.com/TheDudeFromCI/mineflayer-pvp) - 用于基本 PVP 和 PVE 的简单 API
193
192
  * [auto-eat](https://github.com/LINKdiscordd/mineflayer-auto-eat) - 自动进食
194
- * [Tool](https://github.com/TheDudeFromCI/mineflayer-tool) - 具有高级 API 的自动工具/武器选择实用程序
195
- * [Hawkeye](https://github.com/sefirosweb/minecraftHawkEye) - 使用弓箭自动瞄准的实用程序
193
+ * [Auto Crystal](https://github.com/link-discord/mineflayer-autocrystal) - 自动放置和破碎结
194
+ * [Tool](https://github.com/TheDudeFromCI/mineflayer-tool) - 一个具有高级API的工具/武器自动选择工具的工具
195
+ * [Hawkeye](https://github.com/sefirosweb/minecraftHawkEye) - 一个使用自动瞄准弓的工具
196
+ * [GUI](https://github.com/firejoust/mineflayer-GUI) - 简化了嵌套箱子GUI窗口的导航和管理
197
+ * [Projectile](https://github.com/firejoust/mineflayer-projectile) - 以投射物为基础的战斗的可配置插件
198
+
196
199
 
197
200
  也可以看看这些 :
198
201
 
@@ -203,13 +206,14 @@ Mineflayer 是可插拔的;任何人都可以创建一个插件,在 Mineflay
203
206
  * [Bloodhound](https://github.com/Nixes/mineflayer-bloodhound) - 确定谁和什么对另一个实体的损害负责
204
207
  * [tps](https://github.com/SiebeDW/mineflayer-tps) - 获取当前的 tps(已处理的 tps)
205
208
  * [panorama](https://github.com/IceTank/mineflayer-panorama) - 拍摄您的世界的全景图像
209
+ * [player-death-event](https://github.com/tuanzisama/mineflayer-death-event) - 在Mineflayer里监听玩家死亡事件
206
210
 
207
211
  ## 正在使用 Mineflayer 的项目
208
212
 
209
213
  * [rom1504/rbot](https://github.com/rom1504/rbot)
210
- * [YouTube - building a spiral staircase](https://www.youtube.com/watch?v=UM1ZV5200S0)
211
- * [YouTube - replicating a building](https://www.youtube.com/watch?v=0cQxg9uDnzA)
212
- * [Darthfett/Helperbot](https://github.com/Darthfett/Helperbot)
214
+ * [YouTube - 建造旋转楼梯](https://www.youtube.com/watch?v=UM1ZV5200S0)
215
+ * [YouTube - 复制一个建筑](https://www.youtube.com/watch?v=0cQxg9uDnzA)
216
+ * [Darthfett/Helperbot](https://github.com/Darthfett/Helperbot) - 完成一些简单指令
213
217
  * [vogonistic/voxel](https://github.com/vogonistic/mineflayer-voxel) - 使用 voxel.js 可视化机器人正在做什么
214
218
  * [JonnyD/Skynet](https://github.com/JonnyD/Skynet) - 将玩家活动记录到在线 API 上
215
219
  * [MinecraftChat](https://github.com/rom1504/MinecraftChat) (最后一个开源版本,由 AlexKvazos 构建)——基于 Minecraft 网络的聊天客户端 <https://minecraftchat.net/>
@@ -233,6 +237,9 @@ Mineflayer 是可插拔的;任何人都可以创建一个插件,在 Mineflay
233
237
 
234
238
  运行 `npm mocha_test -- -g <test_name>`,其中 `<test_name>` 是测试名称,例如 `bed`, `useChests`, `rayTrace`...
235
239
 
240
+ ### 示例
241
+
242
+ `npm run mocha_test -- -g "1.18.1.*BlockFinder"` 进行1.18.1寻路测试
236
243
  ## 许可证
237
244
 
238
245
  [MIT](../LICENSE)
package/index.d.ts CHANGED
@@ -189,6 +189,7 @@ export interface Bot extends TypedEmitter<BotEvents> {
189
189
  heldItem: Item | null
190
190
  currentWindow: Window | null
191
191
  simpleClick: simpleClick
192
+ tablist: Tablist
192
193
 
193
194
  connect: (options: BotOptions) => void
194
195
 
@@ -427,6 +428,11 @@ export interface simpleClick {
427
428
  rightMouse: (slot: number) => Promise<void>
428
429
  }
429
430
 
431
+ export interface Tablist {
432
+ header: ChatMessage
433
+ footer: ChatMessage
434
+ }
435
+
430
436
  export interface chatPatternOptions {
431
437
  repeat: boolean
432
438
  parse: boolean
@@ -796,7 +802,7 @@ export class Team {
796
802
 
797
803
  update (name: string, friendlyFire: boolean, nameTagVisibility: string, collisionRule: string, formatting: number, prefix: string, suffix: string): void;
798
804
 
799
- displayName (member: string);
805
+ displayName (member: string): ChatMessage;
800
806
  }
801
807
 
802
808
  export type DisplaySlot =
package/lib/features.json CHANGED
@@ -328,5 +328,10 @@
328
328
  "name": "tallWorld",
329
329
  "description": "world starts at -64 and ends at 384",
330
330
  "versions": ["1.18", "1.18.1"]
331
+ },
332
+ {
333
+ "name": "sendStringifiedSignText",
334
+ "description": "sign text send when updating signs is send as stringified strings",
335
+ "versions": ["1.8", "1.8.9"]
331
336
  }
332
337
  ]
@@ -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,43 +37,6 @@ function inject (bot, { version, storageBuilder }) {
42
37
  delete paintingsByPos[painting.position]
43
38
  }
44
39
 
45
- function addBlockEntity (nbtData, x, y, z, type) {
46
- const blockEntity = nbtData === undefined ? {} : nbt.simplify(nbtData)
47
- const pos = (x !== undefined ? new Vec3(x, y, z) : new Vec3(blockEntity.x, blockEntity.y, blockEntity.z)).floored()
48
- // Set raw nbt of blockEntity
49
- blockEntity.raw = nbtData
50
- blockEntity.type = type
51
- const signType = 7
52
- // Handle signs
53
- if (blockEntity.id === 'minecraft:sign' || blockEntity.id === 'Sign' || blockEntity.type === signType) {
54
- const prepareJson = (i) => {
55
- const data = blockEntity[`Text${i}`]
56
-
57
- if (data === null || data === '') return ''
58
-
59
- const json = JSON.parse(data)
60
- if (json === null || !('text' in json)) return ''
61
-
62
- json.text = json.text.replace(/^"|"$/g, '')
63
- return json
64
- }
65
-
66
- blockEntity.Text1 = new ChatMessage(prepareJson(1))
67
- blockEntity.Text2 = new ChatMessage(prepareJson(2))
68
- blockEntity.Text3 = new ChatMessage(prepareJson(3))
69
- blockEntity.Text4 = new ChatMessage(prepareJson(4))
70
-
71
- signs[pos] = [
72
- blockEntity.Text1.toString(),
73
- blockEntity.Text2.toString(),
74
- blockEntity.Text3.toString(),
75
- blockEntity.Text4.toString()
76
- ].join('\n')
77
- }
78
-
79
- blockEntities[pos] = blockEntity
80
- }
81
-
82
40
  function delColumn (chunkX, chunkZ) {
83
41
  bot.world.unloadColumn(chunkX, chunkZ)
84
42
  }
@@ -254,9 +212,7 @@ function inject (bot, { version, storageBuilder }) {
254
212
  if (!block) return null
255
213
 
256
214
  if (extraInfos) {
257
- block.signText = signs[block.position]
258
215
  block.painting = paintingsByPos[block.position]
259
- block.blockEntity = blockEntities[block.position]
260
216
  }
261
217
 
262
218
  return block
@@ -293,9 +249,6 @@ function inject (bot, { version, storageBuilder }) {
293
249
  }
294
250
  if (oldBlock.type !== newBlock.type) {
295
251
  const pos = point.floored()
296
- delete blockEntities[pos]
297
- delete signs[pos]
298
-
299
252
  const painting = paintingsByPos[pos]
300
253
  if (painting) deletePainting(painting)
301
254
  }
@@ -335,11 +288,13 @@ function inject (bot, { version, storageBuilder }) {
335
288
  })
336
289
 
337
290
  if (typeof packet.blockEntities !== 'undefined') {
291
+ const column = bot.world.getColumn(packet.x, packet.z)
338
292
  for (const blockEntity of packet.blockEntities) {
339
- if (blockEntity.x !== undefined) {
340
- addBlockEntity(blockEntity.nbtData, blockEntity.x, blockEntity.y, blockEntity.z, blockEntity.type)
293
+ if (blockEntity.x !== undefined) { // 1.17+
294
+ column.setBlockEntity(blockEntity, blockEntity.nbtData)
341
295
  } else {
342
- addBlockEntity(blockEntity)
296
+ const pos = new Vec3(blockEntity.value.x.value & 0xf, blockEntity.value.y.value, blockEntity.value.z.value & 0xf)
297
+ column.setBlockEntity(pos, blockEntity)
343
298
  }
344
299
  }
345
300
  }
@@ -434,36 +389,33 @@ function inject (bot, { version, storageBuilder }) {
434
389
  })
435
390
 
436
391
  bot._client.on('update_sign', (packet) => {
437
- const pos = new Vec3(packet.location.x, packet.location.y, packet.location.z)
438
-
439
- const prepareString = (i) => {
440
- let text = packet[`text${i}`]
392
+ const pos = new Vec3(packet.location.x & 0xf, packet.location.y, packet.location.z & 0xf)
441
393
 
442
- if (text === 'null' || text === '') {
443
- text = '""'
444
- }
445
-
446
- const json = JSON.parse(text)
447
- if (json.text) {
448
- json.text = json.text.replace(/^"|"$/g, '')
449
- }
450
-
451
- 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
452
398
  }
453
399
 
454
- signs[pos] = [
455
- prepareString(1),
456
- prepareString(2),
457
- prepareString(3),
458
- prepareString(4)
459
- ].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)
460
407
  })
461
408
 
462
409
  bot._client.on('tile_entity_data', (packet) => {
463
410
  if (packet.location !== undefined) {
464
- addBlockEntity(packet.nbtData, packet.location.x, packet.location.y, packet.location.z, packet.action)
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)
465
414
  } else {
466
- addBlockEntity(packet.nbtData)
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)
467
419
  }
468
420
  })
469
421
 
@@ -480,12 +432,25 @@ function inject (bot, { version, storageBuilder }) {
480
432
  }
481
433
  }
482
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
+ }
483
451
  bot._client.write('update_sign', {
484
452
  location: block.position,
485
- text1: JSON.stringify(lines[0]),
486
- text2: JSON.stringify(lines[1]),
487
- text3: JSON.stringify(lines[2]),
488
- text4: JSON.stringify(lines[3])
453
+ ...signData
489
454
  })
490
455
  }
491
456
 
@@ -583,7 +548,6 @@ function inject (bot, { version, storageBuilder }) {
583
548
  bot.canSeeBlock = canSeeBlock
584
549
  bot.blockAt = blockAt
585
550
  bot._updateBlockState = updateBlockState
586
- bot._blockEntities = blockEntities
587
551
  bot.waitForChunksToLoad = callbackify(waitForChunksToLoad)
588
552
  }
589
553
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mineflayer",
3
- "version": "3.15.0",
3
+ "version": "3.16.0",
4
4
  "description": "create minecraft bots with a stable, high level API",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -24,9 +24,9 @@
24
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.28.1",
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": "^2.0.0",
38
+ "typed-emitter": "^1.0.0",
39
39
  "vec3": "^0.1.7"
40
40
  },
41
41
  "devDependencies": {