-
-
Notifications
You must be signed in to change notification settings - Fork 932
/
jumper.js
116 lines (108 loc) · 2.76 KB
/
jumper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* Jumping is fun. Riding pigs is even funnier!
*
* Learn how to make your bot interactive with this example.
*
* This bot can move, jump, ride vehicles, attack nearby entities and much more.
*/
const mineflayer = require('mineflayer')
if (process.argv.length < 4 || process.argv.length > 6) {
console.log('Usage : node jumper.js <host> <port> [<name>] [<password>]')
process.exit(1)
}
const bot = mineflayer.createBot({
host: process.argv[2],
port: parseInt(process.argv[3]),
username: process.argv[4] ? process.argv[4] : 'jumper',
password: process.argv[5]
})
let target = null
bot.on('chat', (username, message) => {
if (username === bot.username) return
target = bot.players[username].entity
let entity
switch (message) {
case 'forward':
bot.setControlState('forward', true)
break
case 'back':
bot.setControlState('back', true)
break
case 'left':
bot.setControlState('left', true)
break
case 'right':
bot.setControlState('right', true)
break
case 'sprint':
bot.setControlState('sprint', true)
break
case 'stop':
bot.clearControlStates()
break
case 'jump':
bot.setControlState('jump', true)
bot.setControlState('jump', false)
break
case 'jump a lot':
bot.setControlState('jump', true)
break
case 'stop jumping':
bot.setControlState('jump', false)
break
case 'attack':
entity = bot.nearestEntity()
if (entity) {
bot.attack(entity, true)
} else {
bot.chat('no nearby entities')
}
break
case 'mount':
entity = bot.nearestEntity((entity) => { return entity.name === 'minecart' })
if (entity) {
bot.mount(entity)
} else {
bot.chat('no nearby objects')
}
break
case 'dismount':
bot.dismount()
break
case 'move vehicle forward':
bot.moveVehicle(0.0, 1.0)
break
case 'move vehicle backward':
bot.moveVehicle(0.0, -1.0)
break
case 'move vehicle left':
bot.moveVehicle(1.0, 0.0)
break
case 'move vehicle right':
bot.moveVehicle(-1.0, 0.0)
break
case 'tp':
bot.entity.position.y += 10
break
case 'pos':
bot.chat(bot.entity.position.toString())
break
case 'yp':
bot.chat(`Yaw ${bot.entity.yaw}, pitch: ${bot.entity.pitch}`)
break
}
})
bot.once('spawn', () => {
// keep your eyes on the target, so creepy!
setInterval(watchTarget, 50)
function watchTarget () {
if (!target) return
bot.lookAt(target.position.offset(0, target.height, 0))
}
})
bot.on('mount', () => {
bot.chat(`mounted ${bot.vehicle.displayName}`)
})
bot.on('dismount', (vehicle) => {
bot.chat(`dismounted ${vehicle.displayName}`)
})