feat(sleeper): ✨ add and adjust functionality to properly sleep
Can now use beds in inventory but with a hacky block placing workaround. `findBlock` returns a null position. So it uses the closest adjacent block and assumes it'll work. Bot also is more robust at sleeping,
This commit is contained in:
parent
112eb04a8d
commit
8e719d5ccf
|
@ -12,11 +12,15 @@ function sleep(quiet = cfg.sleep.quiet) {
|
||||||
!quiet && bot.chat("can't sleep, not in overworld now")
|
!quiet && bot.chat("can't sleep, not in overworld now")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (bot.isSleeping && !cfg.sleep.force) {
|
||||||
|
!quiet && bot.chat("already in bed!")
|
||||||
|
return
|
||||||
|
}
|
||||||
let bed = bot.findBlock({
|
let bed = bot.findBlock({
|
||||||
matching: block => bot.isABed(block)
|
matching: block => bot.isABed(block)
|
||||||
})
|
})
|
||||||
let bed_occupied = bed && bot.parseBedMetadata(bed).occupied
|
let bed_occupied = bed && bot.parseBedMetadata(bed).occupied
|
||||||
if (bed && !bed_occupied) {
|
if (bed && bed_occupied) {
|
||||||
bot.lookAt(bed.position)
|
bot.lookAt(bed.position)
|
||||||
bed = bot.findBlock({
|
bed = bot.findBlock({
|
||||||
matching: block => bot.isABed(block) && !bot.parseBedMetadata(block).occupied
|
matching: block => bot.isABed(block) && !bot.parseBedMetadata(block).occupied
|
||||||
|
@ -26,23 +30,46 @@ function sleep(quiet = cfg.sleep.quiet) {
|
||||||
if (bed && !bed_occupied) {
|
if (bed && !bed_occupied) {
|
||||||
bot.lookAt(bed.position)
|
bot.lookAt(bed.position)
|
||||||
bot.waitForChunksToLoad(() => {
|
bot.waitForChunksToLoad(() => {
|
||||||
cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position)
|
cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position, 2)
|
||||||
bot.sleep(bed, (err) => {
|
bot.once('goal_reached', (goal) => {
|
||||||
if (err) {
|
console.info(goal)
|
||||||
!quiet && bot.chat(`can't sleep: ${err.message}`)
|
bot.sleep(bed, (err) => {
|
||||||
} else {
|
if (err) {
|
||||||
!quiet && bot.chat("zzz")
|
!quiet && bot.chat(`can't sleep: ${err.message}`)
|
||||||
console.log("sleeping? ", bot.isSleeping)
|
} else {
|
||||||
// hack until this is fixed
|
!quiet && bot.chat("zzz")
|
||||||
// TODO confirm this is fixed
|
console.log("sleeping? ", bot.isSleeping)
|
||||||
// bot.isSleeping = true
|
// hack until this is fixed
|
||||||
}
|
// TODO confirm this is fixed
|
||||||
|
// bot.isSleeping = true
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else if (inv && inv.equipItem("red_bed", "hand", true)) {
|
} else if (bed = bot.inventory.items().filter(bot.isABed)[0]) {
|
||||||
// doesn't work fortunately
|
const v = require('vec3')
|
||||||
// FIXME: DONT IMPLEMENT until it is detected as NOT NETHER
|
bot.equip(bed, "hand", (err) => { if (err) console.error(err) })
|
||||||
// bot.placeBlock()
|
bot.waitForChunksToLoad(() => {
|
||||||
|
let refBlock =
|
||||||
|
// FIXME hack to get around findBlock returning null
|
||||||
|
bot.blockAt(bot.entity.position.offset(1, 0, 1), false)
|
||||||
|
// bot.findBlock({
|
||||||
|
// matching: (block) => {
|
||||||
|
// // if (block && block.type !== 0 && block.position) {
|
||||||
|
// if (block && block.position) {
|
||||||
|
// console.info("found", block)
|
||||||
|
// const blockAbove = bot.blockAt(block.position.offset(0, 1, 0))
|
||||||
|
// return !blockAbove || blockAbove.type === 0
|
||||||
|
// }
|
||||||
|
// // console.info("not found", block)
|
||||||
|
// return false
|
||||||
|
// }
|
||||||
|
// , maxDistance: 10
|
||||||
|
// })
|
||||||
|
console.log(refBlock)
|
||||||
|
bot.placeBlock(refBlock, new v.Vec3(0, 1, 0), console.error)
|
||||||
|
setTimeout(sleep, 3000, true)
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
// TODO: use mover
|
// TODO: use mover
|
||||||
// bot.gameplay.solveFor(
|
// bot.gameplay.solveFor(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user