-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleep.js
executable file
·33 lines (28 loc) · 902 Bytes
/
sleep.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
const Movements = require('mineflayer-pathfinder').Movements
const helper = require('./helper.js')
let mcData
mcData = require('minecraft-data')
const { GoalNear } = require('mineflayer-pathfinder').goals
async function sleepInBed(bot, username) {
const bed = bot.findBlock({
matching: block => bot.isABed(block)
})
// if a bed is not found, bot will log 'Couldn't find a bed'
if (!bed) {
bot.chat('/msg ' + username + ' Couldn\'t find a bed')
return
}
// path to the bed
const p = new Movements(bot, mcData)
bot.pathfinder.setMovements(p)
await bot.pathfinder.goto(new GoalNear(bed.position.x, bed.position.y, bed.position.z, 1))
if (bed) {
try {
bot.chat('/msg ' + username + ' Going to bed...')
await bot.sleep(bed)
} catch (err) {
console.error(err)
}
}
}
module.exports = { sleepInBed }