Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions lib/plugins/bed.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,26 @@ function inject (bot) {
}

await bot.activateBlock(bedBlock)

const err = await waitUntilSleep()
if (err) {
throw new Error(err)
}
}
}

bot._client.on('game_state_change', (packet) => {
if (packet.reason === 0) {
// occurs when you can't spawn in your bed and your spawn point gets reset
bot.emit('spawnReset')
}
})
async function waitUntilSleep () {
return new Promise((resolve, reject) => {
const timeoutForSleep = setTimeout(() => {
resolve('bot is not sleeping')
Comment thread
sefirosweb marked this conversation as resolved.
Outdated
}, 3000)

bot.once('sleep', () => {
clearTimeout(timeoutForSleep)
resolve()
})
})
}

bot.on('entitySleep', (entity) => {
if (entity === bot.entity) {
Expand Down
1 change: 0 additions & 1 deletion test/externalTests/bed.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module.exports = () => async (bot) => {
// Sleep
assert(!bot.isSleeping)
await bot.sleep(bot.blockAt(bedPos1))
await once(bot, 'sleep')

// Wake
assert(bot.isSleeping)
Expand Down