-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealTime.js
More file actions
58 lines (50 loc) · 1.34 KB
/
RealTime.js
File metadata and controls
58 lines (50 loc) · 1.34 KB
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
58
/// <reference path="C:/Users/Administrator/Documents/WORKDIR/HelperLib/src/index.d.ts" />
// Register Plugin
const plugin = {
Name: "RealTime",
Introduction: "Sync real time",
Version: [0, 0, 2],
Other: {
Author: "dmbkstudio",
Github: "https://github.com/dmbkstudio/RealTime",
License: "GPL-3.0 license",
},
};
ll.registerPlugin(
plugin.Name,
plugin.Introduction,
plugin.Version,
plugin.Other
);
// Plugin Variables
const pluginPath = "./plugins/" + plugin.Name + "/";
// Create Config File
const config = new JsonConfigFile(
pluginPath + "config.json",
JSON.stringify({
syncInterval: 10000,
})
);
// Get Real Time
const getTimeObj = () => {
system.getTimeObj();
};
// Convert Real Time to Tick Game Time
const timeObjToTick = (timeObj) => {
const { h } = timeObj;
const time = (h * 1000 - 8000 + 24000) % 24000;
return time;
};
// Sync Game Time to Real Time
const syncGameTimeToRealTime = () => {
const currentTimeObj = system.getTimeObj();
const gameTime = timeObjToTick(currentTimeObj);
mc.setTime(gameTime);
};
// Regularly execute time synchronization
const syncInterval = parseInt(config.get("syncInterval"));
setInterval(syncGameTimeToRealTime, syncInterval);
// Listen pkayer is on bed
mc.listen("onBedEnter", (_player) => {
return false;
});