nineMinecraft is a joke site.
nineMinecraft is in no way affiliated with Modrinth or 9minecraft. (And frankly, who wants to be affiliated with the latter?)
Deltatime

Deltatime

Data pack

Keep track of the real time even on laggy servers (uses the worldborder method)

Server CursedGame MechanicsLibraryManagementOptimizationUtility

96 downloads
1 follower

WARNING!

  • this pack was designed to be used with Multi world border mod
  • if you don't use this mod, you need to adjust the minimal diameter of the worldborder in the datapack (decreasing accuracy) to avoid getting unexpected worldborder damage

Scoreboard values

Scoreboard objective: deltatime

  • tickdelta -> previous tick duration (defaultly in milliseconds) (maxes out at 10 seconds by default)
  • tickstoadd -> number to add to a counter, which you don't want to be affected by lags (more info below on how to use it effectively)
  • accuracy <- the accuracy of the timings (defaults to 1000 -> milliseconds)
    • for even more accuracy, you need to edit this datapack's worldborder's minimal values
    • for even even more accuracy, you need to use my mod with the same name

How to use tickstoadd

example:

scoreboard players operation untilactionprev objective = untilaction objective
scoreboard players operation untilaction objective -= tickstoadd deltatime
execute if score untilaction objective matches ..20 unless score untilactionprev objective matches ..20 run function my:action1
execute if score untilaction objective matches ..0 unless score untilactionprev objective matches ..0 run function my:action2
  • In this example, we are trying to run "function my:action2" after "untilaction objective" ticks run and a "function my:action1" 1 second before it.
  • If we want to make it independant of server performance, we need to add a larger number of ticks to the counter, if the server lags.
  • This means that there is a possibility that the counter jumps over the 20 or 0.
  • In order to prevent the actions from not executing, we need to have another variable, which tells us the tickcount before the tickstoadd get added (subtracted). Then we need to check if the previous count is higher than our desired value and the current count is exactly or less than our desired value.

If you just want to time one action, you can just check for ..0 without the helper variable

(note that if you set the counter to a lower/higher (according to the direction of counting) value while the counter is counting and you won't also change the previous count, it will execute everything in between the previous and current value)

How does the datapack work?

  • worldborder in minecraft does not time itself based on ticks but on real seconds
  • this makes it possible to calculate the time by changing the border's size with a set duration
  • the next tick just get the border's size and calculate how much time passed based on how much has the border changed

Also check out the mod version for even better accuracy! (although even less maintained)

External resources


Project members

SmajloSlovakian

Member


Technical information

License
GPL-3.0-or-later
Project ID