Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/examples/looker.js
9427 views
1
/*
2
* This script will automatically look at the closest entity.
3
* It checks for a near entity every tick.
4
*/
5
const mineflayer = require('mineflayer')
6
7
if (process.argv.length < 4 || process.argv.length > 6) {
8
console.log('Usage : node looker.js <host> <port> [<name>] [<password>]')
9
process.exit(1)
10
}
11
12
const bot = mineflayer.createBot({
13
host: process.argv[2],
14
port: parseInt(process.argv[3]),
15
username: process.argv[4] ? process.argv[4] : 'looker',
16
password: process.argv[5]
17
})
18
19
bot.once('spawn', function () {
20
setInterval(() => {
21
const entity = bot.nearestEntity()
22
if (entity !== null) {
23
if (entity.type === 'player') {
24
bot.lookAt(entity.position.offset(0, 1.6, 0))
25
} else if (entity.type === 'mob') {
26
bot.lookAt(entity.position)
27
}
28
}
29
}, 50)
30
})
31
32