mineflayer 4.28.0 → 4.29.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 +4 -0
- package/examples/bossbar.js +55 -0
- package/examples/sound.js +34 -0
- package/lib/bossbar.js +13 -2
- package/lib/plugins/boss_bar.js +25 -14
- package/lib/plugins/sound.js +20 -1
- package/package.json +1 -1
package/docs/history.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## 4.29.0
|
|
2
|
+
* [Sound test (#3657)](https://github.com/PrismarineJS/mineflayer/commit/51495665bbc3789ddc4284403c1ef288fea18ddc) (thanks @rom1504)
|
|
3
|
+
* [Add boss bar test (#3655)](https://github.com/PrismarineJS/mineflayer/commit/b6950e9c42324c0f6fba6f2f802d0c87973a8c92) (thanks @rom1504)
|
|
4
|
+
|
|
1
5
|
## 4.28.0
|
|
2
6
|
* [Add a test for title and improve the title functionality in mineflayer (#3653)](https://github.com/PrismarineJS/mineflayer/commit/4593da148afd84d9a298074123c5e022f1f8d3e4) (thanks @rom1504)
|
|
3
7
|
* [Add experience test (#3652)](https://github.com/PrismarineJS/mineflayer/commit/32d9d8434465bcea6705d5d6b073a8497adb7c34) (thanks @rom1504)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const mineflayer = require('mineflayer')
|
|
2
|
+
|
|
3
|
+
if (process.argv.length < 4 || process.argv.length > 6) {
|
|
4
|
+
console.log('Usage : node bossbar.js <host> <port> [<name>] [<password>]')
|
|
5
|
+
process.exit(1)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const bot = mineflayer.createBot({
|
|
9
|
+
host: process.argv[2],
|
|
10
|
+
port: parseInt(process.argv[3]),
|
|
11
|
+
username: process.argv[4] ? process.argv[4] : 'bossbar_bot',
|
|
12
|
+
password: process.argv[5]
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// Wait for spawn
|
|
16
|
+
bot.once('spawn', () => {
|
|
17
|
+
console.log('Bot spawned!')
|
|
18
|
+
|
|
19
|
+
// Create a boss bar
|
|
20
|
+
bot.chat('/bossbar add test:bar "Test Boss Bar"')
|
|
21
|
+
bot.chat('/bossbar set test:bar players ' + bot.username)
|
|
22
|
+
bot.chat('/bossbar set test:bar color red')
|
|
23
|
+
bot.chat('/bossbar set test:bar style notched_6')
|
|
24
|
+
bot.chat('/bossbar set test:bar value 50')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// Listen for boss bar events
|
|
28
|
+
bot.on('bossBarCreated', (bossBar) => {
|
|
29
|
+
console.log('Boss bar created:', bossBar.title.toString())
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
bot.on('bossBarUpdated', (bossBar) => {
|
|
33
|
+
console.log('Boss bar updated:', {
|
|
34
|
+
title: bossBar.title.toString(),
|
|
35
|
+
health: bossBar.health,
|
|
36
|
+
color: bossBar.color,
|
|
37
|
+
dividers: bossBar.dividers
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
bot.on('bossBarDeleted', (bossBar) => {
|
|
42
|
+
console.log('Boss bar deleted:', bossBar.title.toString())
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// After 5 seconds, update the boss bar
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
bot.chat('/bossbar set test:bar color blue')
|
|
48
|
+
bot.chat('/bossbar set test:bar style notched_10')
|
|
49
|
+
bot.chat('/bossbar set test:bar value 75')
|
|
50
|
+
}, 5000)
|
|
51
|
+
|
|
52
|
+
// After 10 seconds, remove the boss bar
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
bot.chat('/bossbar remove test:bar')
|
|
55
|
+
}, 10000)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const mineflayer = require('mineflayer')
|
|
2
|
+
|
|
3
|
+
if (process.argv.length < 4 || process.argv.length > 6) {
|
|
4
|
+
console.log('Usage : node sound.js <host> <port> [<name>] [<password>]')
|
|
5
|
+
process.exit(1)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const bot = mineflayer.createBot({
|
|
9
|
+
host: process.argv[2],
|
|
10
|
+
port: parseInt(process.argv[3]),
|
|
11
|
+
username: process.argv[4] ? process.argv[4] : 'sound_bot',
|
|
12
|
+
password: process.argv[5]
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// Listen for any sound effect
|
|
16
|
+
bot.on('soundEffectHeard', (soundName, position, volume, pitch) => {
|
|
17
|
+
const { x, y, z } = position
|
|
18
|
+
console.log(`Heard sound: ${soundName} at ${x}, ${y}, ${z}`)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
// Listen for note block sounds
|
|
22
|
+
bot.on('noteHeard', (block, instrument, pitch) => {
|
|
23
|
+
console.log(`Heard note block: ${instrument.name} at pitch ${pitch}`)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// Listen for hardcoded sound effects (like mob sounds)
|
|
27
|
+
bot.on('hardcodedSoundEffectHeard', (soundId, soundCategory, position, volume, pitch) => {
|
|
28
|
+
const { x, y, z } = position
|
|
29
|
+
console.log(`Heard hardcoded sound: ${soundId} (${soundCategory}) at ${x}, ${y}, ${z}`)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
bot.on('spawn', () => {
|
|
33
|
+
console.log('Bot spawned!')
|
|
34
|
+
})
|
package/lib/bossbar.js
CHANGED
|
@@ -6,7 +6,7 @@ function loader (registry) {
|
|
|
6
6
|
return class BossBar {
|
|
7
7
|
constructor (uuid, title, health, dividers, color, flags) {
|
|
8
8
|
this._entityUUID = uuid
|
|
9
|
-
this.
|
|
9
|
+
this.title = title
|
|
10
10
|
this._health = health
|
|
11
11
|
this._dividers = divisions[dividers]
|
|
12
12
|
this._color = colors[color]
|
|
@@ -20,7 +20,18 @@ function loader (registry) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
set title (title) {
|
|
23
|
-
|
|
23
|
+
if (title && typeof title === 'object' && title.type === 'string' && 'value' in title) {
|
|
24
|
+
this._title = title.value
|
|
25
|
+
} else {
|
|
26
|
+
const chatMsg = ChatMessage.fromNotch(title)
|
|
27
|
+
if (chatMsg !== undefined && chatMsg !== null) {
|
|
28
|
+
this._title = chatMsg
|
|
29
|
+
} else if (typeof title === 'string') {
|
|
30
|
+
this._title = title
|
|
31
|
+
} else {
|
|
32
|
+
this._title = ''
|
|
33
|
+
}
|
|
34
|
+
}
|
|
24
35
|
}
|
|
25
36
|
|
|
26
37
|
set health (health) {
|
package/lib/plugins/boss_bar.js
CHANGED
|
@@ -4,17 +4,23 @@ function inject (bot, { version }) {
|
|
|
4
4
|
const BossBar = require('../bossbar')(bot.registry)
|
|
5
5
|
const bars = {}
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
function extractTitle (title) {
|
|
8
|
+
if (!title) return ''
|
|
9
|
+
if (typeof title === 'string') return title
|
|
10
|
+
// Return the original object for BossBar to handle
|
|
11
|
+
return title
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function handleBossBarPacket (packet) {
|
|
8
15
|
if (packet.action === 0) {
|
|
9
16
|
bars[packet.entityUUID] = new BossBar(
|
|
10
17
|
packet.entityUUID,
|
|
11
|
-
packet.title,
|
|
18
|
+
extractTitle(packet.title),
|
|
12
19
|
packet.health,
|
|
13
20
|
packet.dividers,
|
|
14
21
|
packet.color,
|
|
15
22
|
packet.flags
|
|
16
23
|
)
|
|
17
|
-
|
|
18
24
|
bot.emit('bossBarCreated', bars[packet.entityUUID])
|
|
19
25
|
} else if (packet.action === 1) {
|
|
20
26
|
bot.emit('bossBarDeleted', bars[packet.entityUUID])
|
|
@@ -23,26 +29,31 @@ function inject (bot, { version }) {
|
|
|
23
29
|
if (!(packet.entityUUID in bars)) {
|
|
24
30
|
return
|
|
25
31
|
}
|
|
26
|
-
if (packet.action === 2) {
|
|
32
|
+
if (packet.action === 2 && packet.health !== undefined) {
|
|
27
33
|
bars[packet.entityUUID].health = packet.health
|
|
28
34
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
bars[packet.entityUUID].title = packet.title
|
|
35
|
+
if (packet.action === 3 && packet.title !== undefined) {
|
|
36
|
+
bars[packet.entityUUID].title = extractTitle(packet.title)
|
|
32
37
|
}
|
|
33
|
-
|
|
34
38
|
if (packet.action === 4) {
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
if (packet.dividers !== undefined) {
|
|
40
|
+
bars[packet.entityUUID].dividers = packet.dividers
|
|
41
|
+
}
|
|
42
|
+
if (packet.color !== undefined) {
|
|
43
|
+
bars[packet.entityUUID].color = packet.color
|
|
44
|
+
}
|
|
37
45
|
}
|
|
38
|
-
|
|
39
|
-
if (packet.action === 5) {
|
|
46
|
+
if (packet.action === 5 && packet.flags !== undefined) {
|
|
40
47
|
bars[packet.entityUUID].flags = packet.flags
|
|
41
48
|
}
|
|
42
|
-
|
|
43
49
|
bot.emit('bossBarUpdated', bars[packet.entityUUID])
|
|
44
50
|
}
|
|
45
|
-
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Handle all possible packet names
|
|
54
|
+
bot._client.on('boss_bar', handleBossBarPacket)
|
|
55
|
+
bot._client.on('bossbar', handleBossBarPacket)
|
|
56
|
+
bot._client.on('boss_bar_update', handleBossBarPacket)
|
|
46
57
|
|
|
47
58
|
Object.defineProperty(bot, 'bossBars', {
|
|
48
59
|
get () {
|
package/lib/plugins/sound.js
CHANGED
|
@@ -3,13 +3,24 @@ const { Vec3 } = require('vec3')
|
|
|
3
3
|
module.exports = inject
|
|
4
4
|
|
|
5
5
|
function inject (bot) {
|
|
6
|
+
const mcData = require('minecraft-data')(bot.version)
|
|
7
|
+
|
|
6
8
|
bot._client.on('named_sound_effect', (packet) => {
|
|
7
9
|
const soundName = packet.soundName
|
|
8
10
|
const pt = new Vec3(packet.x / 8, packet.y / 8, packet.z / 8)
|
|
9
11
|
const volume = packet.volume
|
|
10
12
|
const pitch = packet.pitch
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
// In 1.8.8, sound names are in the format "note.harp" or "random.click"
|
|
15
|
+
// We need to convert them to the format expected by the test
|
|
16
|
+
const normalizedSoundName = bot.supportFeature('playsoundUsesResourceLocation')
|
|
17
|
+
? `minecraft:${soundName.replace(/\./g, '_')}`
|
|
18
|
+
: soundName
|
|
19
|
+
|
|
20
|
+
// Emit both events for compatibility with tests
|
|
21
|
+
bot.emit('soundEffectHeard', normalizedSoundName, pt, volume, pitch)
|
|
22
|
+
// Emit hardcodedSoundEffectHeard for compatibility (use 0, 'master' as dummy values)
|
|
23
|
+
bot.emit('hardcodedSoundEffectHeard', 0, 'master', pt, volume, pitch)
|
|
13
24
|
})
|
|
14
25
|
|
|
15
26
|
bot._client.on('sound_effect', (packet) => {
|
|
@@ -19,6 +30,14 @@ function inject (bot) {
|
|
|
19
30
|
const volume = packet.volume
|
|
20
31
|
const pitch = packet.pitch
|
|
21
32
|
|
|
33
|
+
// Try to resolve sound name from mcData
|
|
34
|
+
let soundName = soundId
|
|
35
|
+
if (mcData.sounds && mcData.sounds[soundId]) {
|
|
36
|
+
soundName = mcData.sounds[soundId].name
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Emit both events for compatibility
|
|
22
40
|
bot.emit('hardcodedSoundEffectHeard', soundId, soundCategory, pt, volume, pitch)
|
|
41
|
+
bot.emit('soundEffectHeard', soundName, pt, volume, pitch)
|
|
23
42
|
})
|
|
24
43
|
}
|