mineflayer 3.12.0 → 3.13.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/docs/history.md +6 -0
- package/lib/plugins/blocks.js +17 -3
- package/lib/plugins/entities.js +5 -1
- package/lib/plugins/generic_place.js +5 -1
- package/lib/plugins/place_block.js +1 -1
- package/lib/plugins/place_entity.js +11 -5
- package/lib/plugins/scoreboard.js +2 -9
- package/lib/scoreboard.js +48 -35
- package/package.json +1 -1
package/docs/history.md
CHANGED
package/lib/plugins/blocks.js
CHANGED
|
@@ -476,6 +476,7 @@ function inject (bot, { version, storageBuilder }) {
|
|
|
476
476
|
// if we get a respawn packet and the dimension is changed,
|
|
477
477
|
// unload all chunks from memory.
|
|
478
478
|
let dimension
|
|
479
|
+
let worldName
|
|
479
480
|
function dimensionToFolderName (dimension) {
|
|
480
481
|
if (bot.supportFeature('dimensionIsAnInt')) {
|
|
481
482
|
return dimensionNames[dimension]
|
|
@@ -511,13 +512,26 @@ function inject (bot, { version, storageBuilder }) {
|
|
|
511
512
|
}
|
|
512
513
|
|
|
513
514
|
bot._client.on('login', (packet) => {
|
|
514
|
-
|
|
515
|
+
if (bot.supportFeature('dimensionIsAnInt')) {
|
|
516
|
+
dimension = packet.dimension
|
|
517
|
+
} else {
|
|
518
|
+
dimension = packet.dimension
|
|
519
|
+
worldName = packet.worldName
|
|
520
|
+
}
|
|
515
521
|
switchWorld()
|
|
516
522
|
})
|
|
517
523
|
|
|
518
524
|
bot._client.on('respawn', (packet) => {
|
|
519
|
-
if (
|
|
520
|
-
|
|
525
|
+
if (bot.supportFeature('dimensionIsAnInt')) { // <=1.15.2
|
|
526
|
+
if (dimension === packet.dimension) return
|
|
527
|
+
dimension = packet.dimension
|
|
528
|
+
} else { // >= 1.15.2
|
|
529
|
+
if (dimension === packet.dimension) return
|
|
530
|
+
if (worldName === packet.worldName && packet.copyMetadata === true) return // don't unload chunks if in same world and metaData is true
|
|
531
|
+
// Metadata is true when switching dimensions however, then the world name is different
|
|
532
|
+
dimension = packet.dimension
|
|
533
|
+
worldName = packet.worldName
|
|
534
|
+
}
|
|
521
535
|
switchWorld()
|
|
522
536
|
})
|
|
523
537
|
|
package/lib/plugins/entities.js
CHANGED
|
@@ -89,7 +89,11 @@ function inject (bot, { version }) {
|
|
|
89
89
|
return best
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
// Reset list of players and entities on login
|
|
93
|
+
bot._client.on('login', (packet) => {
|
|
94
|
+
bot.players = {}
|
|
95
|
+
bot.uuidToUsername = {}
|
|
96
|
+
bot.entities = {}
|
|
93
97
|
// login
|
|
94
98
|
bot.entity = fetchEntity(packet.entityId)
|
|
95
99
|
bot.username = bot._client.username
|
|
@@ -7,7 +7,7 @@ function inject (bot, { version }) {
|
|
|
7
7
|
*
|
|
8
8
|
* @param {import('prismarine-block').Block} referenceBlock
|
|
9
9
|
* @param {import('vec3').Vec3} faceVector
|
|
10
|
-
* @param {{half?: 'top'|'bottom', delta?: import('vec3').Vec3, forceLook?: boolean | 'ignore', offhand?: boolean}} options
|
|
10
|
+
* @param {{half?: 'top'|'bottom', delta?: import('vec3').Vec3, forceLook?: boolean | 'ignore', offhand?: boolean, swingArm?: 'right' | 'left', showHand?: boolean}} options
|
|
11
11
|
*/
|
|
12
12
|
async function _genericPlace (referenceBlock, faceVector, options) {
|
|
13
13
|
let handToPlaceWith = 0
|
|
@@ -39,6 +39,10 @@ function inject (bot, { version }) {
|
|
|
39
39
|
// TODO: tell the server that we are sneaking while doing this
|
|
40
40
|
const pos = referenceBlock.position
|
|
41
41
|
|
|
42
|
+
if (options.swingArm) {
|
|
43
|
+
bot.swingArm(options.swingArm, options.showHand)
|
|
44
|
+
}
|
|
45
|
+
|
|
42
46
|
if (bot.supportFeature('blockPlaceHasHeldItem')) {
|
|
43
47
|
const packet = {
|
|
44
48
|
location: pos,
|
|
@@ -21,7 +21,7 @@ function inject (bot) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
async function placeBlock (referenceBlock, faceVector) {
|
|
24
|
-
await placeBlockWithOptions(referenceBlock, faceVector, {})
|
|
24
|
+
await placeBlockWithOptions(referenceBlock, faceVector, { swingArm: 'right' })
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
bot.placeBlock = callbackify(placeBlock)
|
|
@@ -5,6 +5,12 @@ module.exports = inject
|
|
|
5
5
|
function inject (bot, { version }) {
|
|
6
6
|
const Item = require('prismarine-item')(version)
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {import('prismarine-block').Block} referenceBlock
|
|
11
|
+
* @param {import('vec3').Vec3} faceVector
|
|
12
|
+
* @param {{forceLook?: boolean | 'ignore', offhand?: boolean, swingArm?: 'right' | 'left', showHand?: boolean}} options
|
|
13
|
+
*/
|
|
8
14
|
async function placeEntityWithOptions (referenceBlock, faceVector, options) {
|
|
9
15
|
if (!bot.heldItem) throw new Error('must be holding an item to place an entity')
|
|
10
16
|
|
|
@@ -20,14 +26,14 @@ function inject (bot, { version }) {
|
|
|
20
26
|
name = bot.heldItem.spawnEggMobName
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
const pos = await bot._genericPlace(referenceBlock, faceVector, options)
|
|
24
|
-
|
|
25
29
|
if (type === 'spawn_egg') {
|
|
26
|
-
|
|
27
|
-
} else {
|
|
28
|
-
bot.swingArm()
|
|
30
|
+
options.showHand = false
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
if (!options.swingArm) options.swingArm = options.offhand ? 'left' : 'right'
|
|
34
|
+
|
|
35
|
+
const pos = await bot._genericPlace(referenceBlock, faceVector, options)
|
|
36
|
+
|
|
31
37
|
if (type === 'boat') {
|
|
32
38
|
if (bot.supportFeature('useItemWithOwnPacket')) {
|
|
33
39
|
bot._client.write('use_item', {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
const ScoreBoard = require('../scoreboard')
|
|
2
|
-
|
|
3
1
|
module.exports = inject
|
|
4
2
|
|
|
5
3
|
function inject (bot) {
|
|
6
|
-
const
|
|
4
|
+
const ScoreBoard = require('../scoreboard')(bot)
|
|
7
5
|
const scoreboards = {}
|
|
8
6
|
|
|
9
7
|
bot._client.on('scoreboard_objective', (packet) => {
|
|
@@ -29,12 +27,7 @@ function inject (bot) {
|
|
|
29
27
|
bot._client.on('scoreboard_score', (packet) => {
|
|
30
28
|
const scoreboard = scoreboards[packet.scoreName]
|
|
31
29
|
if (scoreboard !== undefined && packet.action === 0) {
|
|
32
|
-
const
|
|
33
|
-
let displayName = new ChatMessage(itemName)
|
|
34
|
-
if (itemName in bot.teamMap) {
|
|
35
|
-
displayName = bot.teamMap[itemName].displayName(itemName)
|
|
36
|
-
}
|
|
37
|
-
const updated = scoreboard.add(itemName, value, displayName)
|
|
30
|
+
const updated = scoreboard.add(packet.itemName, packet.value)
|
|
38
31
|
bot.emit('scoreUpdated', scoreboard, updated)
|
|
39
32
|
}
|
|
40
33
|
|
package/lib/scoreboard.js
CHANGED
|
@@ -4,49 +4,62 @@ const sortItems = (a, b) => {
|
|
|
4
4
|
return 1
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
this.name = packet.name
|
|
10
|
-
this.setTitle(packet.displayText)
|
|
11
|
-
this.itemsMap = {}
|
|
12
|
-
}
|
|
7
|
+
module.exports = (bot) => {
|
|
8
|
+
const ChatMessage = require('prismarine-chat')(bot.version)
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
17
|
-
|
|
18
|
-
this.
|
|
10
|
+
class ScoreBoard {
|
|
11
|
+
constructor (packet) {
|
|
12
|
+
this.name = packet.name
|
|
13
|
+
this.setTitle(packet.displayText)
|
|
14
|
+
this.itemsMap = {}
|
|
19
15
|
}
|
|
20
|
-
}
|
|
21
16
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
setTitle (title) {
|
|
18
|
+
try {
|
|
19
|
+
this.title = JSON.parse(title).text // version>1.13
|
|
20
|
+
} catch {
|
|
21
|
+
this.title = title
|
|
22
|
+
}
|
|
23
|
+
}
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
add (name, value) {
|
|
26
|
+
this.itemsMap[name] = { name, value }
|
|
27
|
+
this.itemsMap[name] = {
|
|
28
|
+
name,
|
|
29
|
+
value,
|
|
30
|
+
get displayName () {
|
|
31
|
+
if (name in bot.teamMap) {
|
|
32
|
+
return bot.teamMap[name].displayName(name)
|
|
33
|
+
}
|
|
34
|
+
return new ChatMessage(name)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return this.itemsMap[name]
|
|
38
|
+
}
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
remove (name) {
|
|
41
|
+
const removed = this.itemsMap[name]
|
|
42
|
+
delete this.itemsMap[name]
|
|
43
|
+
return removed
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get items () {
|
|
47
|
+
return Object.values(this.itemsMap).sort(sortItems)
|
|
48
|
+
}
|
|
35
49
|
}
|
|
36
|
-
}
|
|
37
50
|
|
|
38
|
-
ScoreBoard.positions = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
ScoreBoard.positions = {
|
|
52
|
+
get list () {
|
|
53
|
+
return this[0]
|
|
54
|
+
},
|
|
42
55
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
56
|
+
get sidebar () {
|
|
57
|
+
return this[1]
|
|
58
|
+
},
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
get belowName () {
|
|
61
|
+
return this[2]
|
|
62
|
+
}
|
|
49
63
|
}
|
|
64
|
+
return ScoreBoard
|
|
50
65
|
}
|
|
51
|
-
|
|
52
|
-
module.exports = ScoreBoard
|