const assert = require('assert')
const { once } = require('../../lib/promise_utils')
module.exports = () => async (bot) => {
const midnight = 18000
const bedItem = bot.registry.itemsArray.find(item => item.name.endsWith('bed'))
const bedPos1 = bot.entity.position.offset(2, 0, 0).floored()
const bedPos2 = bedPos1.offset(0, 0, 1)
assert(bedItem)
if (bot.supportFeature('setBlockUsesMetadataNumber', bot.version)) {
bot.chat(`/setblock ${bedPos1.toArray().join(' ')} ${bedItem.name} 0`)
bot.chat(`/setblock ${bedPos2.toArray().join(' ')} ${bedItem.name} 8`)
} else {
bot.chat(`/setblock ${bedPos1.toArray().join(' ')} ${bedItem.name}[part=foot]`)
bot.chat(`/setblock ${bedPos2.toArray().join(' ')} ${bedItem.name}[part=head]`)
}
bot.chat(`/time set ${midnight}`)
await once(bot, 'time')
await bot.test.wait(1000)
console.log(bot.time.timeOfDay, bot.blockAt(bedPos1).name, bot.blockAt(bedPos2).name)
assert(bot.time.timeOfDay >= midnight)
assert(bot.blockAt(bedPos1).name.endsWith('bed'))
assert(bot.blockAt(bedPos2).name.endsWith('bed'))
assert(!bot.isSleeping)
await bot.sleep(bot.blockAt(bedPos1))
assert(bot.isSleeping)
await bot.wake()
await once(bot, 'wake')
assert(!bot.isSleeping)
}