Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/lib/plugins/time.js
1467 views
1
module.exports = inject
2
3
function inject (bot) {
4
bot.time = {
5
doDaylightCycle: null,
6
bigTime: null,
7
time: null,
8
timeOfDay: null,
9
day: null,
10
isDay: null,
11
moonPhase: null,
12
bigAge: null,
13
age: null
14
}
15
bot._client.on('update_time', (packet) => {
16
const time = longToBigInt(packet.time)
17
const age = longToBigInt(packet.age)
18
const doDaylightCycle = packet.tickDayTime !== undefined ? !!packet.tickDayTime : time >= 0n
19
// When doDaylightCycle is false, we need to take the absolute value of time
20
const finalTime = doDaylightCycle ? time : (time < 0n ? -time : time)
21
22
bot.time.doDaylightCycle = doDaylightCycle
23
bot.time.bigTime = finalTime
24
bot.time.time = Number(finalTime)
25
bot.time.timeOfDay = bot.time.time % 24000
26
bot.time.day = Math.floor(bot.time.time / 24000)
27
bot.time.isDay = bot.time.timeOfDay >= 0 && bot.time.timeOfDay < 13000
28
bot.time.moonPhase = bot.time.day % 8
29
bot.time.bigAge = age
30
bot.time.age = Number(age)
31
32
bot.emit('time')
33
})
34
}
35
36
function longToBigInt (arr) {
37
return BigInt.asIntN(64, (BigInt(arr[0]) << 32n)) | BigInt(arr[1])
38
}
39
40