From a7ccb08d43a5819165dec35d4af34d4ad6252526 Mon Sep 17 00:00:00 2001 From: jay Date: Thu, 24 Dec 2020 10:35:01 +0500 Subject: [PATCH] refactor: :heavy_minus_sign: remove sleeper's prismarine-gameplay dependence --- lib/plugins/sleeper.js | 55 +++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/lib/plugins/sleeper.js b/lib/plugins/sleeper.js index cfa67af..b544e1b 100644 --- a/lib/plugins/sleeper.js +++ b/lib/plugins/sleeper.js @@ -1,13 +1,6 @@ let pathfinder //TODO replace with simple pathfinder motions -const { - gameplay, - MoveTo, - MoveToInteract, - ObtainItem, - // Craft -} = require('prismarine-gameplay') let cfg = {} let bot = {} @@ -33,42 +26,33 @@ function sleep(quiet) { } if (bed && bedstatus == "") { bot.lookAt(bed.position) - // const nearbed = - bot.gameplay.solveFor( - new MoveTo((bed.position.range = 2) && bed.position), (err) => { - // new MoveTo(bed.position), (err) => { - // new MoveToInteract(bed.position), (err) => { + bot.waitForChunksToLoad(() => { + cfg.plugins.moveNear(bed.position) + bot.sleep(bed, (err) => { if (err) { - !quiet && bot.chat(`can't reach bed: ${err.message}`) + !quiet && bot.chat(`can't sleep: ${err.message}`) } else { - bot.waitForChunksToLoad(() => { - bot.sleep(bed, (err) => { - if (err) { - !quiet && bot.chat(`can't sleep: ${err.message}`) - } else { - !quiet && bot.chat("zzz") - console.log("sleeping? ", bot.isSleeping) - // hack until this is fixed - // bot.isSleeping = bot.isSleeping ? bot.isSleeping : true - bot.isSleeping = true - } - }) - }) + !quiet && bot.chat("zzz") + console.log("sleeping? ", bot.isSleeping) + // hack until this is fixed + // bot.isSleeping = bot.isSleeping ? bot.isSleeping : true + bot.isSleeping = true } }) - // } else if (bed){ + }) } else if (inv && inv.equipItem("red_bed", "hand", true)) { // doesn't work fortunately // FIXME: DONT IMPLEMENT until it is detected as NOT NETHER - bot.placeBlock() + // bot.placeBlock() } else { - bot.gameplay.solveFor( - new ObtainItem("bed"), (err) => { - if (err) { - !quiet && bot.chat(`need a${bedstatus} bed: may not see if just placed`) - } - } - ) + // TODO: use mover + // bot.gameplay.solveFor( + // new ObtainItem("bed"), (err) => { + // if (err) { + // !quiet && bot.chat(`need a${bedstatus} bed: may not see if just placed`) + // } + // } + // ) // bot.chat('/afk') } bot.pathfinder.movements @@ -104,7 +88,6 @@ const load = (config) => { pathfinder = bot.pathfinder || require('mineflayer-pathfinder').pathfinder // bot.loadPlugin(pathfinder) - bot.loadPlugin(gameplay) inv = cfg.plugins["inventory"] bot.on("time", autoSleep)