CMDred / TimeLib

A Minecraft Data Pack library that lets you get the real life date & time ingame.
MIT License
5 stars 0 forks source link

TimeLib

A Minecraft Data Pack library that lets you get the real life date & time ingame. For inquiries, please contact @silicatYT on Discord.

Features

How to use

TimeLib automatically keeps track of the date & time for you. For that to work, you first need to configure the settings to your personal taste. To access the settings, click the message that appears in chat after reloading or manually running /function timelib:util/settings.

Settings

Additionally, string versions of the Day, WeekDay and Month are stored in the timelib:date storage.

Events

Every time the date changes (or TimeLib updates the time), the function tag #timelib:time_updated is executed.

Convert any Unix Timestamp into a date & time

Note: Any output is automatically adjusted for the timezone specified in the first two settings.

How it works

TimeLib combines the with Base64 encoded Unix Timestamp found within player heads with the daytime found within command block outputs to get the current date & time. To achieve tick accuracy, TimeLib checks a repeating command block's time output every tick to see when it changes. At that point it uses several calculations & the macros introduced in 1.20.2 to schedule functions to run when the next second, minute, hour and day passes. This means that once time is synced, almost no further commands are needed.

Further logic and calculations are necessary to support edge cases such as daylight savings time, Singleplayer support, what should happen if the Unix Timestamp from the player head is from a different day etc. We hope that with this library, nobody will have to deal with these troubles anymore.

Credit

From CMDred:

Good to know

License

As per the MIT License, you are allowed to redistribute, modify and use TimeLib as long as we are credited for the original work.