feat: update sleeper

This commit is contained in:
jay 2020-12-22 11:31:06 +05:00
parent 5ead6b7267
commit 8eb6d790b0

View File

@ -1,6 +1,6 @@
const pathfinder = require('mineflayer-pathfinder').pathfinder let pathfinder
const { Bot } = require('mineflayer') //TODO replace with simple pathfinder motions
const { const {
gameplay, gameplay,
MoveTo, MoveTo,
@ -71,6 +71,7 @@ function sleep(quiet) {
) )
// bot.chat('/afk') // bot.chat('/afk')
} }
bot.pathfinder.movements
} }
function wake() { function wake() {
@ -86,7 +87,7 @@ function wake() {
function autoSleep() { function autoSleep() {
if (!bot.time.isDay && !cfg.sleep.timeoutFn && cfg.sleep.auto && !bot.isSleeping) { if (!bot.time.isDay && !cfg.sleep.timeoutFn && cfg.sleep.auto && !bot.isSleeping) {
sleep() sleep()
cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout) // give 2 seconds for multiple events cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout)
console.log("sleeping?", bot.isSleeping, bot.time) console.log("sleeping?", bot.isSleeping, bot.time)
} }
} }
@ -98,10 +99,11 @@ const load = (config) => {
auto: true, auto: true,
// timeout: 30 * 1000, // timeout: 30 * 1000,
timeout: 2 * 60 * 1000, timeout: 2 * 60 * 1000,
quiet: false quiet: !!cfg.quiet
} }
bot.loadPlugin(pathfinder) pathfinder = bot.pathfinder || require('mineflayer-pathfinder').pathfinder
// bot.loadPlugin(pathfinder)
bot.loadPlugin(gameplay) bot.loadPlugin(gameplay)
inv = cfg.plugins["inventory"] inv = cfg.plugins["inventory"]
bot.on("time", autoSleep) bot.on("time", autoSleep)