mineflayer 3.14.0 → 3.14.1
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/attack.js +45 -0
- package/lib/features.json +5 -0
- package/lib/plugins/entities.js +11 -4
- package/package.json +1 -1
package/docs/history.md
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*
|
|
2
|
+
*
|
|
3
|
+
* A bot that attacks the player that sends a message or the nearest entity (excluding players)
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
const mineflayer = require('mineflayer')
|
|
7
|
+
|
|
8
|
+
if (process.argv.length < 4 || process.argv.length > 6) {
|
|
9
|
+
console.log('Usage : node attack.js <host> <port> [<name>] [<password>]')
|
|
10
|
+
process.exit(1)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const bot = mineflayer.createBot({
|
|
14
|
+
host: process.argv[2],
|
|
15
|
+
port: parseInt(process.argv[3]),
|
|
16
|
+
username: process.argv[4] ? process.argv[4] : 'attack',
|
|
17
|
+
password: process.argv[5]
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
bot.on('spawn', () => {
|
|
21
|
+
bot.on('chat', (username, message) => {
|
|
22
|
+
if (message === 'attack me') attackPlayer(username)
|
|
23
|
+
else if (message === 'attack') attackEntity()
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
function attackPlayer (username) {
|
|
28
|
+
const player = bot.players[username]
|
|
29
|
+
if (!player || !player.entity) {
|
|
30
|
+
bot.chat('I can\'t see you')
|
|
31
|
+
} else {
|
|
32
|
+
bot.chat(`Attacking ${player.username}`)
|
|
33
|
+
bot.attack(player.entity)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function attackEntity () {
|
|
38
|
+
const entity = bot.nearestEntity()
|
|
39
|
+
if (!entity) {
|
|
40
|
+
bot.chat('No nearby entities')
|
|
41
|
+
} else {
|
|
42
|
+
bot.chat(`Attacking ${entity.name ?? entity.username}`)
|
|
43
|
+
bot.attack(entity)
|
|
44
|
+
}
|
|
45
|
+
}
|
package/lib/features.json
CHANGED
|
@@ -318,5 +318,10 @@
|
|
|
318
318
|
"name": "setSlotAsTransaction",
|
|
319
319
|
"description": "use setslot as transaction instead of just hoping it'll work",
|
|
320
320
|
"versions": ["1.17", "1.17.1"]
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
"name": "armAnimationBeforeUse",
|
|
324
|
+
"description": "arm animation packet sent before use entity packet",
|
|
325
|
+
"versions": ["1.8", "1.8.9"]
|
|
321
326
|
}
|
|
322
327
|
]
|
package/lib/plugins/entities.js
CHANGED
|
@@ -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 (
|
|
553
|
-
|
|
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) {
|