mineflayer 3.15.0 → 4.0.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 +2 -5
- package/docs/FAQ.md +10 -2
- package/docs/README.md +2 -5
- package/docs/api.md +122 -158
- package/docs/es/README_ES.md +6 -6
- package/docs/history.md +17 -0
- package/docs/zh/README_ZH_CN.md +27 -20
- package/examples/anvil.js +10 -12
- package/examples/chest.js +14 -16
- package/examples/digger.js +25 -31
- package/examples/inventory.js +10 -12
- package/index.d.ts +45 -58
- package/lib/features.json +5 -0
- package/lib/plugins/anvil.js +4 -4
- package/lib/plugins/bed.js +2 -3
- package/lib/plugins/blocks.js +43 -79
- package/lib/plugins/book.js +4 -5
- package/lib/plugins/chat.js +1 -9
- package/lib/plugins/chest.js +3 -4
- package/lib/plugins/craft.js +1 -2
- package/lib/plugins/creative.js +4 -4
- package/lib/plugins/digging.js +1 -14
- package/lib/plugins/enchantment_table.js +5 -6
- package/lib/plugins/entities.js +3 -2
- package/lib/plugins/fishing.js +2 -2
- package/lib/plugins/furnace.js +6 -7
- package/lib/plugins/inventory.js +14 -14
- package/lib/plugins/physics.js +5 -5
- package/lib/plugins/place_block.js +2 -2
- package/lib/plugins/simple_inventory.js +4 -5
- package/lib/plugins/villager.js +2 -3
- package/lib/promise_utils.js +0 -11
- package/package.json +4 -4
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
|
]
|
package/lib/plugins/anvil.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const assert = require('assert')
|
|
2
|
-
const {
|
|
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 =
|
|
109
|
-
anvil.rename =
|
|
108
|
+
anvil.combine = combine
|
|
109
|
+
anvil.rename = rename
|
|
110
110
|
|
|
111
111
|
return anvil
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
bot.openAnvil =
|
|
114
|
+
bot.openAnvil = openAnvil
|
|
115
115
|
}
|
package/lib/plugins/bed.js
CHANGED
|
@@ -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
|
|
|
@@ -174,7 +173,7 @@ function inject (bot) {
|
|
|
174
173
|
})
|
|
175
174
|
|
|
176
175
|
bot.parseBedMetadata = parseBedMetadata
|
|
177
|
-
bot.wake =
|
|
178
|
-
bot.sleep =
|
|
176
|
+
bot.wake = wake
|
|
177
|
+
bot.sleep = sleep
|
|
179
178
|
bot.isABed = isABed
|
|
180
179
|
}
|
package/lib/plugins/blocks.js
CHANGED
|
@@ -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
|
|
4
|
+
const { onceWithCleanup } = require('../promise_utils')
|
|
5
5
|
|
|
6
6
|
const { OctahedronIterator } = require('prismarine-world').iterators
|
|
7
7
|
|
|
@@ -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
|
-
|
|
293
|
+
if (blockEntity.x !== undefined) { // 1.17+
|
|
294
|
+
column.setBlockEntity(blockEntity, blockEntity.nbtData)
|
|
341
295
|
} else {
|
|
342
|
-
|
|
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
|
-
|
|
443
|
-
|
|
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
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,8 +548,7 @@ function inject (bot, { version, storageBuilder }) {
|
|
|
583
548
|
bot.canSeeBlock = canSeeBlock
|
|
584
549
|
bot.blockAt = blockAt
|
|
585
550
|
bot._updateBlockState = updateBlockState
|
|
586
|
-
bot.
|
|
587
|
-
bot.waitForChunksToLoad = callbackify(waitForChunksToLoad)
|
|
551
|
+
bot.waitForChunksToLoad = waitForChunksToLoad
|
|
588
552
|
}
|
|
589
553
|
|
|
590
554
|
function onesInShort (n) {
|
package/lib/plugins/book.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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
|
|
|
@@ -83,11 +82,11 @@ function inject (bot, { version }) {
|
|
|
83
82
|
return book
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
bot.writeBook =
|
|
85
|
+
bot.writeBook = async (slot, pages) => {
|
|
87
86
|
await write(slot, pages, null, null, false)
|
|
88
|
-
}
|
|
87
|
+
}
|
|
89
88
|
|
|
90
|
-
bot.signBook =
|
|
89
|
+
bot.signBook = async (slot, pages, author, title) => {
|
|
91
90
|
await write(slot, pages, author, title, true)
|
|
92
|
-
}
|
|
91
|
+
}
|
|
93
92
|
}
|
package/lib/plugins/chat.js
CHANGED
|
@@ -169,7 +169,7 @@ function inject (bot, options) {
|
|
|
169
169
|
chatWithHeader('', message)
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
bot.tabComplete =
|
|
172
|
+
bot.tabComplete = tabComplete
|
|
173
173
|
|
|
174
174
|
function addDefaultPatterns () {
|
|
175
175
|
if (!defaultChatPatterns) return
|
|
@@ -193,11 +193,3 @@ function inject (bot, options) {
|
|
|
193
193
|
}
|
|
194
194
|
bot.awaitMessage = awaitMessage
|
|
195
195
|
}
|
|
196
|
-
|
|
197
|
-
function callbackify (f) { // specifically for this function because cb isn't the last parameter
|
|
198
|
-
return function (...args) {
|
|
199
|
-
const cb = args[1]
|
|
200
|
-
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
|
-
}
|
|
203
|
-
}
|
package/lib/plugins/chest.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
const { callbackify } = require('../promise_utils')
|
|
2
1
|
|
|
3
2
|
module.exports = inject
|
|
4
3
|
|
|
@@ -26,7 +25,7 @@ function inject (bot) {
|
|
|
26
25
|
return chest
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
bot.openContainer =
|
|
30
|
-
bot.openChest =
|
|
31
|
-
bot.openDispenser =
|
|
28
|
+
bot.openContainer = openContainer
|
|
29
|
+
bot.openChest = openContainer
|
|
30
|
+
bot.openDispenser = openContainer
|
|
32
31
|
}
|
package/lib/plugins/craft.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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
|
|
|
@@ -226,7 +225,7 @@ function inject (bot, { version }) {
|
|
|
226
225
|
return true
|
|
227
226
|
}
|
|
228
227
|
|
|
229
|
-
bot.craft =
|
|
228
|
+
bot.craft = craft
|
|
230
229
|
bot.recipesFor = recipesFor
|
|
231
230
|
bot.recipesAll = recipesAll
|
|
232
231
|
}
|
package/lib/plugins/creative.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const assert = require('assert')
|
|
2
2
|
const { Vec3 } = require('vec3')
|
|
3
|
-
const {
|
|
3
|
+
const { sleep } = require('../promise_utils')
|
|
4
4
|
const { once } = require('events')
|
|
5
5
|
|
|
6
6
|
module.exports = inject
|
|
@@ -10,8 +10,8 @@ function inject (bot, { version }) {
|
|
|
10
10
|
|
|
11
11
|
// these features only work when you are in creative mode.
|
|
12
12
|
bot.creative = {
|
|
13
|
-
setInventorySlot:
|
|
14
|
-
flyTo:
|
|
13
|
+
setInventorySlot: setInventorySlot,
|
|
14
|
+
flyTo: flyTo,
|
|
15
15
|
startFlying,
|
|
16
16
|
stopFlying
|
|
17
17
|
}
|
|
@@ -23,7 +23,7 @@ function inject (bot, { version }) {
|
|
|
23
23
|
}
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
-
// WARN: This method should not be called twice on the same slot before first
|
|
26
|
+
// WARN: This method should not be called twice on the same slot before first promise succeeds
|
|
27
27
|
async function setInventorySlot (slot, item) {
|
|
28
28
|
assert(slot >= 0 && slot <= 44)
|
|
29
29
|
|
package/lib/plugins/digging.js
CHANGED
|
@@ -198,25 +198,12 @@ function inject (bot) {
|
|
|
198
198
|
return block.digTime(type, creative, bot.entity.isInWater, !bot.entity.onGround, enchantments, bot.entity.effects)
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
bot.dig =
|
|
201
|
+
bot.dig = dig
|
|
202
202
|
bot.stopDigging = noop
|
|
203
203
|
bot.canDigBlock = canDigBlock
|
|
204
204
|
bot.digTime = digTime
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
function callbackify (f) { // specifically for this function because cb could be the non-last parameter
|
|
208
|
-
return function (...args) {
|
|
209
|
-
const cbIndex = typeof args[1] === 'function' ? 1 : (typeof args[2] === 'function' ? 2 : 3)
|
|
210
|
-
const cb = args[cbIndex]
|
|
211
|
-
|
|
212
|
-
if (cbIndex === 1) args[1] = true
|
|
213
|
-
else if (typeof args[1] === 'string') args[1] = args[1] === 'ignore' ? args[1] : false
|
|
214
|
-
else args[1] = !!args[1] // coerce to boolean
|
|
215
|
-
|
|
216
|
-
return f(...args).then(r => { if (cb) { cb(undefined, r) } return r }, err => { if (cb) { cb(err) } else throw err })
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
207
|
function noop (err) {
|
|
221
208
|
if (err) throw err
|
|
222
209
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
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
|
|
|
@@ -15,10 +14,10 @@ function inject (bot) {
|
|
|
15
14
|
|
|
16
15
|
resetEnchantmentOptions()
|
|
17
16
|
|
|
18
|
-
enchantmentTable.enchant =
|
|
19
|
-
enchantmentTable.takeTargetItem =
|
|
20
|
-
enchantmentTable.putTargetItem =
|
|
21
|
-
enchantmentTable.putLapis =
|
|
17
|
+
enchantmentTable.enchant = enchant
|
|
18
|
+
enchantmentTable.takeTargetItem = takeTargetItem
|
|
19
|
+
enchantmentTable.putTargetItem = putTargetItem
|
|
20
|
+
enchantmentTable.putLapis = putLapis
|
|
22
21
|
enchantmentTable.targetItem = function () { return this.slots[0] }
|
|
23
22
|
|
|
24
23
|
bot._client.on('craft_progress_bar', onUpdateWindowProperty)
|
|
@@ -100,5 +99,5 @@ function inject (bot) {
|
|
|
100
99
|
}
|
|
101
100
|
}
|
|
102
101
|
|
|
103
|
-
bot.openEnchantmentTable =
|
|
102
|
+
bot.openEnchantmentTable = openEnchantmentTable
|
|
104
103
|
}
|
package/lib/plugins/entities.js
CHANGED
|
@@ -588,6 +588,7 @@ function inject (bot, { version }) {
|
|
|
588
588
|
}
|
|
589
589
|
|
|
590
590
|
function useEntity (target, leftClick, x, y, z) {
|
|
591
|
+
const sneaking = bot.getControlState('sneak')
|
|
591
592
|
if (x && y && z) {
|
|
592
593
|
bot._client.write('use_entity', {
|
|
593
594
|
target: target.id,
|
|
@@ -595,13 +596,13 @@ function inject (bot, { version }) {
|
|
|
595
596
|
x,
|
|
596
597
|
y,
|
|
597
598
|
z,
|
|
598
|
-
sneaking
|
|
599
|
+
sneaking
|
|
599
600
|
})
|
|
600
601
|
} else {
|
|
601
602
|
bot._client.write('use_entity', {
|
|
602
603
|
target: target.id,
|
|
603
604
|
mouse: leftClick,
|
|
604
|
-
sneaking
|
|
605
|
+
sneaking
|
|
605
606
|
})
|
|
606
607
|
}
|
|
607
608
|
}
|
package/lib/plugins/fishing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { Vec3 } = require('vec3')
|
|
2
|
-
const {
|
|
2
|
+
const { createDoneTask, createTask } = require('../promise_utils')
|
|
3
3
|
|
|
4
4
|
module.exports = inject
|
|
5
5
|
|
|
@@ -54,5 +54,5 @@ function inject (bot) {
|
|
|
54
54
|
await fishingTask.promise
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
bot.fish =
|
|
57
|
+
bot.fish = fish
|
|
58
58
|
}
|
package/lib/plugins/furnace.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const assert = require('assert')
|
|
2
|
-
const { callbackify } = require('../promise_utils')
|
|
3
2
|
|
|
4
3
|
module.exports = inject
|
|
5
4
|
|
|
@@ -25,11 +24,11 @@ function inject (bot) {
|
|
|
25
24
|
furnace.totalProgress = null
|
|
26
25
|
furnace.progress = null
|
|
27
26
|
furnace.progressSeconds = null
|
|
28
|
-
furnace.takeInput =
|
|
29
|
-
furnace.takeFuel =
|
|
30
|
-
furnace.takeOutput =
|
|
31
|
-
furnace.putInput =
|
|
32
|
-
furnace.putFuel =
|
|
27
|
+
furnace.takeInput = takeInput
|
|
28
|
+
furnace.takeFuel = takeFuel
|
|
29
|
+
furnace.takeOutput = takeOutput
|
|
30
|
+
furnace.putInput = putInput
|
|
31
|
+
furnace.putFuel = putFuel
|
|
33
32
|
furnace.inputItem = function () { return this.slots[0] }
|
|
34
33
|
furnace.fuelItem = function () { return this.slots[1] }
|
|
35
34
|
furnace.outputItem = function () { return this.slots[2] }
|
|
@@ -118,5 +117,5 @@ function inject (bot) {
|
|
|
118
117
|
return ticks * 0.05
|
|
119
118
|
}
|
|
120
119
|
|
|
121
|
-
bot.openFurnace =
|
|
120
|
+
bot.openFurnace = openFurnace
|
|
122
121
|
}
|
package/lib/plugins/inventory.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const assert = require('assert')
|
|
2
2
|
const { Vec3 } = require('vec3')
|
|
3
3
|
const { once } = require('events')
|
|
4
|
-
const {
|
|
4
|
+
const { sleep, createDoneTask, createTask, withTimeout } = require('../promise_utils')
|
|
5
5
|
|
|
6
6
|
module.exports = inject
|
|
7
7
|
|
|
@@ -306,7 +306,7 @@ function inject (bot, { version, hideErrors }) {
|
|
|
306
306
|
window.emit('close')
|
|
307
307
|
closeWindow(window)
|
|
308
308
|
}
|
|
309
|
-
window.withdraw =
|
|
309
|
+
window.withdraw = async (itemType, metadata, count) => {
|
|
310
310
|
if (bot.inventory.emptySlotCount() === 0) {
|
|
311
311
|
throw new Error('Unable to withdraw, Bot inventory is full.')
|
|
312
312
|
}
|
|
@@ -322,8 +322,8 @@ function inject (bot, { version, hideErrors }) {
|
|
|
322
322
|
destEnd: window.inventoryEnd
|
|
323
323
|
}
|
|
324
324
|
await transfer(options)
|
|
325
|
-
}
|
|
326
|
-
window.deposit =
|
|
325
|
+
}
|
|
326
|
+
window.deposit = async (itemType, metadata, count) => {
|
|
327
327
|
const options = {
|
|
328
328
|
window: window,
|
|
329
329
|
itemType,
|
|
@@ -335,7 +335,7 @@ function inject (bot, { version, hideErrors }) {
|
|
|
335
335
|
destEnd: window.inventoryStart
|
|
336
336
|
}
|
|
337
337
|
await transfer(options)
|
|
338
|
-
}
|
|
338
|
+
}
|
|
339
339
|
}
|
|
340
340
|
|
|
341
341
|
async function openBlock (block) {
|
|
@@ -643,21 +643,21 @@ function inject (bot, { version, hideErrors }) {
|
|
|
643
643
|
bot.emit(`setWindowItems:${window.id}`)
|
|
644
644
|
})
|
|
645
645
|
|
|
646
|
-
bot.activateBlock =
|
|
647
|
-
bot.activateEntity =
|
|
648
|
-
bot.activateEntityAt =
|
|
649
|
-
bot.consume =
|
|
646
|
+
bot.activateBlock = activateBlock
|
|
647
|
+
bot.activateEntity = activateEntity
|
|
648
|
+
bot.activateEntityAt = activateEntityAt
|
|
649
|
+
bot.consume = consume
|
|
650
650
|
bot.activateItem = activateItem
|
|
651
651
|
bot.deactivateItem = deactivateItem
|
|
652
652
|
|
|
653
653
|
// not really in the public API
|
|
654
|
-
bot.clickWindow =
|
|
654
|
+
bot.clickWindow = clickWindow
|
|
655
655
|
bot.putSelectedItemRange = putSelectedItemRange
|
|
656
656
|
bot.putAway = putAway
|
|
657
657
|
bot.closeWindow = closeWindow
|
|
658
|
-
bot.transfer =
|
|
659
|
-
bot.openBlock =
|
|
660
|
-
bot.openEntity =
|
|
661
|
-
bot.moveSlotItem =
|
|
658
|
+
bot.transfer = transfer
|
|
659
|
+
bot.openBlock = openBlock
|
|
660
|
+
bot.openEntity = openEntity
|
|
661
|
+
bot.moveSlotItem = moveSlotItem
|
|
662
662
|
bot.updateHeldItem = updateHeldItem
|
|
663
663
|
}
|
package/lib/plugins/physics.js
CHANGED
|
@@ -3,7 +3,7 @@ const assert = require('assert')
|
|
|
3
3
|
const math = require('../math')
|
|
4
4
|
const conv = require('../conversions')
|
|
5
5
|
const { performance } = require('perf_hooks')
|
|
6
|
-
const {
|
|
6
|
+
const { createDoneTask, createTask } = require('../promise_utils')
|
|
7
7
|
|
|
8
8
|
const { Physics, PlayerState } = require('prismarine-physics')
|
|
9
9
|
|
|
@@ -223,7 +223,7 @@ function inject (bot, { physicsEnabled }) {
|
|
|
223
223
|
}
|
|
224
224
|
})
|
|
225
225
|
|
|
226
|
-
bot.look =
|
|
226
|
+
bot.look = async (yaw, pitch, force) => {
|
|
227
227
|
if (!lookingTask.done) {
|
|
228
228
|
lookingTask.finish() // finish the previous one
|
|
229
229
|
}
|
|
@@ -245,15 +245,15 @@ function inject (bot, { physicsEnabled }) {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
await lookingTask.promise
|
|
248
|
-
}
|
|
248
|
+
}
|
|
249
249
|
|
|
250
|
-
bot.lookAt =
|
|
250
|
+
bot.lookAt = async (point, force) => {
|
|
251
251
|
const delta = point.minus(bot.entity.position.offset(0, bot.entity.height, 0))
|
|
252
252
|
const yaw = Math.atan2(-delta.x, -delta.z)
|
|
253
253
|
const groundDistance = Math.sqrt(delta.x * delta.x + delta.z * delta.z)
|
|
254
254
|
const pitch = Math.atan2(delta.y, groundDistance)
|
|
255
255
|
await bot.look(yaw, pitch, force)
|
|
256
|
-
}
|
|
256
|
+
}
|
|
257
257
|
|
|
258
258
|
// player position and look (clientbound)
|
|
259
259
|
bot._client.on('position', (packet) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { onceWithCleanup
|
|
1
|
+
const { onceWithCleanup } = require('../promise_utils')
|
|
2
2
|
|
|
3
3
|
module.exports = inject
|
|
4
4
|
|
|
@@ -24,6 +24,6 @@ function inject (bot) {
|
|
|
24
24
|
await placeBlockWithOptions(referenceBlock, faceVector, { swingArm: 'right' })
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
bot.placeBlock =
|
|
27
|
+
bot.placeBlock = placeBlock
|
|
28
28
|
bot._placeBlockWithOptions = placeBlockWithOptions
|
|
29
29
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const assert = require('assert')
|
|
2
|
-
const { callbackify } = require('../promise_utils')
|
|
3
2
|
|
|
4
3
|
module.exports = inject
|
|
5
4
|
|
|
@@ -144,10 +143,10 @@ function inject (bot) {
|
|
|
144
143
|
return bot.clickWindow(slot, 1, 0)
|
|
145
144
|
}
|
|
146
145
|
|
|
147
|
-
bot.equip =
|
|
148
|
-
bot.unequip =
|
|
149
|
-
bot.toss =
|
|
150
|
-
bot.tossStack =
|
|
146
|
+
bot.equip = equip
|
|
147
|
+
bot.unequip = unequip
|
|
148
|
+
bot.toss = toss
|
|
149
|
+
bot.tossStack = tossStack
|
|
151
150
|
bot.setQuickBarSlot = setQuickBarSlot
|
|
152
151
|
bot.getEquipmentDestSlot = getDestSlot
|
|
153
152
|
bot.simpleClick = { leftMouse, rightMouse }
|
package/lib/plugins/villager.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
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
|
|
|
@@ -249,6 +248,6 @@ function inject (bot, { version }) {
|
|
|
249
248
|
await bot.transfer(options)
|
|
250
249
|
}
|
|
251
250
|
|
|
252
|
-
bot.openVillager =
|
|
253
|
-
bot.trade =
|
|
251
|
+
bot.openVillager = openVillager
|
|
252
|
+
bot.trade = trade
|
|
254
253
|
}
|
package/lib/promise_utils.js
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
function callbackify (f) {
|
|
2
|
-
return function (...args) {
|
|
3
|
-
const cb = args[f.length]
|
|
4
|
-
return f(...args).then(r => {
|
|
5
|
-
if (cb) { cb(undefined, r) }
|
|
6
|
-
return r
|
|
7
|
-
}, err => { if (cb) { cb(err) } else throw err })
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
1
|
function sleep (ms) {
|
|
12
2
|
return new Promise(resolve => setTimeout(resolve, ms))
|
|
13
3
|
}
|
|
@@ -92,7 +82,6 @@ function withTimeout (promise, timeout) {
|
|
|
92
82
|
}
|
|
93
83
|
|
|
94
84
|
module.exports = {
|
|
95
|
-
callbackify,
|
|
96
85
|
sleep,
|
|
97
86
|
createTask,
|
|
98
87
|
createDoneTask,
|