CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/examples/perfectShotBow.js
Views: 789
1
const mineflayer = require('mineflayer')
2
const minecraftHawkEye = require('minecrafthawkeye')
3
4
const bot = mineflayer.createBot({
5
host: process.argv[2],
6
port: parseInt(process.argv[3]),
7
username: process.argv[4] ? process.argv[4] : 'Archer',
8
password: process.argv[5]
9
})
10
bot.loadPlugin(minecraftHawkEye)
11
12
bot.on('spawn', function () {
13
bot.chat(`/give ${bot.username} bow{Enchantments:[{id:unbreaking,lvl:100}]} 1`)
14
bot.chat(`/give ${bot.username} crossbow{Enchantments:[{id:quick_charge,lvl:3},{id:unbreaking,lvl:100}]} 1`)
15
bot.chat(`/give ${bot.username} minecraft:arrow 300`)
16
bot.chat('/time set day')
17
bot.chat('/kill @e[type=minecraft:arrow]')
18
19
bot.chat('Ready!')
20
21
// Get target for block position, use whatever you need
22
const target = bot.hawkEye.getPlayer()
23
24
if (!target) {
25
return false
26
}
27
28
// const validWeapons = ['bow', 'crossbow', 'snowball', 'ender_pearl', 'egg', 'splash_potion']
29
const weapon = 'crossbow'
30
31
// Auto attack every 1,2 secs with bow
32
// With crossbow attack when crossbow is charget (enchant 3 = 0.5s)
33
// ['snowball', 'ender_pearl', 'egg', 'splash_potion'] auto attack every 0,1 sec, no recommended use autoAttack for these items, instead use "bot.hawkEye.oneShot(target, weapon)"
34
35
bot.hawkEye.autoAttack(target, weapon)
36
// If you force stop attack use:
37
// hawkEye.stop();
38
39
// Use one shot time with calc:
40
// bot.hawkEye.oneShot(target, weapon);
41
42
// If you want to shot in XYZ position:
43
/*
44
const blockPosition = {
45
position: {
46
x: 244.5,
47
y: 75.5,
48
z: -220
49
},
50
isValid: true // Fake to is "alive"
51
}
52
// bot.hawkEye.oneShot(blockPosition, weapon);
53
// bot.hawkEye.autoAttack(blockPosition);
54
*/
55
})
56
57
bot.on('die', () => {
58
bot.hawkEye.stop()
59
})
60
61