⚠ 注意 ⚠
(2025年9月27日)我发现 TimeLib 存在几个严重问题,使其在某些用例中不可靠。请仔细阅读以下内容并自行评估是否要使用 TimeLib。一旦 Mojang 找到或添加了修复这些问题的方法,我将再次继续支持 TimeLib。截至我撰写本文时,TimeLib v2.3.1 是最新版本。
TimeLib 并未永久停更,待所有问题解决后它将回归!
我会在此处以及 MinecraftCommands Discord 服务器(在 #resources 频道)发布有关该情况的更新。
根本性(目前)无法修复的问题:
由于这些问题,为了让 TimeLib 按预期工作,用户需要每次世界重新加载时都手动确认/调整日期。这违背了 TimeLib 的初衷,因此我需要时间思考/等待 Mojang 使缓解这些问题成为可能。
- ⚠ 如果玩家头颅档案(包含时间戳)超过 24 小时(可能因缓存导致且无法检测),则无法准确自动检测日期
- ⚠ 自 1.21.9 版本起,Unix 时间戳只能从在线玩家处获取,这意味着当没有玩家在线时 TimeLib 无法更新日期,可能会破坏依赖它的整合包(注:只需要玩家在初始阶段同步一次日期即可。只要时间不同步发生,即使没有玩家在线它也能继续工作)
- 包含游戏暂停/冻结期间刻数的
PausedTicks计分板仅在从头到尾至少有一名玩家在线时才有效。如果所有人在游戏冻结时离开(不必同时),或者一开始就没有人在线,那么PausedTicks中存储的值是不可靠的- 同样的问题导致将游戏冻结 24 小时以上会使天数不增加(因为如果没有人在线,就无法判断过去了多少时间)
- 由于夏令时的原因,Unix 时间戳(预期应单调递增)可能会倒退 1 小时,从而破坏那些严格依赖单调性的整合包。由于无法自动检测时区和夏令时,在没有玩家手动输入的情况下无法对此进行补救
其他已知的可修复漏洞/疏忽:
一旦我有空处理,我会修复这些问题。 在此期间,我将它们列在这里以便你知晓。虽然并非所有已知问题都已列出,但这些都是主要问题。
- ⚠ 一个疏忽导致在极少数情况下日期可能比实际日期提前 1 天
- ⚠ 一个疏忽导致在服务器/客户端连续运行超过 1 天后日期不再增加
- ⚠ 当时间不正确(因为检索必要数据需要一点时间)时,TimeLib 不会指示时间尚未同步,这可能会破坏那些试图在未准备好时获取数据的整合包
TimeLib
一个 Minecraft 数据包库,让你在游戏中获取现实世界的日期和时间。如有咨询,请在 Discord 上联系 @silicatYT。
下载:Modrinth
报告错误:GitHub
功能
- 提供具有刻级精度的现实世界日期和时间:
- 年、月、日、星期几、小时、分钟、秒及 Unix 时间戳
- 提供当前刻率
- 检测游戏暂停及暂停时长(例如
/tick freeze或单人模式) - 将任何 Unix 时间戳转换为日期和时间
- 支持不同时区及夏令时
- 支持延迟、不同的刻率及暂停
- 高效率
使用方法
TimeLib 会自动为你跟踪日期和时间。为此,你需要首先根据个人喜好配置设置。要访问设置,请点击重新加载后出现在聊天栏中的消息,或手动运行 /function timelib:util/settings。
→ 设置
Command Block Offset(命令方块偏移量):这是必需的,用于抵消 UTC 时区与你的系统时间之间的差异。如果夏令时发生变化,需要调整此设置以确保日期计算正常工作。- 示例: UTC(晚上 7 点),系统时钟(晚上 8 点)→ 使用 1h
Timezone Offset(时区偏移量):使用此项更改显示的时间。- 示例: 晚上 8 点 + 1h 偏移 → 晚上 9 点
→ 获取现实世界的日期和时间
年、月、日、星期几、小时、分钟、秒及 Unix 时间戳的值都存储在玩家 #TimeLib 中,每个值都有自己独立的计分板目标:
TimeLib.Year, TimeLib.Month, TimeLib.Day, TimeLib.WeekDay, TimeLib.Hour, TimeLib.Minute, TimeLib.Second & TimeLib.UnixTime
此外,日期和时间的字符串版本(带有前导零)存储在 timelib:date 和 timelib:daytime 数据存储中。
→ 事件
#timelib:date_changed:每当日期更改时执行的函数标签#timelib:daytime_changed:每当白天时间更改时执行的函数标签#timelib:game_unpaused:每当游戏取消暂停时执行的函数标签#TimeLib TimeLib.PausedTicks计分板保存游戏被暂停的刻数
→ 获取刻率
刻率每秒更新一次,可以从 TimeLib.Tickrate 计分板目标中读取。
→ 将任何 Unix 时间戳转换为日期和时间
注意: 输出的日期和时间位于 UTC 时区,因为夏令时无法得到适当考虑。
- 将
#TimeLib.Input TimeLib.UnixTime分数设置为输入值。 - 运行
/function timelib:util/unix_timestamp_to_date。 - 输出值将存储在
#TimeLib.Output TimeLib.?分数中,以及timelib:output数据存储中。
工作原理
- TimeLib 将玩家头颅内 Base64 编码的 Unix 时间戳与命令方块输出中的白天信息相结合,以计算当前的日期和时间。
- 为了获取刻率(tickrate),TimeLib 会统计每次白天变化之间的刻数。
- 暂停检测使用
minecraft.custom:minecraft:total_world_time记分板目标,该目标即使在游戏暂停时也会每刻递增。
此外还使用了其他逻辑来确保最佳结果、良好的性能和准确性。
致谢
来自 CMDred:
- SilicatYT: TimeLib
- BananaRedPanda: Base64 解码器 & 协助开发
注意事项
- TimeLib 需要互联网连接。
- 获取刻率并未利用世界边界(worldborder)的非常规手段。
- 如果你的数据包在超世界(overworld)的
29999999 29999999处使用了强制加载区块,可能会发生冲突。 - TimeLib(2.3.0 及更高版本)使用了 lantern load 库,允许你检查依赖项。如果你遵循其约定:
#TimeLib load.status:如果安装了 TimeLib 则为 1,否则未设置#TimeLib.Version load.status:特定发布版本的编号
- 升级到新版本:
- 对于 2.3.0 之前 的 TimeLib 版本:执行
/function timelib:uninstall,然后用新版本替换当前的 TimeLib,最后执行/reload安装新版本 - 从 2.3.0 或更高版本 升级到更新版本,只需将旧的数据包替换为新的即可
- 对于 2.3.0 之前 的 TimeLib 版本:执行
- (v2.3.0+)如果同时安装了多个不同版本的 TimeLib,TimeLib 会抛出错误并停止工作。这也适用于尝试调用实用函数的情况。
- 在运行
/function timelib:uninstall后尝试运行实用函数时,也会出现类似行为
- 在运行
许可证
根据 MIT 许可证,只要对原作署名,你就有权重新分发、修改和使用 TimeLib。
⚠ ATTENTION ⚠
(Sep 27, 2025) I found few major problems with TimeLib that make it unreliable for certain usecases. Please read through these carefully and assess for yourself whether you want to use TimeLib. Once a way is found or added by Mojang to fix these issues, I will keep supporting TimeLib again. As of me writing this, TimeLib v2.3.1 is the latest release.
TimeLib is NOT permanently discontinued, it will come back once all is sorted out!
I will post updates to the situation here, as well as the MinecraftCommands Discord server (in #resources).
Fundamental (currently) unfixable Problems:
Because of these issues, for TimeLib to keep working as expected, the user would need to manually confirm / adjust the date every time the world reloads. That breaks the point of TimeLib, which is why I need time to think / wait until Mojang makes it possible to mitigate these issues.
- ⚠ If the player head profile (which includes a timestamp) is older than 24 hours (which can happen due to caching and cannot be detected), it's impossible to automatically detect the date accurately
- ⚠ Since 1.21.9, the unix timestamp can only be retrieved from online players, meaning TimeLib cannot update the date while nobody's online, potentially breaking packs that rely on it (Note: It only needs the player to synchronize the date initially. Until the time is desynced, it keeps working even when nobody's online)
- The
PausedTicksscore that contains the number of ticks that the game has been paused/frozen for only works if at least one player is online from start to finish. If everyone leaves (doesn't have to be at the same time) while the game is frozen, or nobody was online in the first place, the stored value inPausedTicksis not reliable- The same problem makes it so freezing the game for 24h+ makes the day not increment (because there's no way to tell how much time has passed if nobody's online)
- Because of daylight savings, the unix timestamp (which is expected to increase monotonously) could go backwards by 1h, potentially breaking packs that necessarily rely on the monotony. Being unable to detect timezones & daylight savings automatically, this cannot be counteracted without manual player input
Other big known fixable bugs / oversights:
I will fix these issues once I get to them. In the meantime, I put them here so you're aware of them. While these are not all known issues, these are the major ones.
- ⚠ An oversight makes it possible under rare circumstances for the date to be 1 day ahead of what it should be
- ⚠ An oversight prevents the date from incrementing after more than 1 day has passed since the server / client was running without reboots
- ⚠ While the time is incorrect (because it takes a bit to retrieve the necessary data), TimeLib does not indicate that the time is not synchronized yet, potentially breaking packs that try to grab data when it's not ready
TimeLib
A Minecraft Data Pack library that lets you get the real life date & time ingame. For inquiries, please contact @silicatYT on Discord.
Download: Modrinth
Report bugs: GitHub
Features
- Provides the real life date & time with tick accuracy:
- Year, Month, Day, Week Day, Hour, Minute, Second & the Unix Timestamp
- Provides the current tickrate
- Detects pausing the game & the pause duration (e.g.
/tick freezeor singleplayer) - Convert any Unix Timestamp into a date & time
- Supports different timezones & daylight savings time
- Supports lag, different tick rates & pausing
- High efficiency
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 run /function timelib:util/settings.
→ Settings
Command Block Offset: This is required to offset the time difference between the UTC timezone and your system time. If daylight savings change, this setting needs to be adjusted to ensure that the date calculation works properly.- Example: UTC (7pm), System clock (8pm) → Use 1h
Timezone Offset: Use this to change the displayed time.- Example: 8pm + 1h offset → 9pm
→ Get the real life date & time
The values for Year, Month, Day, Week Day, Hour, Minute, Second & the Unix Timestamp are all stored inside the player #TimeLib, with each value having its own scoreboard objective:
TimeLib.Year, TimeLib.Month, TimeLib.Day, TimeLib.WeekDay, TimeLib.Hour, TimeLib.Minute, TimeLib.Second & TimeLib.UnixTime
Additionally, string versions (with leading 0s) of the date and daytime are stored in the timelib:date and timelib:daytime storages.
→ Events
#timelib:date_changed: Function tag that gets executed whenever the date changes#timelib:daytime_changed: Function tag that gets executed whenever the daytime changes#timelib:game_unpaused: Function tag that gets executed whenever the game unpauses- The
#TimeLib TimeLib.PausedTicksscoreboard holds the number of ticks the game has been paused for
- The
→ Get the tickrate
The tickrate updates once per second and can be read from the TimeLib.Tickrate scoreboard objective.
→ Convert any Unix Timestamp into a date & time
Note: The output date & time are in the UTC timezone, as daylight savings time cannot be properly accounted for.
- Set the
#TimeLib.Input TimeLib.UnixTimescore as the input. - Run
/function timelib:util/unix_timestamp_to_date. - The output values will be stored inside the
#TimeLib.Output TimeLib.?scores, as well as thetimelib:outputdata storage.
How it works
- TimeLib combines the with Base64 encoded Unix Timestamp inside player heads with the daytime information inside command block outputs to calculate the current date & time.
- To get the tickrate, TimeLib counts the number of ticks between each daytime change.
- The pause detection uses the
minecraft.custom:minecraft:total_world_timescoreboard objective, which increments every tick even while the game is paused.
Additional logic is used to ensure optimal results, good performance and accuracy.
Credit
From CMDred:
- SilicatYT: TimeLib
- BananaRedPanda: Base64 Decoder & Help
Good to know
- TimeLib requires an internet connection.
- Getting the tickrate does not utilize worldborder shenanigans.
- If your Data Pack uses a forceloaded chunk at
29999999 29999999in the overworld, there may be collision. - TimeLib (2.3.0 and newer) uses the lantern load library that lets you check for dependencies. If you follow its conventions:
#TimeLib load.status: 1 if TimeLib is installed, otherwise unset#TimeLib.Version load.status: Release-specific number
- Upgrade to a newer release:
- For TimeLib releases before 2.3.0:
/function timelib:uninstall, then replace your current TimeLib version with the new one, then/reloadto install the new version - For upgrading from release 2.3.0 or later to a newer release, simply replace the old datapack with the new one
- For TimeLib releases before 2.3.0:
- (v2.3.0+) TimeLib throws errors and stops working if multiple different releases are installed simultaneously. This extends to trying to call utility functions.
- Similar behaviour occurs when trying to run utility functions after running
/function timelib:uninstall
- Similar behaviour occurs when trying to run utility functions after running
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.
下载 TimeLib
下载 TimeLib
下载 TimeLib
下载 TimeLib
下载 TimeLib
下载 TimeLib
下载 TimeLib
下载 TimeLib
下载 TimeLib
下载 TimeLib
修复:
- 修复了一个导致 TimeLib 完全无法使用的错误(在尝试调用 tick 函数时出现拼写错误)
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
数据包
此数据包添加了属于阿瓦里海盗的独特结构,将他们的独特风格带入你的 Minecraft 世界!兼容性:1.20 至 26.3
数据包
一个 Minecraft 光线投射库,能够精确检测玩家正在查看的方块,包括像台阶和楼梯这样的特殊方块形状。
数据包
此数据包添加了新的“祝福模式”难度。
数据包
允许服务器管理员方便地禁用 Xaero's Map 系列模组中的实体雷达、小地图等功能,使竞技游戏更加公平。
数据包
手持潜影盒时可直接打开,无需将其放置在地面上。只需按住 Shift 并右键点击即可访问你的潜影盒。
数据包
为你的 Minecraft 世界添加了超过 900 个新的进度
评论 0
登录后参与评分
还没有评论,来抢沙发吧