-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathbed.js
57 lines (49 loc) · 1.21 KB
/
bed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var assert = require('assert');
module.exports = inject;
function inject(bot) {
bot.isSleeping = false;
function wake(cb) {
if(!bot.isSleeping)
cb(new Error("already awake"));
else {
bot._client.write('entity_action', {
entityId: bot.entity.id,
actionId: 2,
jumpBoost: 0
});
cb();
}
}
function sleep(bedBlock,cb) {
if(!(bot.time.day>=12541 && bot.time.day<=23458))
cb(new Error("it's not night"));
else if(bot.isSleeping)
cb(new Error("already sleeping"));
else if(bedBlock.type!==26)
cb(new Error("wrong block : not a bed block"));
else {
bot.activateBlock(bedBlock);
cb();
}
}
bot._client.on('game_state_change', function(packet) {
if (packet.reason === 0) {
// occurs when you can't spawn in your bed and your spawn point gets reset
bot.emit('spawnReset');
}
});
bot.on('entitySleep', function(entity) {
if (entity === bot.entity) {
bot.isSleeping = true;
bot.emit('sleep');
}
});
bot.on('entityWake', function(entity) {
if (entity === bot.entity) {
bot.isSleeping = false;
bot.emit('wake');
}
});
bot.wake = wake;
bot.sleep = sleep;
}