Correctly calculate IRL time based on game ticks #24
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation of game time to IRL time conversion
getFullTime()
returns the absolute in-game time in ticks. One tick is 50ms (20TPS = 1/20s
) and Minecraft time passes 72 times faster than IRL time (IRL_day_ms / (MC_day_ticks * 50) = 86400000 / (24000 * 50)
). And 3600 = 72*50, thus converting in-game time to IRL time:game_ticks * 3600
However, the first day of Minecraft (i.e. absolute time 0 ticks) is not midnight, but 06:00 AM. Therefore, 21600000 (6 IRL hours in ms) is added.
Therefore, the first day of the server was Thursday, January 1st 1970, at 06:00 AM (UNIX time is used, which starts in the year 1970).
IRL time to game time
Unfortunately, the in-game absolute time is not linear as players can sleep to skip nights and thunderstorms, effectively adding ticks to the absolute time. As the ticks added by players sleeping are not recorded, it is not possible to reverse the conversion.
The following is a JavaScript/TypeScript function to estimate IRL time to game time by ignoring the sleeping factor.