Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/test/externalTests/bed.js
2163 views
1
const assert = require('assert')
2
const { once } = require('../../lib/promise_utils')
3
4
module.exports = () => async (bot) => {
5
// Wait a few seconds for chunks
6
await bot.test.wait(3000)
7
const midnight = 18000
8
const bedItem = bot.registry.itemsArray.find(item => item.name.endsWith('bed'))
9
const bedPos1 = bot.entity.position.offset(2, 0, 0).floored()
10
const bedPos2 = bedPos1.offset(0, 0, 1)
11
12
assert(bedItem)
13
14
// Put the bed
15
if (bot.supportFeature('setBlockUsesMetadataNumber', bot.version)) {
16
bot.chat(`/setblock ${bedPos1.toArray().join(' ')} ${bedItem.name} 0`) // Footer
17
bot.chat(`/setblock ${bedPos2.toArray().join(' ')} ${bedItem.name} 8`) // Head
18
} else {
19
bot.chat(`/setblock ${bedPos1.toArray().join(' ')} ${bedItem.name}[part=foot,facing=south]`)
20
bot.chat(`/setblock ${bedPos2.toArray().join(' ')} ${bedItem.name}[part=head,facing=south]`)
21
}
22
bot.chat(`/time set ${midnight}`)
23
await once(bot, 'time')
24
await bot.test.wait(1000)
25
26
console.log(bot.time.timeOfDay, bot.blockAt(bedPos1).name, bot.blockAt(bedPos2).name)
27
const blockAtBed1 = bot.blockAt(bedPos1)
28
const blockAtBed2 = bot.blockAt(bedPos2)
29
assert(bot.time.timeOfDay >= midnight)
30
assert(blockAtBed1?.name?.endsWith('bed'), `Expected ${bedPos1} to be bed, got ${JSON.stringify(blockAtBed1)}`)
31
assert(blockAtBed2?.name?.endsWith('bed'), `Expected ${bedPos2} to be bed, got ${JSON.stringify(blockAtBed2)}`)
32
33
// Sleep
34
assert(!bot.isSleeping)
35
const wakePromise = once(bot, 'wake')
36
await bot.sleep(bot.blockAt(bedPos1))
37
38
// Wake
39
assert(bot.isSleeping)
40
await bot.wake()
41
await wakePromise
42
assert(!bot.isSleeping)
43
}
44
45