CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/test/externalTests/bed.js
Views: 789
1
const assert = require('assert')
2
const { once } = require('../../lib/promise_utils')
3
4
module.exports = () => async (bot) => {
5
const midnight = 18000
6
const bedItem = bot.registry.itemsArray.find(item => item.name.endsWith('bed'))
7
const bedPos1 = bot.entity.position.offset(2, 0, 0).floored()
8
const bedPos2 = bedPos1.offset(0, 0, 1)
9
10
assert(bedItem)
11
12
// Put the bed
13
if (bot.supportFeature('setBlockUsesMetadataNumber', bot.version)) {
14
bot.chat(`/setblock ${bedPos1.toArray().join(' ')} ${bedItem.name} 0`) // Footer
15
bot.chat(`/setblock ${bedPos2.toArray().join(' ')} ${bedItem.name} 8`) // Head
16
} else {
17
bot.chat(`/setblock ${bedPos1.toArray().join(' ')} ${bedItem.name}[part=foot]`)
18
bot.chat(`/setblock ${bedPos2.toArray().join(' ')} ${bedItem.name}[part=head]`)
19
}
20
bot.chat(`/time set ${midnight}`)
21
await once(bot, 'time')
22
await bot.test.wait(1000)
23
24
console.log(bot.time.timeOfDay, bot.blockAt(bedPos1).name, bot.blockAt(bedPos2).name)
25
assert(bot.time.timeOfDay >= midnight)
26
assert(bot.blockAt(bedPos1).name.endsWith('bed'))
27
assert(bot.blockAt(bedPos2).name.endsWith('bed'))
28
29
// Sleep
30
assert(!bot.isSleeping)
31
await bot.sleep(bot.blockAt(bedPos1))
32
33
// Wake
34
assert(bot.isSleeping)
35
await bot.wake()
36
await once(bot, 'wake')
37
assert(!bot.isSleeping)
38
}
39
40